Skip to content

Commit fcb6c92

Browse files
authored
Merge pull request #2246 from Jamesbarford/fix/database-indexes
Fix; for query performance
2 parents 0a42de6 + b880a24 commit fcb6c92

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

database/src/pool/postgres.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ static MIGRATIONS: &[&str] = &[
410410
411411
CREATE INDEX error_artifact_idx ON error(aid);
412412
"#,
413+
// For completed requests we take the last N completed. As the total number
414+
// of requests grows to make things fast we need an index on the completed_at
415+
r#"
416+
CREATE INDEX benchmark_request_completed_idx ON benchmark_request(completed_at);
417+
"#,
413418
];
414419

415420
#[async_trait::async_trait]
@@ -743,10 +748,8 @@ impl PostgresConnection {
743748
UNION
744749
SELECT tag FROM parents
745750
)
746-
SELECT job_queue.*
747-
FROM requests
748-
-- Only get requests that have some jobs
749-
RIGHT JOIN job_queue on job_queue.request_tag = requests.tag
751+
-- Only get the jobs of in_progress requests
752+
SELECT * FROM job_queue INNER JOIN requests ON job_queue.request_tag = requests.tag
750753
")).await.unwrap(),
751754
}),
752755
conn,

0 commit comments

Comments
 (0)