Repository navigation
Conversation
A direct read from a text index adds ephemeral virtual columns (__text_index_idx_...) to the MergeTree read plus a separate index-read step. A distributed worker fragment cannot reproduce these: the virtual column is not in the table and ReadFromDistributedPlanSource cannot materialize it. buildQueryPipeline runs the second optimization pass once via optimize() and, for make_distributed_plan, again via convertToDistributed(). The text index optimization is not idempotent (it appends the virtual column to all_column_names), so the single-stage re-optimization re-adds the same column and aborts with the LOGICAL_ERROR "Column ... already added for reading" (server abort in debug/sanitizer builds). The multi-stage path instead fails at execution with NOT_FOUND_COLUMN_IN_BLOCK. Reject the unsupported combination cleanly at planning time in checkDistributedReadSupported, next to the existing rejections for pinned block-number boundaries and part-order virtual columns. Found by the AST fuzzer (STID 4792-6322). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260629-134800 |
|
cc @kssenii @CurtizJ — could you review this? It rejects |
|
Workflow [PR], commit [95e2471] Summary: ❌
AI ReviewSummaryThis PR moves the text-index guard to the point where the optimizer already knows whether a Documented surface
Final Verdict✅ No new findings. |
CI finish ledger — 867d48cEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
This PR's own fix (the make_distributed_plan + text-index direct-read LOGICAL_ERROR, STID 4792-6322) and its regression test 04417 are green. The lone red check is the pre-existing chronic UnionStep block-structure-mismatch (STID 0993-27f0), owned by open fixing PR #107719. Session id: cron:our-pr-ci-monitor:20260629-183000 |
The guard was unconditional, so it also rejected queries whose plan is not split into fragments. Such a plan is executed locally, the synthetic __text_index_..._has_<hash> column never has to be reconstructed on a worker, and the query runs correctly today. Rejecting it was a regression. Whether a read ends up inside a shipped fragment is only decided by the tryMakeDistributed* transforms and the exchange optimization, both of which run after checkDistributedReadSupported. The check therefore moves to a separate pass that runs after them and returns early when the plan contains no exchange step, which is exactly when makeDistributedPlan produces a single stage that QueryPlan::convertToDistributed keeps local. The single-stage LOGICAL_ERROR "Column ... already added for reading" the original guard also covered no longer happens: the direct read pass bails out once index read tasks are present (ClickHouse#111930). What remains is the multi-stage failure, where a worker rebuilds the fragment against the table and the synthetic column is missing (NOT_FOUND_COLUMN_IN_BLOCK at execution). Verified against a server with the stateless worker enabled: all four shipped shapes in the test fail with that error on master and are rejected at planning time with the fix, while both single-stage shapes return the same rows as the non-distributed plan in either build. The hasTextIndexReadTasks accessor is dropped: getIndexReadTasks is public.
…up_by Three fixes from the second-model review of the previous commit. The new pass was gated on the local `make_distributed_plan`, which is false once the plan already carries exchanges. StorageMerge pushes a filter into a child plan and re-runs the second pass on it, so the direct read can be applied for the first time during such a later run and the guard would be skipped. Gate on the raw setting instead, like the neighbouring `optimizeExchanges` and `materializeConstantsForSetOperationBranches` calls. Not reachable today (ReadFromMerge is rejected earlier as non-serializable), so no test. distributed_plan_single_stage keeps every exchange inside one local stage, so exchange presence alone no longer means the read is shipped. Skip the check in that mode, otherwise the promised single-stage behavior breaks for that debugging path. The three count() queries in the test asserted only the error code, and the test profile sets max_rows_to_group_by, which makes tryMakeDistributedAggregation throw the same SUPPORT_IS_DISABLED code before the new check is reached. Measured: with max_rows_to_group_by = 10G those queries throw "does not support aggregation with max_rows_to_group_by" even with direct text index reading disabled, so all three assertions passed for the wrong reason. Pin the setting to 0, as 04320_distributed_plan_read_rejects already does.
Two more oracle problems from the second-model review. All the rejection queries accepted only the error code, and a server without a stateless worker client throws the same SUPPORT_IS_DISABLED code from DistributedPlanExecutor while constructing the executor, so the assertions did not distinguish the planning rejection from a missing worker. Set distributed_plan_execute_locally = 1, as the 19 sibling distributed_plan tests do. On master the queries now fail with the actual defect (NOT_FOUND_COLUMN_IN_BLOCK for the synthetic __text_index_ column) instead of a generic code, which is a much sharper pre-fix signal. The two single-stage queries only compared rows, which a plan silently falling back to a per-row function evaluation would also satisfy. Add a plan oracle asserting the synthetic __text_index_ column is present, so the rows prove direct read really was applied. Measured with direct read disabled it returns 0, so the assertion is discriminating. The outer SELECT pins make_distributed_plan to 0 because the EXPLAIN wrapper itself is not serializable. Also add the missing hasAllTokens carrier, verified to fail on master with the same missing-column error.
The second-model review pointed out that a subplan with text index tasks and no exchange of its own is attached beneath an outer plan that does have exchanges, so the read is still shipped. Measured: a join whose right side is a local text index read fails on master with the same missing-column error and is rejected by this change, because the guard runs on the whole plan after the subplans are attached. Add it as a regression case.
CI finish ledger - 6f8d218Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The fixing pull request for the first row is merged but is not yet on this branch, so the Session id: cron:our-pr-ci-monitor:20260730-163853 |
…ndex-make-distributed-plan-4792-6322
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code |
CI finish ledger - 95e2471Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
All 174 check-runs on this commit are completed and this is the only failing check. Not caused by This discharges the link-back promised on the previous head's ledger The Session id: cron:our-pr-ci-monitor:20260730-230000 |
|
@groeneai Post a minimal reproducible example. |
|
Needs a server with the stateless worker enabled ( SET allow_experimental_full_text_index = 1;
CREATE TABLE t_min (s String, INDEX idx s TYPE text(tokenizer = 'splitByNonAlpha'))
ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t_min VALUES ('uniform');
SELECT count() FROM t_min WHERE hasToken(s, 'uniform')
SETTINGS make_distributed_plan = 1, distributed_plan_execute_locally = 1;On 26.7.4.12: Direct read replaces One thing you should know before deciding on this PR: the same file returns So I would rather close this PR than narrow it further, unless you want the reject kept as the permanent guard for when that override is removed. Your call. |
Add to 04836 and 04837 the scenarios that the rejected-behavior tests of the superseded PRs covered and the new positive tests did not: the AST fuzzer shape with a mixed PREWHERE conjunction and a xor in WHERE, a text index read shipped through a subquery under a shuffle join (both from ClickHouse#108818), and a join whose side carries a direct text-index read with a filter-sensitive result (from ClickHouse#112723). Every query is repeated with the distributed mode off and must return identical results. Related: ClickHouse#108818 Related: ClickHouse#112723 Co-Authored-By: Claude Fable 5 <[email protected]>
|
I'm trying to add proper support in #114242. Closing this for now. |
Related: #108256
Related: #110710
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
NOT_FOUND_COLUMN_IN_BLOCKwhen running a query withmake_distributed_plan = 1over aMergeTreetable that does a direct read from a text index (hasToken,hasAnyTokens,hasAllTokens). Such a read is now rejected at planning time when the plan is split into fragments; a plan that stays single-stage is executed locally and keeps working.Description
Direct read from a text index replaces a text-search function with a synthetic
__text_index_..._has_<hash>column that exists only in the coordinator'sReadFromMergeTreestep. A worker rebuilds its fragment against the table, where that column does not exist, so the read fails at execution:surfacing to the client as
RECEIVED_ERROR_FROM_REMOTE_IO_SERVER. The fix rejects such a read at planning time, next to the existing rejections for pinned block-number boundaries and the part-order virtual columns, and mirrors #108256 which rejects projections for distributed reads for the same reason.Only a plan that is actually split into fragments ships the read. The check therefore runs in its own pass after the
tryMakeDistributed*transforms and the exchange optimization, which is what decides whether a fragment is created, and returns early when the plan has no exchange step, i.e. exactly whenmakeDistributedPlanproduces a single stage thatQueryPlan::convertToDistributedkeeps local. Next tocheckDistributedReadSupportedwould be too early: the exchange topology does not exist yet, so every direct text index read would be rejected, including the ones that run locally and correctly today.This PR originally also covered a single-stage
LOGICAL_ERROR(Column ... already added for reading) from re-running the non-idempotent text index optimization. That no longer happens: the pass skips repeated direct-read registration once index read tasks are present (#110710), so only the shipped-fragment failure remains.Verified against a server with the stateless worker enabled: every shipped shape in the test, including a text index read reached through a join, fails with the missing-column error on master and is rejected at planning time with this change, while both single-stage shapes return the same rows as the non-distributed plan in either build. Found by the AST fuzzer,
AST fuzzer (amd_debug, targeted), STID 4792-6322.