fix: Optimize project stat query

This commit is contained in:
2026-03-13 06:06:38 +01:00
parent 8e86e8720d
commit 96fc44a649
2 changed files with 3 additions and 4 deletions

View File

@@ -2,9 +2,10 @@
-- Column order: cluster (equality), hpc_user (GROUP BY), start_time (range scan) -- Column order: cluster (equality), hpc_user (GROUP BY), start_time (range scan)
-- Includes aggregated columns to avoid main table lookups entirely. -- Includes aggregated columns to avoid main table lookups entirely.
DROP INDEX IF EXISTS jobs_cluster_starttime_user_stats;
CREATE INDEX IF NOT EXISTS jobs_cluster_user_starttime_stats CREATE INDEX IF NOT EXISTS jobs_cluster_user_starttime_stats
ON job (cluster, hpc_user, start_time, duration, job_state, num_nodes, num_hwthreads, num_acc); ON job (cluster, hpc_user, start_time, duration, job_state, num_nodes, num_hwthreads, num_acc);
CREATE INDEX IF NOT EXISTS jobs_cluster_project_starttime_stats
ON job (cluster, project, start_time, duration, job_state, num_nodes, num_hwthreads, num_acc);
PRAGMA optimize; PRAGMA optimize;

View File

@@ -238,7 +238,6 @@ func (r *JobRepository) JobsStatsGrouped(
groupBy *model.Aggregate, groupBy *model.Aggregate,
reqFields map[string]bool, reqFields map[string]bool,
) ([]*model.JobsStatistics, error) { ) ([]*model.JobsStatistics, error) {
start := time.Now()
col := groupBy2column[*groupBy] col := groupBy2column[*groupBy]
query := r.buildStatsQuery(filter, col, config.Keys.ShortRunningJobsDuration, reqFields) query := r.buildStatsQuery(filter, col, config.Keys.ShortRunningJobsDuration, reqFields)
@@ -325,7 +324,6 @@ func (r *JobRepository) JobsStatsGrouped(
} }
} }
cclog.Debugf("Timer JobsStatsGrouped %s", time.Since(start))
return stats, nil return stats, nil
} }