Repository navigation
Cherry pick #110710 to 25.8: Fix text-index direct-read double-registration over Merge/Distributed - #111092
Closed
robot-ch-test-poll2 wants to merge 6 commits into
Closed
Cherry pick #110710 to 25.8: Fix text-index direct-read double-registration over Merge/Distributed#111092robot-ch-test-poll2 wants to merge 6 commits into
robot-ch-test-poll2 wants to merge 6 commits into
Conversation
optimizeDirectReadFromTextIndex can visit the same ReadFromMergeTree step more than once. When an identical text-index predicate is present in both PREWHERE and WHERE and the query is walked through a Merge -> Distributed -> MergeTree plan, the inner plan is optimized again while building the pipeline. On the first visit the pass rewrites PREWHERE and creates the index read tasks; on the second visit PREWHERE is already rewritten, so the WHERE branch runs and re-registers the same synthetic __text_index_..._has_<hash> read column, aborting with "Column ... already added for reading". Skip the pass for a step whose index read tasks are already populated: the optimization has already run for it and there is nothing left to do. Closes: #110697
The regression test's EXPLAIN visibility check asserts the text-index direct-read column appears in the plan. Under random setting prefer_localhost_replica=0 the Merge -> Distributed read is dispatched to the remote replica, so the MergeTree-level __text_index_..._has_<hash> column is absent from the initiator plan and the check spuriously reports 0. The double-registration bug being tested only engages on the local (initiator) optimization path, so pinning prefer_localhost_replica=1 keeps the test faithful to the bug while fixing the flakiness. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ix 04549 flakiness Address AI review on the earlier fix: the unconditional early return in processAndOptimizeTextIndexFunctions skipped the whole pass on any re-visit, which also dropped the tokenizer/preprocessor rewrite of a different text-index predicate pushed into a Merge child via ReadFromMerge::addFilter (semantic, not just perf). Instead, gate only the direct-read replacement on both the PREWHERE and WHERE branches by whether the step already carries index read tasks. A re-visit no longer re-registers the synthetic __text_index_..._has_<hash> column (no "already added for reading"), while the semantic rewrite still runs. Also stabilize the regression test 04549: pin query_plan_direct_read_from_text_index=1 on the EXPLAIN visibility query (the runner randomizes it; when off the optimization is disabled and the synthetic column is absent, so the visibility check spuriously returned 0). The crash-fix count() queries stay unpinned so both randomized values exercise the fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ewrite The extra query used has(...), which processTextIndexFunction does not rewrite, so it did not exercise the tokenizer/preprocessor rewrite path the fix preserves. Add a String column with its own text index and assert that a direct-read PREWHERE predicate combined with a DIFFERENT tokenizing WHERE predicate (hasAnyTokens) returns the same result for query_plan_direct_read_from_text_index = 0 and = 1, and that the WHERE predicate keeps its 3-argument tokenizer rewrite in EXPLAIN even when the step is re-visited after the PREWHERE already registered a direct-read column. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The double-registration abort is thrown during pipeline build (ReadFromMerge::initializePipeline -> buildQueryPipeline), only when direct read from the text index is enabled. The runner randomizes query_plan_direct_read_from_text_index to 0 on ~5% of runs, which disables the optimization and silently skips the crash path, so the crash-repro count() query must pin the setting to exercise the fix deterministically on every run. The pinned EXPLAIN visibility query does not cover this: EXPLAIN only builds and optimizes the plan and never calls buildQueryPipeline. The count()=1 crash-fix assertions are unchanged; the 0/1 comparison queries are kept for semantic coverage of the second-pass tokenizer rewrite. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…here-where-dup-110697 Fix text-index direct-read double-registration over Merge/Distributed
Member
|
Closing: this backport is not applicable to 25.8. The bug fixed by #110710 lives in the text-index direct-read optimization ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #110710
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job