Skip to content

Fix processAndOptimizeTextIndexFunctions when query_plan_merge_expressions = 0 - #100909

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
Ergus:Fix_100879
Mar 29, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
Ergus:Fix_100879

Conversation

@Ergus

@Ergus Ergus commented Mar 27, 2026 •

Copy link
Copy Markdown
Member

In this case ExpressionStep is directly above ReadFromMergeTree, and we need to handle that.

Fixes: #100879

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):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.379

…sions = 0

In this case ExpressionStep is directly above ReadFromMergeTree, and we need to handle that.

Fixes: ClickHouse#100879
@clickhouse-gh

clickhouse-gh Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3903e03]

Summary: ✅


AI Review

Summary

This PR fixes text-index optimization for plans where query_plan_merge_expressions = 0 by composing intermediate ExpressionStep DAGs before processing FilterStep, and adds a regression test covering both query_plan_direct_read_from_text_index = 0/1. I did not find new high-confidence correctness/safety/performance issues in the code changes.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ⚠️ Changelog category is valid, but Changelog entry is required for Bug Fix and is currently ... (not user-readable/specific).
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Replace Changelog entry with a specific user-facing description of the fixed misbehavior (instead of ...).

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 27, 2026
@@ -0,0 +1,36 @@
-- Test for issue #100879: hasAllTokens/hasAnyTokens give wrong results
-- with query_plan_merge_expressions = 0.

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.

Could we use the full setting name here for clarity (query_plan_merge_expressions instead of merge_expressions)? It helps readers quickly map the test comment to the exact setting being toggled below.

Copilot AI left a comment

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.

Pull request overview

Fixes incorrect hasAllTokens/hasAnyTokens behavior when query_plan_merge_expressions = 0 by ensuring text-index function preprocessing still works even if ExpressionStep nodes appear between ReadFromMergeTree and FilterStep.

Changes:

  • Added a stateless regression test covering both query_plan_merge_expressions = 1 and 0.
  • Updated processAndOptimizeTextIndexFunctions to find a FilterStep above the current node while collecting intermediate ExpressionSteps.
  • Composed/merged collected ExpressionStep DAGs into the filter DAG so text-index preprocessing can resolve physical column names correctly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/queries/0_stateless/02346_text_index_bug100879.sql Adds regression SQL reproducer for #100879 across merge-expressions on/off.
tests/queries/0_stateless/02346_text_index_bug100879.reference Adds expected output for the new regression test.
src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp Enhances optimization to handle ExpressionStep layers between read and filter by composing DAGs.

@CurtizJ CurtizJ self-assigned this Mar 27, 2026
@george-larionov

Copy link
Copy Markdown
Member

Probably this needs a backport?

@george-larionov george-larionov 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.

It looks good to me overall, just a minor comment and probably we need to mark it as backport needed.

@clickhouse-gh

clickhouse-gh Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 24.80% 24.50% -0.30%
Branches 76.70% 76.70% +0.00%

Changed lines: 96.88% (31/32) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov merged commit a35aabd into ClickHouse:master Mar 29, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 29, 2026
@rschu1ze rschu1ze added the pr-backport Changes, backported to release branch. Do not use manually - automated use only! label Apr 1, 2026
@rschu1ze

rschu1ze commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

@Ergus I know you put in some work into this PR. At the same time, Groene CI (the AI CI fixing bot) started to suppress similar failures caused by query_plan_merge_expressions = 0 in other tests by pinning the setting to = 1 at the beginning of the test, see here. The thing is that query_plan_merge_expressions is an expert-level setting (see Core/Settings.cpp) and stuff is expected to break if it's disabled. In practice, customers wouldn't disable the setting. I think the bot is right. Therefore, we can save the extra complexity in optimizeDirectReadFromTextIndex.cpp and simply pin the setting in the test. Wdyt?

alexey-milovidov added a commit that referenced this pull request Apr 29, 2026
- Fix typo: `behavoir` → `behavior` (also `prevent` → `prevents`).
- Replace placeholder entry for `#100909` with description of the
  `processAndOptimizeTextIndexFunctions` fix when
  `query_plan_merge_expressions = 0`.
- Replace placeholder entry for `#101230` with description of the
  `S3Queue` stale processing nodes cleanup fix.
- Rewrite the row-policies-in-`query_log` entry (`#101044`) for
  clarity, fixing typos (`sub queries`, `etc..to`, `palnner`,
  `were planner`).

PR: #103729

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

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default 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.

02346_text_index_bug89605 gives wrong result with query_plan_merge_expressions = 0

7 participants