Skip to content

Commit 9ed014f

Browse files
committed
Document change to random_order definition
1 parent 6592276 commit 9ed014f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

opsqueue/migrations/20250803174028_better_random_order_formula.up.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ ALTER TABLE chunks DROP COLUMN random_order;
66
ALTER TABLE chunks_metadata DROP COLUMN random_order;
77

88
-- 2. Recreate the column with its new, proper definition
9+
--
10+
-- Compared to the OG definition, we ensure that the top 42 bits of `submission_id`
11+
-- which contain the timestamp part of the snowflake,
12+
-- always participate in the `random_order`,
13+
-- since the lower 22 bits are likely to be `0` except when under peak load.
914
ALTER TABLE chunks ADD COLUMN random_order INTEGER NOT NULL GENERATED ALWAYS AS (
1015
(((submission_id + (submission_id >> 22) + chunk_index) % 65536) * 40503) % 65536
1116
) VIRTUAL;

0 commit comments

Comments
 (0)