Skip to content

Commit be4dd4f

Browse files
committed
Use AS MATERIALIZED in job dequeing logic
1 parent 50600d4 commit be4dd4f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

database/src/pool/postgres.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,11 +1970,15 @@ where
19701970
// We take the oldest job from the job_queue matching the benchmark_set,
19711971
// target and status of 'queued' or 'in_progress'
19721972
// If a job was dequeued, we increment its retry (dequeue) count
1973+
19731974
let row_opt = self
19741975
.conn()
19751976
.query_opt(
19761977
"
1977-
WITH picked AS (
1978+
-- We use the AS MATERIALIZED clause to ensure that Postgres will run each CTE only once,
1979+
-- and not do any optimizer magic that could run the CTE query multiple times.
1980+
-- See https://stackoverflow.com/a/73967537/1107768
1981+
WITH picked AS MATERIALIZED (
19781982
SELECT
19791983
id
19801984
FROM

0 commit comments

Comments
 (0)