added new index after changing order#907
Conversation
nthmost-orkes
left a comment
There was a problem hiding this comment.
Index design looks correct — the column order matches the current ORDER BY in PostgresQueueDAO (deliver_on, priority DESC, created_on), the partial index on popped = false is a real improvement over V7's approach of including popped as a regular column, and the INCLUDE (message_id) makes it a covering index for the CTE so no heap fetch needed. Good stuff.
One concern: the migration uses a plain CREATE INDEX, which takes a ShareLock on queue_message for the duration of the build and blocks all writes (queue pops and pushes) until it finishes. V9 uses DROP INDEX CONCURRENTLY / CREATE INDEX CONCURRENTLY specifically to avoid this on busy production systems. This migration should do the same.
The catch is that CONCURRENTLY can't run inside a transaction block, so you'd also need a -- flyway:nonTransactional comment at the top of the file (V9 uses CONCURRENTLY but is missing this header, which is actually a latent bug there). So the migration would look like:
-- flyway:nonTransactional
DROP INDEX CONCURRENTLY IF EXISTS combo_queue_message;
CREATE INDEX CONCURRENTLY combo_queue_message
ON queue_message (queue_name, deliver_on ASC, priority DESC, created_on ASC)
INCLUDE (message_id)
WHERE popped = false;
Otherwise this LGTM.
|
Index design looks correct — the column order matches the current ORDER BY in PostgresQueueDAO (deliver_on, priority DESC, created_on), the partial index on popped = false is a real improvement over V7's approach of including popped as a regular column, and the INCLUDE (message_id) makes it a covering index for the CTE so no heap fetch needed. Good stuff. One concern: the migration uses a plain CREATE INDEX, which takes a ShareLock on queue_message for the duration of the build and blocks all writes (queue pops and pushes) until it finishes. V9 uses DROP INDEX CONCURRENTLY / CREATE INDEX CONCURRENTLY specifically to avoid this on busy production systems. This migration should do the same. The catch is that CONCURRENTLY can't run inside a transaction block, so you'd also need a -- flyway:nonTransactional
DROP INDEX CONCURRENTLY IF EXISTS combo_queue_message;
CREATE INDEX CONCURRENTLY combo_queue_message
ON queue_message (queue_name, deliver_on ASC, priority DESC, created_on ASC)
INCLUDE (message_id)
WHERE popped = false;Otherwise this LGTM. |
|
@nthmost-orkes , I added the header line, can we merge it now? |
Yes -- sorry to overlook this, just need to run tests and i'll pull this in. |
|
@nthmost-orkes , it's all green now, how do I merge? should it merge automatically? |
I think we have a flaky test blocking this from passing |
|
The Root cause: This PR adds Fix: Rename the new migration to the next available version: (Current highest is |
|
@nthmost-orkes , fixed name, CI build is ok now. |
Pull Request type
Changes in this PR
fix index after fixing shceduler polling query order #515
Before a query was:
and there was an index for that (check
postgres-persistence/src/main/resources/db/migration_postgres/V7__new_qm_index_desc_priority.sqland probably index was incorrect also):after query changes:
Please notice order of order by changed, so in this PR old index is deleted and new is created specifically to make poll query efficient: