Repository navigation
[ZC: WW.3.S] UM-1689: let the plan look the keeper up instead of scanning for it - #2131
Conversation
…canning for it The plan joined each candidate row to its group's keeper against a query that computes ROW_NUMBER() over the whole eligible set, and SQLite cannot look a group up inside such a query: there is no index on its result, so the join scanned the set once for every row. On the production ledger that read 142 GB and never finished; with the keepers materialized into an indexed table the same plan reads 3.5 GB and finishes in minutes. The plan's results are the same: the same 448,977 candidates, the same four manifests, the same keeper for each group, and the same rows left alone. A test reads the query plan and asserts that the keeper is looked up through an index rather than scanned, so the shape cannot quietly go back to a scan.
This comment has been minimized.
This comment has been minimized.
|
Automatic approval held Kody's assessment:
|
|
@kody start-review |
A double space where the note means a sentence break, corrected to the real gap.
This comment has been minimized.
This comment has been minimized.
…was given The keepers table made the label query cheap by reading the labels from the keepers, and the keepers are every group's newest row in the whole ledger. A run bounded to a window therefore reported a label and wrote a manifest for every label the ledger holds, not only the labels the window holds, and a ledger with more than eight labels could stop a narrow run from being planned at all. The window's rows now live in a table of their own, the same way the keepers do, and the labels are read from there. The labels the plan reports are the labels of the rows it may touch, by construction rather than by a second query that has to be kept in step with the first. Both plans were run over the same window of the production ledger and agree: the same 5,275 groups, the same 5,275 keepers, the same candidates, and the same manifest digests. A test writes nine labels outside the window and one cross-host pair inside it, and asserts that the run is planned, that only the label the window holds is reported, and that no manifest is left for a label the run never touched. The test fails on the old query with "this plan needs 10 manifests".
This comment has been minimized.
This comment has been minimized.
|
@kody start-review The plan joins each candidate row to its group's keeper. The keeper is materialized into an indexed table, and the window's rows into a table of their own, so the labels the plan reports are read from the rows it may touch rather than from the whole ledger. The first run of the review found that regression, and it is fixed: a test writes nine labels outside the window and one cross-host pair inside it, and asserts that only the label the window holds is reported and that no manifest is left for a label the run never touched. Both plans were run over the same window of the production ledger and agree on every group, keeper and manifest digest. |
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
[ZC: WW.3.S] UM-1689: let the plan look the keeper up instead of scanning for it
Fixes UM-1689 (follow-up to #2125).
Summary
The duplicate-cleanup planning script now materializes each group’s keeper in a temporary SQLite table and indexes the group keys. Candidate rows look up their keeper through that index instead of joining against a window-function result, avoiding the repeated full scans that made the plan impractical on large ledgers. The ledger remains open read-only, and the documented intent is to preserve the plan’s results.
A test checks SQLite’s query plan to ensure the keeper is searched through an index rather than scanned. The planning script now derives manifest labels from the materialized keepers; an automated review flagged that this may include labels whose keepers fall outside the requested time window.
Summary
No functional or query-planning changes are included in the provided patch.
Summary
The duplicate-cleanup planner now materializes rows within the requested time window and uses that set to determine which labels to report and which candidate rows to plan. Keeper selection remains based on the newest row for each group across the ledger, including rows outside the window. This prevents unrelated labels elsewhere in the ledger from creating empty manifests or causing a narrow plan to exceed the cleanup CLI’s label limit.
Tests
Added coverage confirming that the query looks up keepers through an index and that labels absent from the requested window are not reported or given manifests. Test execution is not reported.
Summary
The cleanup planner now stages rows within the requested time window and uses that window as the source for both candidate grouping and manifest labels. It still determines each group’s keeper from the ledger as a whole, so the newest row can be selected even when it falls outside the requested window. This prevents labels found only outside the window from producing empty manifests or causing a narrow run to exceed the cleanup CLI’s label limit.
Tests
Added coverage for planning a window when the ledger contains more labels than the cleanup CLI supports, verifying that only labels present in the window are reported and written to manifests. Updated the query-plan test to create the temporary tables and indexes required by the planner’s revised query.