Repository navigation
Conversation
… empty needle The text index never indexes empty values, and a needle that tokenizes to an empty token list produces an All-mode text search over zero tokens, which is vacuously true. Because the text index condition can replace the real predicate evaluation (exact/direct read), every row matched: has(a, ''), mapContainsKey(m, '') and mapContainsValue(m, '') returned all rows instead of 0. Extend the empty-needle guard added in ClickHouse#108340 (equals branch) to the has handler and the mapKeys/mapValues (mapContainsKey/mapContainsValue and their *Like variants) branch: when the tokenized needle is empty, bail out so the predicate falls back to a full scan with real evaluation. Closes: ClickHouse#110092 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260711-133600 |
|
Workflow [PR], commit [78808e0] AI ReviewSummaryThis PR fixes the real empty-needle exact direct-read bug for Tests
Final Verdict
|
…sion The bad results only occur in the direct-read rewrite, not the ordinary row-scan path. CI can run stateless tests with query_plan_direct_read_from_text_index=0, in which the original predicate is still evaluated and both buggy and fixed code return 0, so the test would not catch a regression. Pin the setting on the index-on cases so the direct-read path where the bug lives is exercised. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
CI finish ledger — 14e520eEvery failure below has an owner (a fixing PR). None is PR-caused: this PR only edits
Session id: cron:our-pr-ci-monitor:20260711-210000 |
…empty-needle-has-map
| SET use_skip_indexes = 1; | ||
| SELECT count() FROM tab WHERE has(arr, ''); | ||
| SELECT count() FROM tab WHERE mapContainsKey(mp, ''); | ||
| SELECT count() FROM tab WHERE mapContainsValue(mp, ''); |
There was a problem hiding this comment.
This regression still only exercises the stringToTokens callers. The code change at src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:872-882 also touched the stringLikeToTokens branch for mapContainsKeyLike / mapContainsValueLike, and the PR description says those variants are fixed when the pattern reduces to an empty token list. Please add empty-pattern cases here, for example mapContainsKeyLike(mp, '') and mapContainsValueLike(mp, ''), with query_plan_direct_read_from_text_index = 1, so a regression in the *Like path cannot merge green.
There was a problem hiding this comment.
mapContainsKeyLike / mapContainsValueLike still are not covered by this regression in the way your latest comment claims. In MergeTreeIndexConditionText::getDirectReadMode they are Hint-only, not exact-read (src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:287-293), and empty-token hint queries are explicitly not converted to virtual columns (src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:314-317, src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp:479-481). So the new cases at tests/queries/0_stateless/02346_text_index_bug110092.sql:44-45 still return 0 even if the tokens.empty() guard is removed from make_map_function, because the original predicate is still evaluated. The stringLikeToTokens callers you touched are still missing a fails-without / passes-with proof; this needs a smaller focused test (likely below SQL level) or the *Like coverage claim should be dropped.
Pin query_plan_direct_read_from_text_index=1 on the index-on cases and OR each empty-needle predicate with a never-matching one so granule pruning no longer masks the always-true virtual column. Without the fix these return all rows; with it they return 0. Adds the has(mp,'') and mapContainsKeyLike/ mapContainsValueLike empty-pattern cases so the full changed exact-read surface is covered. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
All three addressed in 78808e0. The regression previously used plain predicates, which do not fail without the fix: granule pruning hides the always-true empty-needle virtual column in a simple predicate (both buggy and fixed return 0). The bug only surfaces once pruning cannot mask it, so each empty-needle case is now ORed with a never-matching predicate ( Re-added the Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260713-102500 |
|
Superseded by #110246 |
Closes: #110092
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results for
has,mapContainsKeyandmapContainsValuewith an empty needle when a text index is present. Previouslyhas(a, ''),mapContainsKey(m, '')andmapContainsValue(m, '')returned all rows instead of 0, because the empty needle tokenizes to an empty token list and an All-mode text search over zero tokens is vacuously true.Description
The text index never indexes empty values. A needle that tokenizes to an empty token list produces an All-mode
TextSearchQueryover zero tokens, which matches every row; since the text index condition can replace the real predicate evaluation (exact/direct read), the predicate returned all rows. Withuse_skip_indexes = 0the results were already correct.This extends the empty-needle guard added in #108340 (equals branch of
MergeTreeIndexConditionText.cpp) to:hashandler (text index overArray(String)),mapKeys/mapValuesbranch (mapContainsKey/mapContainsValueand their*Likevariants).When the tokenized needle is empty the index cannot serve the predicate, so we return
falseand fall back to a full scan with real evaluation. The guard is on the post-tokenization token list, so preprocessor/*Likeneedles that reduce to nothing are covered too.Repro: https://fiddle.clickhouse.com/bf0c24a1-cb9b-4366-aad8-47bfa952e61a