Skip to content

Support text index built on mapValues with IN operator - #99286

Merged
CurtizJ merged 4 commits into
ClickHouse:masterfrom
CurtizJ:text-index-map-values-in-support
Mar 13, 2026
Merged

CurtizJ merged 4 commits into
ClickHouse:masterfrom
CurtizJ:text-index-map-values-in-support

Conversation

@CurtizJ

@CurtizJ CurtizJ commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Support text index built on mapValues(map) with IN operator.


Note

Medium Risk
Touches text-index condition building for IN (including tuple-IN) and changes when the index is considered applicable, which can affect query result correctness and granule skipping. Additional guardrails and new stateless tests reduce risk but this remains query-planner sensitive logic.

Overview
Enables using text indexes built on mapValues(map) to optimize IN/tuple-IN predicates on map element access (e.g. map['k'] IN (...)), by recognizing arrayElement(map, 'key') as indexable via a new hasIndexForMapElementValue() check.

Adds a correctness safeguard to disable text-index usage for IN sets containing empty strings (to avoid always-true-on-granule behavior), and introduces new stateless tests covering map-values IN, combined mapKeys/mapValues skipping, and empty-string edge cases.

Written by Cursor Bugbot for commit 7848b4f. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.633
  • Backported to: 26.2.5.23

@clickhouse-gh

clickhouse-gh Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7848b4f]

Summary: ❌

job_name test_name status info comment
Finish Workflow error IGNORED

AI Review

1) Summary

This PR enables text-index analysis for mapValues(map) in IN/tuple-IN predicates on arrayElement(map, 'key'), adds an empty-string guard in set preparation, and introduces new stateless coverage for IN behavior on map keys/values. High-level verdict: the implementation looks directionally correct, but test coverage is still incomplete for the newly-enabled notIn path.

2) Missing context (if any)

  • No CI logs/results were provided in this review context.
  • No benchmark data was provided for planner/index-usage changes.

3) Findings (by severity)

Blockers

  • None.

Majors

  • [src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:803] The new hasIndexForMapElementValue branch is used from tryPrepareSetForTextSearch for set operators, which includes notIn, but newly added tests cover only IN cases. This leaves planner/granule-skipping behavior for map['k'] NOT IN (...) (including tuple variants) unprotected.
    • Suggested fix: add dedicated stateless tests for map-element NOT IN and tuple NOT IN with map elements, including EXPLAIN indexes = 1 assertions.

4) Tests & Evidence

  • Positives: added tests validate IN on mapValues, tuple IN, combined map key/value indexes, and empty-string edge behavior.
  • Negatives/error paths: missing explicit NOT IN cases for the new map-element set path.
  • Additional tests to add:
    • map['service'] NOT IN ('frontend') on mapValues text index.
    • tuple NOT IN where one tuple element is map['service'].
    • mixed-set edge case for NOT IN with multiple literals and explain-based granule checks.

5) ClickHouse Compliance Checklist (Yes/No + short note)

  • Data deletions logged? Yes — no deletion-path changes in this PR.
  • Serialization formats versioned? Yes — no serialization/protocol changes.
  • Experimental setting gate present? Yes — behavior extends existing text-index capability, no new feature flag needed.
  • Settings exposed for constants/thresholds? Yes — no new constants introduced.
  • Backward compatibility preserved? Yes — query semantics unchanged; only index applicability logic adjusted.
  • SettingsHistory.cpp updated for new/changed settings? N/A — no settings added/changed.
  • Existing tests untouched (only additions)? Yes — only new stateless tests were added.
  • Docs/user-facing notes updated? No — changelog entry is present, no doc changes.
  • Core-area change got extra scrutiny? Yes — MergeTree text-index condition path reviewed.

6) Performance & Safety Notes

  • Safety: new empty-string set-element rejection in tryPrepareSetForTextSearch avoids always-true token checks on granules.
  • Performance: enabling map-element IN with mapValues can improve skipping in relevant workloads; missing NOT IN tests is the main regression risk.
  • Benchmarks: none provided; a minimal benchmark should compare IN/NOT IN query scan granules before/after on large Map(String, String) data.

7) User-Lens Review

The feature is intuitive (map['k'] IN (...) can now leverage mapValues text index) and the added empty-value guard improves robustness. The main surprising part is uncovered NOT IN behavior for the same path, which should be documented by tests to keep operator behavior predictable for users/operators.

8) Final Verdict

  • Status: Request changes
  • Minimum required actions to approve:
    1. Add stateless tests for map['k'] NOT IN (...) and tuple NOT IN with map element operands.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 11, 2026
{
if (header.has(function.getArgumentAt(i).getColumnName()))
auto argument = function.getArgumentAt(i);
if (header.has(argument.getColumnName()) || hasIndexForMapElementValue(argument))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This new hasIndexForMapElementValue path extends set-based optimization to map-element predicates for both in and notIn, but there is no coverage for NOT IN on map elements. Please add stateless tests for map['k'] NOT IN (...) (and tuple NOT IN with a map element) to lock down granule-skipping behavior for the newly-enabled branch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The support for NOT IN doesn't really work (the index never skips granules) and it will be removed soon. So, test is not needed.

@clickhouse-gh

clickhouse-gh Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.80% 23.90% +0.10%
Branches 76.40% 76.30% -0.10%

PR changed lines: PR changed-lines coverage: 100.00% (35/35)
Diff coverage report
Uncovered code

@ahmadov ahmadov self-assigned this Mar 12, 2026
@CurtizJ
CurtizJ added this pull request to the merge queue Mar 13, 2026
Merged via the queue into ClickHouse:master with commit a9e0c3a Mar 13, 2026
317 of 319 checks passed
@CurtizJ
CurtizJ deleted the text-index-map-values-in-support branch March 13, 2026 00:47
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 13, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 13, 2026
robot-clickhouse added a commit that referenced this pull request Mar 13, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Mar 13, 2026
Backport #99286 to 26.2: Support text index built on `mapValues` with `IN` operator
@ahmadov ahmadov added the post-approved Approved, but after the PR is merged. label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements 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 v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants