Repository navigation
Fix FINAL returning a superseded row with a skip index on a float primary key column - #126118
Conversation
…mary key column `buildIndexes` turns `use_skip_indexes_if_final_exact_mode` off when every column of every useful skip index is in the primary key (ClickHouse#93899): rows of one FINAL group have equal key values, so such an index cannot drop the winner of a group while keeping an older version. For floats that premise is false. The FINAL merge treats -0.0 and 0.0, and all NaN payloads, as one key, while a skip index stores the actual values. With rows (1, 0.0, 1) and (1, -0.0, 2) in two parts and `INDEX ix_f f TYPE set(0)` on key column `f`, `FINAL WHERE toString(f) = '0'` drops the granule with the winner and returns the superseded row; SummingMergeTree returns a partial sum. Build the set of primary key columns with `sortingKeyNamesSafeBeforeFinal`, which excludes float-containing columns for the same reason in deferred row policies (ClickHouse#121782). A skip index on a float key column now keeps the exact-mode recovery pass on; for such keys it reads the whole surviving parts, as it already does for an index on a non-key column of these tables. Indexes on non-float key columns keep the shortcut. Closes ClickHouse#122346 Co-Authored-By: Claude Opus 5.5 <[email protected]>
For a primary key the recovery pass cannot sort (floats, Nullable, Variant, reverse order), and for parts without a final mark, `findPKRangesForFinalAfterSkipIndex` returned every surviving part in full, discarding the primary key analysis. With a selective key prefix, FINAL then read more with the skip index than without it. The previous commit enables the pass for skip indexes on float key columns, so those queries hit it too. Return the ranges selected by the primary key instead. They are captured for every part in exact mode and are what FINAL reads with `use_skip_indexes = 0`, so this adds no correctness assumption; the sortable branch already restricts its candidates to the same ranges. On 2 parts of 1M rows with `ORDER BY (id, f)`, `WHERE id BETWEEN 300000 AND 310000 AND f = 3/7` reads 32,768 rows instead of 2,000,000, both for a set index on `f` and for one on a non-key column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`force_data_skipping_indices` only checks that the index is chosen for the query; an index that is declined per part, or prunes nothing, leaves the ranges unchanged without an error. The signed-zero and NaN oracles expect an empty result, which is also what any binary returns when the index prunes nothing, so each float fixture now asserts with `EXPLAIN indexes = 1` that `ix_f` drops one of its two granules (`Granules: 1/2`). The read_rows check also requires both query_log rows to be present. The fallback of the FINAL exact-mode recovery throws LOGICAL_ERROR when a part has no ranges selected by the primary key, like the sortable branch, instead of silently reading the whole part (the snapshot is always set when exact mode is on). The `_no_final_mark` test comment describes the new fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Round r0 (head
Round r1 (head
Round r2 (head |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261015-195000 |
|
Workflow [PR], commit [1386de4] Summary: ✅
AI ReviewSummaryPR #126118 preserves exact-mode recovery for skip indexes on floating-point primary-key columns, preventing stale Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
cc @shankar-iyer @yariks5s, could you review this? The #93899 shortcut that skips the FINAL exact-mode recovery pass now ignores float primary key columns (via |
…nal mark The skip indexes of the existing table are on primary key columns, so the `findPKRangesForFinalAfterSkipIndex` pass is skipped there since ClickHouse#93899 and the comment-only change of this test made the bugfix validation job red. Add a table with a skip index on a column outside of the primary key: the pass now runs, meets the part without the final mark and must keep the ranges selected by the primary key. On master it reads the whole part and fails with `TOO_MANY_ROWS` under `max_rows_to_read = 1000`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126118&sha=1386de4359b9686d30258cb768202ddaef6284ac&name_0=PR&name_1=Bugfix%20validation%20(functional%20tests%2C%20amd64) ClickHouse#126118 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only red check on 1386de4 was |
Backport #126118 to 26.10: Fix FINAL returning a superseded row with a skip index on a float primary key column
…a skip index on a float primary key column
Closes: #122346
Related: #93899
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
SELECT ... FINALreturning stale rows when a data-skipping index is on a floating-point primary key column and one key has versions with0.0and-0.0, or with different NaN payloads. Closes #122346.Description
On 26.8.18.2 (also 26.3.42.3 and 26.9.16.11), with
ReplacingMergeTree(v) ORDER BY (id, f),f Float64,INDEX ix_f f TYPE set(0)and the rows(1, 0.0, 1)and(1, -0.0, 2)in two parts,SELECT * FROM t FINAL WHERE toString(f) = '0'returns the superseded row1 0 1instead of nothing. Two NaN payloads of one key give the same result.#93899 skips the exact-mode recovery pass (
PrimaryKeyExpand) when every column of every useful skip index is in the primary key, because the rows of one FINAL group have equal key values. That is not true for floats: FINAL merges-0.0with0.0, and NaN payloads with each other, while a skip index keeps them apart. The index drops the granule with the winning row, keeps the one with the old row, and the winner never reaches the merge.areAllSkipIndexColumnsInPrimaryKeynow builds its set of primary key columns withsortingKeyNamesSafeBeforeFinal, which already excludes float columns for the same reason in deferred row policies (#121782). Indexes on non-float key columns keep the shortcut.Cost: the recovery pass cannot order float keys (nor
Nullableor reverse-order keys), so for them it read the whole surviving parts; it now reads the ranges selected by the primary key, asuse_skip_indexes = 0does. On 2 parts of 1M rows with a pruning set index onf:WHERE f = 3/7reads 2,000,000 rows instead of 212,992 on master, the same asuse_skip_indexes = 0;WHERE id BETWEEN 300000 AND 310000 AND f = 3/7reads 32,768 rows on master and with the fix. With the index on a non-key column instead, that query reads 32,768 rows instead of 2,000,000 on master.Test
05401_skip_index_final_float_primary_keyfails on master and passes with the fix, including 50 randomized runs.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126118]
Version info
26.11.1.178-master(included in26.11and later)