Repository navigation
Add a regression test for NOT NOT over a text index direct read - #120836
Conversation
`AST fuzzer (amd_release, oracle)` on ClickHouse#118321 reported an `Identity WHERE (NOT(NOT p))` mismatch seeded from `02346_text_index_partially_materialized.sql`: `hasPhrase(text, 'ello50 wor')` counted 30 rows while `NOT (NOT hasPhrase(text, 'ello50 wor'))` counted 0. `hasPhrase` with two arguments tokenizes with `splitByNonAlpha`, under which `'ello50 wor'` is not a phrase of `'hello50 world50'`; the index tokenizer reaches the row-level function only as a third argument injected by `processTextIndexFunction`. Because the index declares `support_phrase_search = 0`, `getDirectReadMode` returns `Hint`, the only mode that keeps the original predicate beside the index virtual column, so that injection is observable. Before ClickHouse#116381, index analysis cancelled a pair of `not` unconditionally, so `not(not(hasPhrase(...)))` canonicalised to the bare atom, the outer `not` node became the replacement key, and `replaceNodes` returned early on it without descending into its children, so the injected three-argument call never reached the executed predicate. `EXPLAIN actions = 1` shows both sides: before Filter column: __text_index_idx_hasPhrase_5d43... AND NOT NOT hasPhrase(text, 'ello50 wor') after Filter column: NOT NOT (__text_index_idx_hasPhrase_5d43... AND hasPhrase(text, 'ello50 wor', 'ngrams(3)')) ClickHouse#116381 fixed this on master by blocking only the unsound half of the cancellation, so this commit adds no source change. `05043_not_in_value_position_key_condition` pins the index-analysis consequence of that fix; the direct-read rewrite had no test of its own. `hasAnyTokens` and `hasAllTokens` take the same injected tokenizer argument, but over a plain text index `getDirectReadMode` gives them `Exact` mode, which drops the original predicate, so this seam is reachable only for a non-positional `hasPhrase` and no sibling arm is added. With the one line of ClickHouse#116381 reverted locally, `not not p` and `prewhere not not p` report 0 instead of 10 (20 of 20 randomized runs fail); on master 50 of 50 randomized runs pass. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118321&sha=518eff241122633d224affa709900640c1544c07&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 Related: ClickHouse#118321 Related: ClickHouse#116381 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Two rounds. Round 1: review by an independent model (engine: codex, 2 findings) plus a cold review of
Round 2 re-derived every source fact behind the round-1 correction independently, before reading the Checked and found sound rather than changed: the absent Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260918-134300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260918-113200 |
|
Workflow [PR], commit [559bded] Summary: ✅ AI ReviewSummaryAdds a stateless regression test for Final VerdictStatus: ✅ Approve |
59577b6
Related: #118321
Related: #116381
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Test only, no
src/change.AST fuzzer (amd_release, oracle)on #118321 reported anIdentity WHERE (NOT(NOT p))mismatch seeded from02346_text_index_partially_materialized.sql:hasPhrase(text, 'ello50 wor')returned 30 rows whileNOT (NOT hasPhrase(text, 'ello50 wor'))returned 0.Root cause: over a text index declared
support_phrase_search = 0,hasPhrasegets theHintdirect-read mode, the only mode that keeps the original predicate beside the index virtual column, so the index tokenizer reaches the row-level function only as an injected third argument. Index analysis used to cancel a pair ofnotunconditionally, soNOT (NOT hasPhrase(...))became the rewrite target itself andreplaceNodesreturned early on it without descending into its children. The bare two-argument call ran instead, and it tokenizes withsplitByNonAlpha, under which'ello50 wor'is not a phrase of'hello50 world50'.#116381 already fixed this on master, so nothing changes here.
05043_not_in_value_position_key_conditionpins the index-analysis consequence of that fix; the direct-read rewrite had no test of its own.The test asserts the fuzzer's identity arms (
p,NOT (NOT p),p AND 1,p OR 0) andPREWHERE NOT (NOT p)over such an index, a ground-truth arm with the tokenizer spelled out and the index off, and a guard thatEXPLAIN actions = 1contains the__text_index_virtual column, so no arm can pass vacuously. The randomized settings the mechanism needs are pinned in the test body.Validation: with the one line of #116381 reverted locally,
not not pandprewhere not not preport0instead of10(20 of 20 randomized runs fail); on master 50 of 50 randomized runs pass.CI report of the fuzzer run: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118321&sha=518eff241122633d224affa709900640c1544c07&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29
Workflow [PR]
Sync PR [sync-upstream/pr/120836]
Version info
26.10.1.155(included in26.10and later)