mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-15 04:17:30 +01:00
Add covering indexes for status/dashboard queries (migration 13)
Adds composite covering indexes on (cluster, job_state, <group_col>, ...) for user, project, and subcluster groupings to enable index-only scans for status views. Drops subsumed 3-column indexes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 3d8def28e96e
This commit is contained in:
@@ -21,12 +21,13 @@ import (
|
|||||||
// is added to internal/repository/migrations/sqlite3/.
|
// is added to internal/repository/migrations/sqlite3/.
|
||||||
//
|
//
|
||||||
// Version history:
|
// Version history:
|
||||||
|
// - Version 13: Add covering indexes for status/dashboard queries (cluster, job_state, ...)
|
||||||
// - Version 12: Add covering index for stats queries (cluster, start_time, hpc_user, ...)
|
// - Version 12: Add covering index for stats queries (cluster, start_time, hpc_user, ...)
|
||||||
// - Version 11: Optimize job table indexes (reduce from ~78 to 48)
|
// - Version 11: Optimize job table indexes (reduce from ~78 to 48)
|
||||||
// - Version 10: Node table
|
// - Version 10: Node table
|
||||||
//
|
//
|
||||||
// Migration files are embedded at build time from the migrations directory.
|
// Migration files are embedded at build time from the migrations directory.
|
||||||
const Version uint = 12
|
const Version uint = 13
|
||||||
|
|
||||||
//go:embed migrations/*
|
//go:embed migrations/*
|
||||||
var migrationFiles embed.FS
|
var migrationFiles embed.FS
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- Reverse migration 13: Remove covering status indexes, restore 3-col indexes
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS jobs_cluster_jobstate_user_stats;
|
||||||
|
DROP INDEX IF EXISTS jobs_cluster_jobstate_project_stats;
|
||||||
|
DROP INDEX IF EXISTS jobs_cluster_jobstate_subcluster_stats;
|
||||||
|
|
||||||
|
-- Restore the original 3-col indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS jobs_cluster_jobstate_user
|
||||||
|
ON job (cluster, job_state, hpc_user);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS jobs_cluster_jobstate_project
|
||||||
|
ON job (cluster, job_state, project);
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
-- Migration 13: Add covering indexes for status/dashboard queries
|
||||||
|
-- Column order: cluster (equality), job_state (equality), grouping col, then aggregated columns
|
||||||
|
-- These indexes allow the status views to be served entirely from index scans.
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS jobs_cluster_jobstate_user_stats
|
||||||
|
ON job (cluster, job_state, hpc_user, duration, start_time, num_nodes, num_hwthreads, num_acc);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS jobs_cluster_jobstate_project_stats
|
||||||
|
ON job (cluster, job_state, project, duration, start_time, num_nodes, num_hwthreads, num_acc);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS jobs_cluster_jobstate_subcluster_stats
|
||||||
|
ON job (cluster, job_state, subcluster, duration, start_time, num_nodes, num_hwthreads, num_acc);
|
||||||
|
|
||||||
|
-- Drop 3-col indexes that are now subsumed by the covering indexes above
|
||||||
|
DROP INDEX IF EXISTS jobs_cluster_jobstate_user;
|
||||||
|
DROP INDEX IF EXISTS jobs_cluster_jobstate_project;
|
||||||
|
|
||||||
|
PRAGMA optimize;
|
||||||
Reference in New Issue
Block a user