Skip to content

Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle - #110246

Merged
alexey-milovidov merged 10 commits into
masterfrom
fix-#110092
Jul 23, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
fix-#110092

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Closes: #110092

This is a continuation of #110094

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed wrong results for functions has, mapContainsKey and mapContainsValue with an empty needle when a text index is present.

Version info

  • Backported to: 26.7.2.1, 26.6.2.104, 26.5.6.65, 26.4.5.153, 26.3.17.70

… 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 #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: #110092

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [60bb05c]

Summary: ✅


AI Review

Summary

This PR closes the exact direct-read text-index bug where an empty needle could turn into an empty token set and then an always-true virtual predicate for has, mapContainsKey, and mapContainsValue on array-tokenizer indexes. The new guards correctly fall back to row-level evaluation, and the updated regression test now forces query_plan_direct_read_from_text_index = 1, so it deterministically exercises the previously broken path. I did not find any remaining correctness issue in the current diff. I did not run the test locally because this checkout has no build directory, but the PR CI is currently green.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 13, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Your PR was poisoned by the test 02346_text_index_bug108519_qcc_skip_index. It is fixed in master. Please update the branch.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Backport?

@alexey-milovidov alexey-milovidov self-assigned this Jul 19, 2026
alexey-milovidov and others added 3 commits July 20, 2026 01:58
Address review feedback: the empty-needle wrong-results path is only
reached when `query_plan_direct_read_from_text_index` is enabled, which
`clickhouse-test` otherwise randomizes. Force the setting on for the
index-lookup block so the regression reliably exercises the fixed path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Both remaining CI reds are unrelated to this PR:

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110246&sha=72768ce112527547fd077031893e6c2c7404b30f&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 and provide a fix in a separate PR (see the analysis in #111053). If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

The arm_msan red is the #111053 txn_version.txt restart race (Code: 27 in VersionInfo::readFromMultiLineBuffer at startup, from the non-permanent-DETACH fabrication window), which #111055 (DETACH ... PERMANENTLY on 04063 + 04241, Closes #111053) already fixes. Linking that as the in-progress fix.

That is a separate failure mode from our #110999, which pins the four tests to storage_policy = 'default' for the sibling object-storage manifestation (Code: 246, raw txn_version.txt not valid DiskObjectStorageMetadata). The two are orthogonal, so no separate PR is needed from us for the arm_msan case.

@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jul 20, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The fresh Stress test (arm_release) red (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110246&sha=e6c07112762fc8f53f07d7976372b186bdf776e4&name_0=PR&name_1=Stress%20test%20%28arm_release%29) is the same known startup-corruption class as before, just via a different test: Cannot start clickhouse-server because test_7.t_plt_evict_reinsert (fabricated by 04417_part_loading_tree_rollback_evict_reinsert_contains) was left attached with fabricated broken parts (Part all_5_6_1_0 intersects previous part all_1_5_4_1 and the transaction metadata ... could not be read). Tracked in #111053; the in-progress fix #111055 detaches the tables permanently in all four part-loading-tree rollback tests, including 04417. Unrelated to this PR — the code change and its test are otherwise fully green (AI Review ✅, coverage 13/13 changed lines).

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 23, 2026
Merged via the queue into master with commit d93bb62 Jul 23, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-#110092 branch July 23, 2026 07:15
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 23, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 23, 2026
rschu1ze added a commit that referenced this pull request Jul 23, 2026
Backport #110246 to 26.3: Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
rschu1ze added a commit that referenced this pull request Jul 23, 2026
Backport #110246 to 26.5: Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
rschu1ze added a commit that referenced this pull request Jul 23, 2026
Backport #110246 to 26.4: Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
rschu1ze added a commit that referenced this pull request Jul 23, 2026
Backport #110246 to 26.6: Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
rschu1ze added a commit that referenced this pull request Jul 23, 2026
Backport #110246 to 26.7: Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 23, 2026
UnamedRus pushed a commit to UnamedRus/ClickHouse that referenced this pull request Aug 12, 2026
…ContainsKey/mapContainsValue with an empty needle
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…ContainsKey/mapContainsValue with an empty needle
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…ContainsKey/mapContainsValue with an empty needle
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
…ContainsKey/mapContainsValue with an empty needle
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Do not use text index for has/mapContainsKey/mapContainsValue with an empty needle
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
STOR: has / mapContains* with an empty needle and a text index -> wrong.
Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/110246.PROD263.txt).
Upstream patch unchanged, with its test(s): 02346_text_index_bug110092.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text index makes has(col, '') / mapContainsKey(m, '') / mapContainsValue(m, '') match all rows — empty needle is vacuously true

6 participants