Repository navigation
perf(migration): qualify the ORDER BY so notification copies use their index - #1147
Conversation
🦋 Changeset detectedLatest commit: 4cf784e The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge.
|
|
Checked the sibling cursor families for the same output-alias shadowing, since
So the two notification tables were the only ones where |
Description
scan_batchbuildsSELECT {columns} FROM {table} [WHERE key > $1] ORDER BY {key} LIMIT $2. Fornotification_outboxandnotification_delivery_logthe column list startsid::text AS id, and inPostgreSQL an
ORDER BYname resolves to the output column before the table column — soORDER BY idsorted the text expression while the indexes cover the
uuidcolumn. Every batch read theremaining rows and sorted their text ids before applying
LIMIT.The keyset predicate (
id > $1::uuid) and theORDER BYnow both name the table, so the plannerreads the
uuidindex directly. The unit test asserts both qualified forms.Related Issue
Closes #1124
Motivation and Context
The migration copies of both notification tables are the largest they get, and the unindexed sort
grows with the backlog: each batch costs a full read of the remaining rows instead of a bounded
index range scan.
How Has This Been Tested?
4 passed, 0 failed (
every_cursor_is_the_tables_own_key,the_uuid_cursor_is_the_two_tables_the_schema_makes_uuid,a_reports_cursor_is_undone_before_it_is_bound,the_first_page_of_every_table_binds_no_cursor).The new assertion checks the exact predicate (
{table}.id > $1::uuid) and the exact ordering(
ORDER BY {table}.id) for both uuid tables, so a regression to the unqualified form fails it.Credit
The fix is @tirthraj01's, who worked it out in
#1124 (comment) and posted it on his fork
(
tirthraj01:perf/1124-qualify-notification-order-by, offrewrite/main). This PR carries his commitunchanged except for one
rustfmtwrap of theformat!call thatcargo fmt --checkrequired, andhe remains the author of the commit.
Types of changes
Checklist: