Replace auction_orders table with index on order_uids column#4568
Conversation
|
Reminder: Please update the DB Readme and comment whether migrations are reversible (include rollback scripts if applicable).
Caused by: |
|
This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed. |
|
Claude finished @MartinquaXD's task in 2m 6s —— View job PR Review: Replace
|
There was a problem hiding this comment.
Code Review
This pull request removes the redundant auction_orders table and replaces it with a GIN index on the order_uids column of the competition_auctions table, updating the database queries, schema, and documentation accordingly. Feedback highlights a critical deployment issue: creating the GIN index on production takes approximately 6.5 hours, which will exceed the 5-minute deployment limit and cause the automated Flyway migration to fail. To prevent this, the index must be created manually on the production database prior to deployment.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| CREATE INDEX CONCURRENTLY IF NOT EXISTS competition_auctions_order_uids_gin | ||
| ON competition_auctions USING GIN (order_uids); |
There was a problem hiding this comment.
According to the database/README.md guidelines, migrations that require a long-running process must be executed manually because the weekly release process imposes a 5-minute deployment limit (and a 600-second pod deadline). Since creating this GIN index on the production database takes approximately 6.5 hours (as noted in the PR description), running this as an automated Flyway migration during deployment will cause the release to time out and fail.
To prevent deployment failure, this index must be created manually on the production database prior to deploying this release. Once created manually, the IF NOT EXISTS clause will allow the Flyway migration to complete instantly during deployment.
|
Since opening the PR I already went ahead and created the new index on all tables - mainnet is still working on it but should be ready in the morning. So while it's not needed for this PR I want to spare others going through the same investigation as I did. |
e95456d to
661f19d
Compare
Description
When I investigated some of the fallout of the recent DNS issues I noticed that the post-processing that happens in the autopilot run loop (storing important bookkeeping information in the DB before telling the winner to

/settle) can be very slow. The biggest offender was thesave_auctioncall that first writes intocompetition_auctionsand then into theauction_orderstable. This currently routinely takes 250-500ms according to our metrics.However, it seems like the write into the
auction_orderstable is completely redundant as it duplicates the information we already have incompetition_auctions::order_uids. The new redundant table was introduced in #4233 to quickly find all auctions that contained a given order uid. However, this can also be achieved using a GIN index on the existingorder_uidstable.partially addresses #3057
Changes
Create GIN index on
competition_auctions::order_uidsand update the code to use that instead of theauction_orderstable. To not have anything break during the release theauction_orderstable will be dropped in the release after that to make sure no pods are using the old table during the rollover.How to test
I cloned the prod DB and created the new GIN index. While it took ~6.5h and 12% CPU usage the resulting index was significantly smaller than the deprecated table + index (20GB vs 470GB) and the new queries were actually faster on the new index.
migration (6.5h @ 12% CPU)

size comparison (19GB vs 492GB)

query performance (77ms vs 147ms)

and as a last sanity check I also compared the data of the 2 tables and since the

competition_auctionstable was created before theauction_orderstable it even contains 6 times as much data.