Skip to content

Fix server crash in text index direct read when a filter uses a derived expression - #111844

Closed
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-4792-5e4c-text-index-createreadtasks-erase
Closed

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:fix-4792-5e4c-text-index-createreadtasks-erase

Conversation

@groeneai

@groeneai groeneai commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

Only affects enable_analyzer = 0.

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

Fixes a server abort in the text index direct-read optimization when a text-search predicate is applied to a derived expression, either an ALIAS column or an index expression such as mapValues(attributes), and the rewrite happens in the WHERE filter step. The optimization tried to prune a filter-expression input name that is not a physical read column. Only affects enable_analyzer = 0.

Description

Found by the AST fuzzer (AST fuzzer (amd_debug)), STID 4792-5e4c: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109524&sha=5a447113dcb18b89e0b150c7dc4efb65ff114342&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 Trunk bug, not caused by any single pull request: 11 unrelated pull requests plus master since 2026-07-02. Most recent on master: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d59f2be34ed39b45665de8c5afe3b333239befeb&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

removed_columns is the set of filter DAG inputs the text-search rewrite no longer needs. When the text index is on a derived expression, the old analyzer names such an input after the expression itself (mapValues(attributes), or the expression behind an ALIAS column), which is not a column the reading step reads. createReadTasksForTextIndex looked that name up in the physical read set and called vector::erase on end(). That aborts in debug and in release builds, since libc++ _LIBCPP_HARDENING_MODE_FAST keeps the valid-iterator check active.

processAndOptimizeTextIndexDAG now drops such a name from removed_columns and re-adds it as a DAG input. This removes the state that made the erase miss, and it also stops ActionsDAG::updateHeader from re-appending the derived column to the filter step's output header. Measured with EXPLAIN header = 1: the filter step carried mapValues(attributes) Array(String) with query_plan_direct_read_from_text_index = 1 and was empty with it off, while results and final query headers were correct either way. The header half was reported by @ ahmadov in review.

It requires enable_analyzer = 0; the analyzer does not name that filter input after the expression. It needs neither Merge nor Distributed: a toLowCardinality needle in PREWHERE is declined by the direct read, so the rewrite falls through to the WHERE FilterStep, which is the only place the derived name is a DAG input.

Both tests assert results rather than only non-crashing, and carry EXPLAIN oracles pinning that the optimization stays engaged and that the filter header does not widen.

Reproducers (both abort on master)

Plain MergeTree, text index on an expression:

SET enable_full_text_index = 1, enable_analyzer = 0, query_plan_direct_read_from_text_index = 1;
CREATE TABLE t (id UInt64, attributes Map(String, String),
    INDEX idx_vals mapValues(attributes) TYPE text(tokenizer = 'array'))
ENGINE = MergeTree ORDER BY id;
INSERT INTO t VALUES (1, {'ip':'192.168.1.1'});
SELECT id FROM t PREWHERE has(mapValues(attributes), toLowCardinality('zzz'))
WHERE has(mapValues(attributes), '192.168.1.1');

Merge -> Distributed -> MergeTree, where ReadFromMerge pushes the filter into the child plan:

SET enable_full_text_index = 1;
CREATE TABLE logs (ts DateTime, attributes Map(String, String),
    INDEX attributes_vals_idx mapValues(attributes) TYPE text(tokenizer = 'array'))
ENGINE = MergeTree ORDER BY ts;
INSERT INTO logs VALUES (1, {'ip':'192.168.1.1'});
CREATE TABLE logs_dist AS logs ENGINE = Distributed(test_shard_localhost, currentDatabase(), logs);
CREATE TABLE logs_merge AS logs ENGINE = Merge(currentDatabase(), '^logs_dist$');

SELECT count() FROM logs_merge
PREWHERE hasAnyTokens(mapValues(attributes), toLowCardinality('0'))
WHERE has(mapValues(attributes), '192.168.1.1')
SETTINGS query_plan_direct_read_from_text_index = 1, enable_analyzer = 0;

The fuzzed query from the master report is the first shape over an ALIAS column, using the table from 04141_text_index_alias_lambda_with_constants. The server logged the derived name it then failed to erase:

processAndOptimizeTextIndexFunctions: Added: [__text_index_idx_kw_text_has_b747...],
Removed: [arrayMap(lambda(tuple(select), concat('-', select)), arr)]

No related open issue found.


Workflow [PR]
Sync PR [sync-upstream/pr/111844]

…lter expression

createReadTasksForTextIndex erased each removed_columns entry from all_column_names
without checking presence. removed_columns comes from the filter DAG and can contain
derived expression names (e.g. mapValues(attributes)) that are not physical read
columns, so std::ranges::find returns end() and erase(end()) aborts the server
(debug and release: release uses libc++ FAST hardening which keeps the erase
valid-iterator check). Guard the erase, matching the idiom used for every other
all_column_names mutation in this file.

Found by AST fuzzer (amd_debug), STID 4792-5e4c.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT count() FROM logs_merge PREWHERE hasAnyTokens(mapValues(attributes), toLowCardinality('0')) WHERE has(mapValues(attributes), '192.168.1.1') SETTINGS query_plan_direct_read_from_text_index=1, enable_analyzer=0; over Merge -> Distributed -> MergeTree with a text index on mapValues(attributes). Aborts every run on master; local stack byte-identical to CI STID 4792-5e4c.
b Root cause explained? Yes. TextIndexDAGReplacer::replace computes removed_columns = (filter-DAG required inputs before rewrite) minus (after rewrite + removeUnusedActions). Those are filter-expression names and can be derived nodes (mapValues(attributes)). createReadTasksForTextIndex erases them from all_column_names, the reading step's physical read set (source columns like attributes). A derived name is absent -> find returns end() -> erase(end()) is UB -> abort.
c Fix matches root cause? Yes. The loop only needs to prune columns present in the read set; a removed filter input that was never a physical read column has nothing to prune. Guard the erase with find() != end().
d Test intent preserved / new tests? New test 04628_text_index_removed_column_erase_over_merge. Pins the exact trigger (enable_analyzer=0, query_plan_direct_read_from_text_index=1), asserts correct results, and asserts the direct-read optimization stays engaged over the same logs_merge topology (present with the setting on, absent with it off).
e Demonstrated both directions? Yes. Without fix: server abort (signal 6). With fix: 0/1/1/0, server alive. Test fails (server death) without the fix, passes with it.
f Fix general, not a narrow patch? Yes. This is the only unguarded erase(it) on all_column_names in the file; every other mutation already guards (lines 3231 std::erase, 3246/3251/3697 find()!=end()). The fix brings the outlier in line.
g Generalizes across inputs? Yes. The guard is input-agnostic (erase iff present). Verified with the derived-expression trigger and a matching-row variant; 100 executions with varied max_threads/optimize_move_to_prewhere all passed. Cannot regress the present-column case.
h Backward compatible? Yes. No setting/format/validation change; pure in-memory query-plan guard. SettingsChangesHistory.cpp not touched.
i Invariants preserved? Yes. all_column_names is the physical read set; removed_columns is a best-effort hint whose namespace need not intersect it. The guard upholds "only erase members of the read set" on all paths.

Session id: cron:clickhouse-author-slot-2:20260724-174000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

An independent model reviewed the diff before this PR was opened. Dispositions below.

❌ Blockers: none.

⚠️ Majors:

  • Test liveness — direct-read preservation assertion checked the wrong table. AGREE, fixed. The original assertion ran EXPLAIN over logs (plain MergeTree), not logs_merge (the triggering topology), so it would still pass if direct read silently declined only through the Merge path. Rewrote it to assert over logs_merge with a discriminating oracle: the synthetic __text_index_attributes_vals_idx column is present with query_plan_direct_read_from_text_index = 1 and absent with = 0.

💡 Nits:

  • Opening comment reproduced the internal postmortem. AGREE, fixed. Trimmed the 8-line comment to two lines pointing at the commit message.
  • Suggested changelog category Critical Bug Fix. DISAGREE. Critical Bug Fix is left for a maintainer to choose; Bug Fix (user-visible misbehavior in an official stable release) is the default for a user-visible server abort, and a maintainer can upgrade the category if warranted.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @ahmadov @Ergus — could you review this? It fixes a server abort in the text-index direct-read optimization: createReadTasksForTextIndex erased a removed_columns entry from the reading step's physical read set without checking presence, but that set can contain a derived filter-expression name (e.g. mapValues(attributes)) that is not a physical read column, so erase(end()) aborted the server over a Merge -> Distributed -> MergeTree plan.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f93f7e7]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Bugfix validation (functional tests, amd64) ERROR
Server startup (amd_msan) ERROR cidb
Scraping system tables FAIL cidb
Bugfix validation (functional tests, aarch64) ERROR
Server startup (arm_msan) ERROR cidb
Scraping system tables FAIL cidb

AI Review

Summary

This PR fixes the original erase(end()) failure and the header-widening follow-up for derived text-index expressions under enable_analyzer = 0, but one pass-through case still looks incorrect: when the direct-read rewrite removes the derived expression from the filter and that expression is only needed above the FilterStep, the rebuilt filter can still drop it from its output. I would not approve the PR until that case is either fixed or disproved with a focused regression test.

Findings

❌ Blockers

  • [src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp:1073-1087] The new addInput fallback still breaks the pass-through-only shape it was meant to preserve. For an exact direct-read predicate such as hasAnyTokens (src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:296-300), replaceFunctionsToVirtualColumns can replace the filter with only the synthetic __text_index_... input (optimizeDirectReadFromTextIndex.cpp:1008-1013), which puts the derived expression name into result.removed_columns. The new branch then removes that name from removed_columns and re-adds it only as a DAG input (:1085-1086). ActionsDAG::updateHeader treats matched inputs as consumed pass-through (src/Interpreters/ActionsDAG.cpp:1545-1583), so if the query selects mapValues(attributes) / arr_prefixed above the filter but does not reference it anywhere else in the filter, the rebuilt FilterStep can still drop the selected column from its output.
    Suggested fix: either keep pass-through-only derived columns as DAG outputs when rebuilding the filter, or add a focused regression query such as SELECT mapValues(attributes) ... WHERE hasAnyTokens(mapValues(attributes), toLowCardinality(...)) (and the ALIAS analogue) and make the implementation satisfy it.
Final Verdict

Status: ❌ Block

  • Minimum required action: fix or disprove the pass-through-only derived-column regression in processAndOptimizeTextIndexDAG; the current tests added in 04628/04926 still keep the derived name live inside WHERE, so they do not cover that case.

LLVM Coverage Report

Measured on commit f93f7e7.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

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

Full report · Diff report

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

clickhouse-gh Bot commented Jul 26, 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.40% 78.40% +0.00%

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

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 06f3afa

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_debug) / Logical error: Inconsistent KeyCondition behavior (STID 5182-2f27) wide-typed key comparison inserts a CAST into the monotonic chain, so matchesExactContinuousRange() promises exact continuity it cannot deliver #109023 (ours, open)
Mergeable Check / PR rollup of the above resolved via the owner above

The server log names the aborting query and the participating conditions, which is what pins the owner:

Inconsistent KeyCondition behavior: matchesExactContinuousRange() reported an exact continuous
range, but the mark range [224, 250) (exact subrange [225, 250)) of part all_2_2_0 is not exactly
continuous. Participating conditions: (_CAST(column 0) in ['9', '9']), (column 1 in (-Inf, 99])
query: SELECT count() FROM t_big WHERE (g = toUInt128(9)) AND (r < 100)

_CAST on the leading key column is the decisive datum: the monotonic function chain is non-empty,
which is exactly the case #109023 stops treating as Constraint::POINT.

Not caused by this PR: the diff is a find() bounds guard in ReadFromMergeTree::createReadTasksForTextIndex
and a stateless test; it does not touch KeyCondition, primary-key analysis, or mark-range selection.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111844&sha=06f3afa9ad5128c5505a541b828c742cf696ff28&name_0=PR&name_1=Stress%20test%20%28amd_debug%29

Session id: cron:our-pr-ci-monitor:20260726-083000

@PedroTadim

Copy link
Copy Markdown
Member

cc @CurtizJ

The `AST fuzzer (amd_debug)` hit this abort on master again (STID 4792-5e4c):

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d59f2be34ed39b45665de8c5afe3b333239befeb&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

The fuzzed query has no `Merge` and no `Distributed` table. It runs over the
`04141_text_index_alias_lambda_with_constants` table, where `arr_keyword` is an
`ALIAS` column bound to a text index:

    SELECT user_id, NULL FROM t_quoted_lambda
    PREWHERE has(arr_keyword, toLowCardinality('[]'))
    WHERE has(arr_keyword, '340282346638528859811704183484516925440.000000')
    GROUP BY ALL

The server logged

    processAndOptimizeTextIndexFunctions: Added: [__text_index_idx_kw_text_has_b747...],
    Removed: [arrayMap(lambda(tuple(select), concat('-', select)), arr)]

and aborted in `createReadTasksForTextIndex` on `all_column_names.erase(end())`,
with a stack identical to the one this pull request already fixes.

So the `Merge` topology was incidental. What the abort actually needs is for the
text-search rewrite to happen in the WHERE `FilterStep` rather than in PREWHERE,
because only there is the derived expression a DAG input. Reducing the fuzzed
query isolates the trigger: a `toLowCardinality` needle makes the direct read
decline the PREWHERE predicate, so `processAndOptimizeTextIndexFunctions` falls
through to the `FilterStep` DAG. It also needs `enable_analyzer = 0`; the
analyzer does not name that input after the expression.

The new test covers both derived shapes on a plain `MergeTree`: a text index on
an `ALIAS` column whose expression is a lambda, and a text index on
`mapValues(attributes)`. Both abort on master and pass with the fix. An
`EXPLAIN actions` oracle keeps the fix from silently disabling the direct read:
the synthetic `__text_index_idx_vals` column must be in the plan with
`query_plan_direct_read_from_text_index = 1` and absent with it set to `0`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

This aborted master again on 2026-08-17: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=d59f2be34ed39b45665de8c5afe3b333239befeb&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

Pushed b787ff3 with a second test, and corrected the description: the Merge/Distributed framing in the original write-up was wrong. Details, all reproduced locally on d59f2be34ed:

The topology is irrelevant. A plain MergeTree is enough. What the abort needs is for the text-search rewrite to land in the WHERE FilterStep instead of PREWHERE, since only there is the derived expression a DAG input (optimizeDirectReadFromTextIndex.cpp:941, not the PREWHERE call site). A toLowCardinality needle in PREWHERE is one way to get there - the direct read declines that predicate, so processAndOptimizeTextIndexFunctions falls through:

SET allow_experimental_full_text_index = 1, enable_full_text_index = 1;
SET query_plan_direct_read_from_text_index = 1, enable_analyzer = 0;
CREATE TABLE t (id UInt64, attributes Map(String, String),
    INDEX idx_vals mapValues(attributes) TYPE text(tokenizer = 'array') GRANULARITY 1)
ENGINE = MergeTree ORDER BY id;
INSERT INTO t VALUES (1, {'ip':'192.168.1.1'});
SELECT id FROM t PREWHERE has(mapValues(attributes), toLowCardinality('zzz'))
WHERE has(mapValues(attributes), '192.168.1.1');

It needs enable_analyzer = 0. With the analyzer the filter input is not named after the expression, and neither reproducer aborts.

An ALIAS column hits it too, which is what the fuzzer found: the table from 04141_text_index_alias_lambda_with_constants, where arr_keyword is arrayMap(select -> concat('-', select), arr) with a text index on it. The fuzzed query was

SELECT user_id, NULL FROM t_quoted_lambda
PREWHERE has(arr_keyword, toLowCardinality('[]'))
WHERE has(arr_keyword, '340282346638528859811704183484516925440.000000')
GROUP BY ALL

and the server logged the derived name it then failed to erase:

processAndOptimizeTextIndexFunctions: Added: [__text_index_idx_kw_text_has_b747...],
Removed: [arrayMap(lambda(tuple(select), concat('-', select)), arr)]

It aborts release builds, not only debug. Verified with the official arm_release binary for d59f2be34ed: exit 134 on the same _LIBCPP_HARDENING_MODE_FAST vector::erase check.

Local verification of this branch's fix, built at d59f2be34ed (RelWithDebInfo):

  • both reproducers and the fuzzed query abort without the guard and pass with it, with correct results;
  • the existing 04628 test's Merge -> Distributed reproducer passes;
  • 04141_text_index_alias_lambda_with_constants passes;
  • the text_index stateless subset (182 tests) was run twice with settings randomization off - once with the patched binary, once with the stock d59f2be34ed release binary - and the failing sets are identical (35 tests, all artifacts of my bare local server config, e.g. missing system.query_log). No regression. That is expected: when the name is found the code path is byte-identical, so the guard can only change behaviour for input that previously aborted.

Fuzzer history for STID 4792-5e4c: 11 unrelated pull requests plus master since 2026-07-02, so it is still firing while this sits unreviewed. cc @ahmadov @CurtizJ - could one of you take a look?

@groeneai groeneai changed the title Fix server crash in text index direct read when a filter uses a derived expression over a Merge table Fix server crash in text index direct read when a filter uses a derived expression Aug 18, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

You are right that the topology framing was wrong: the precondition is the rewrite landing in the WHERE FilterStep, not Merge or Distributed. I generalized from the single shape the fuzzer had given me.

I updated the title, which still said "over a Merge table". The description is yours now, so I left it as you wrote it, and the guard itself is unchanged.

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f93f7e7ca with master 602ce8d11 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 39 s compile time in total, 8 of them have a recent master baseline.

Job report

…04926

The flaky check failed 11 times across five lanes with
"Code: 10 NOT_FOUND_COLUMN_IN_BLOCK: Not found column arr_prefixed" on
query 8. The indexed column is an ALIAS, and the test runner randomizes
optimize_respect_aliases to 0 with ~5% probability
(tests/clickhouse-test:1520). Without alias substitution the old analyzer
cannot resolve an ALIAS column referenced in PREWHERE, so the query fails
before the text-index path is reached. Measured on this branch with the
runner and randomization active: 4 failures in 60 runs before the pin, 0
in 40 after it. The failure is not specific to text indexes or to this
fix; the same PREWHERE on an ALIAS column fails identically on a table
with no index at all.

A query-level SET overrides the runner injection, so the pin goes beside
the settings the test already relies on, rather than a no-random-settings
tag that would drop the remaining coverage.

Also add the EXPLAIN actions on/off oracle to the ALIAS section, matching
the one the expression section already has. The ALIAS queries asserted
result correctness only, and those results are identical whether or not
the rewrite happens, so the section could not detect the direct read
silently ceasing to engage on the shape the master fuzzer actually hit.
Verified discriminating: forcing the on-arm setting to 0 changes the
expected 1 to 0.
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai forget the old analyzer

@PedroTadim PedroTadim closed this Aug 18, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

The guard here is old-analyzer-only: both reproducers abort with enable_analyzer = 0 and return correct results with the default analyzer, so closing this drops the whole fix rather than just a test detail.

The abort is still hitting master (d59f2be34ed, 2026-08-17), and @ alexey-milovidov reported it reaching release builds as well and pushed a second test here a few hours earlier.

Should the one-line guard still land without the old-analyzer tests, or do you want this left unfixed? I will not reopen either way.

@alexey-milovidov

Copy link
Copy Markdown
Member

It reproduces. Either we continue here or we need a big decision - prohibiting the old analyzer in Stress and Fuzz tests.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The constraint you would reach for already exists: <enable_analyzer><min>1</min> in query-fuzzer-tweaks-users.xml. I tested it against a master debug server and it does hold - SET enable_analyzer = 0, the allow_experimental_analyzer spelling, and a query-level SETTINGS clause are all rejected with SETTING_CONSTRAINT_VIOLATION.

The old analyzer arrives through compatibility instead, which sets it with no violation raised. The plain AST fuzzer (amd_debug) job draws a random randint(24, 27).randint(1, 12) version, and of those 48 draws only 24.1 and 24.2 disable the analyzer, so roughly 4 percent of runs. That fits the 90 day split for this abort: 7 rows from the plain variant including the single master hit, 7 from old_compatibility, which is itself pinned to 24.3 because that is the first version keeping the analyzer on.

So the fuzz side of a prohibition is small, just raising that random floor to 24.3. The stateless side is not: 252 corpus files set the old analyzer in their own SQL, and with such a constraint installed those turn into SETTING_CONSTRAINT_VIOLATION failures rather than analyzer coverage.

My suggestion is to land the guard here and keep the prohibition as its own decision. The guard is 5 lines and cannot change behaviour when the name is found, so it is unaffected either way.

@groeneai groeneai added the groeneai-origin-unknown PR origin: unclassified (legacy task) label Aug 19, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master (887b93e16db9) into the branch; the merge was clean and the net diff is unchanged (the 5-line find bounds guard in ReadFromMergeTree::createReadTasksForTextIndex plus the two stateless tests).

Re-verified locally on the merged branch, RelWithDebInfo:

  • with the guard, 04628_text_index_removed_column_erase_over_merge and 04926_text_index_direct_read_derived_column_removed_name both pass and match their references;
  • with the guard reverted on the same merged tree, 04628 fails on the abort trigger and the server goes down, so 04926 cannot even connect (Connection refused).

So the abort still reproduces on current master and the fix is still required. All settings the tests rely on (allow_experimental_full_text_index, enable_full_text_index, query_plan_direct_read_from_text_index, optimize_respect_aliases, enable_analyzer) still exist.

The only thing outstanding is the open question from the discussion above - land the guard here, or take the separate decision about prohibiting the old analyzer in Stress and Fuzz tests. That is a maintainer call; cc @ahmadov @CurtizJ @PedroTadim.

The EXPLAIN arms used a plain String needle, which does not reach the
pruning this pull request bounds. On the merge-base build (887b93e,
no guard) that query returns 1 and the server stays up, while the same
query with the reproducer's toLowCardinality('0') needle aborts in
vector::erase. The arms were therefore green for a reason unrelated to
the fix, and would stay green if the WHERE rewrite regressed.

The discriminator is the LowCardinality wrapper, not whether the needle
matches: a plain non-matching needle survives that build, a
LowCardinality matching needle aborts it. That is the decline-in-PREWHERE
fall-through to the FilterStep DAG which 04926 already documents.

Values are unchanged (1 with the setting on, 0 with it off), so the
reference is untouched. 50 runs of both tests with randomization active
pass.
@ahmadov ahmadov self-assigned this Aug 26, 2026

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.

this test looks similar to 04549_text_index_prewhere_where_dup_over_merge_distributed, should we merge them?

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.

🕵 Leaving this one to you, since it is a scope call rather than a mechanical one. The fixture is the same, but 04549_text_index_prewhere_where_dup_over_merge_distributed sets enable_analyzer = 1 file-wide and this shape only reaches the derived-name path with enable_analyzer = 0, so merging them would place an old-analyzer arm inside an existing master test - which is exactly what @PedroTadim and @rschu1ze have asked this PR not to carry. If you would rather have one file anyway, say so and I will fold 04628 into 04549 with the two arms carrying their own SETTINGS enable_analyzer = 0.

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.

🕵 Now moot. enable_analyzer = 0 is rejected on master since 499465b, so this test can no longer reach the old-analyzer path it was written for. I suggest closing the PR as obsolete instead of merging the tests: #111844 (comment)

… input

`removed_columns` holds filter DAG input names. When a text index is defined on a
derived expression, the old analyzer names a filter DAG input after the expression
itself (`mapValues(attributes)`, `arrayMap(lambda(tuple(x), concat('-', x)), arr)`),
which is not a column the reading step reads. Pruning such a name from the read set
does nothing, and because the rewrite has already dropped it as a DAG input,
`ActionsDAG::updateHeader` re-appends it to the filter step's output header.

Measured with `EXPLAIN header = 1` on the 04628 shape: the filter step's output header
carried `mapValues(attributes) Array(String)` with
`query_plan_direct_read_from_text_index = 1` and was empty with it off. The ALIAS shape
in 04926 widened the same way. Final query headers and row values were correct in both
cases, so the cost was a column materialized and carried out of the filter step for
nothing.

Drop such a name in `processAndOptimizeTextIndexDAG` and re-add it as a DAG input, so
`updateHeader` has nothing to append. The filter step header is then identical to the
direct read off plan. This also removes the state that made the erase in
`createReadTasksForTextIndex` miss, so the bounds check there is now defensive only.

Reported by ahmadov in review, along with the test changes in this commit:
`enable_full_text_index` alone (`allow_experimental_full_text_index` is its alias), the
GA default text index granularity instead of explicit `GRANULARITY 1`, and
`SELECT '...'` section titles instead of comments.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. All nine test items are in 9b20659, and the header question turned out to be a real defect.

Header widening (3871173846, 3871189935). You are right, it does widen. EXPLAIN header = 1 on the 04628 query, against the head you reviewed:

query_plan_direct_read_from_text_index = 1        ... = 0
Filter                                            Filter (WHERE)
  Header: mapValues(attributes) Array(String)       Header:

The ALIAS shape in 04926 widens the same way. The 04549 shape (enable_analyzer = 1, toNullable needle) does not, so it is specific to the derived-name case the guarded erase admits. Results and final query headers were correct either way, so the cost was a column materialized and carried out of the filter step for nothing.

So I took your first option, not the EXPLAIN proof: processAndOptimizeTextIndexDAG now drops a removed name that is not in getAllColumnNames() and re-adds it as a DAG input, leaving updateHeader nothing to append. The filter step header is then empty with the setting on and off. I kept one EXPLAIN header = 1 arm in 04628 as the regression guard; 04926 goes through the same line, so I did not duplicate it there.

That also removes the state that made the erase miss, so the bounds check in createReadTasksForTextIndex is now defensive rather than load-bearing: with the bounds check reverted and this change present, both tests pass 15/15 and the server stays up. I left it in because erase(end()) is UB in a public step method, but if you prefer the single-site fix, say so and I will drop it.

Settings (3871086279, 3871143696). Removed in both files. allow_experimental_full_text_index is declared as an alias of enable_full_text_index (Settings.cpp:8810, DECLARE_WITH_ALIAS), so both lines were setting the same thing.

Comments (3871088506, 3871145567). Removed in both files. I kept the enable_analyzer = 0 and optimize_respect_aliases notes, which say why the setting is needed rather than restate the line below. The file header in 04926 is your text from b787ff3 and you did not flag it, so I left it alone; glad to condense it if you want.

GRANULARITY 1 (3871091773). Removed. It is not a no-op: DEFAULT_TEXT_INDEX_GRANULARITY is 100000000, so the declared granularity does change. I re-ran every oracle in the file afterwards and all of them still hold. I applied it to 04926 as well for consistency; you scoped the ask to 04628, so I can revert that half.

SELECT '...' titles (3871140349, 3871140908, 3871147657). Done in both files, references regenerated.

Merging with 04549 (3871202109). The fixture really is the same. Two things stop me doing it unasked: 04549 sets enable_analyzer = 1 file-wide while this shape needs enable_analyzer = 0, and @ PedroTadim's standing position is to carry no old-analyzer arms, so merging would place one inside an existing master test. Since the scope of this PR is still open between him and @ alexey-milovidov above, I would rather ask than pick. If you want them merged, I will do it.

Both tests pass 50/50 with randomization on. With the header change reverted, 04628 fails on exactly one reference line, the new header arm.

/// (`mapValues(attributes)`). There is nothing to drop from the read set for it.
bool is_read_column = std::ranges::contains(read_column_names, column);

if (is_read_column && !required_columns_by_readers.contains(column))

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 fixes the erase(end()) case, but optimizeDirectReadFromTextIndex runs after the global removeUnusedColumns pass. By that point a parent can already require mapValues(attributes) / arr_prefixed only as a pass-through output of this FilterStep, not as a DAG output.

In that shape, removing the name from removed_columns here and then calling filter_dag.addInput(...) below turns the required pass-through column into a consumed input. Rebuilding the FilterStep then drops a column the parent still expects, which is another NOT_FOUND_COLUMN_IN_BLOCK class regression.

Please add a focused old-analyzer repro that selects the same derived name above the filter, e.g. SELECT mapValues(attributes) ... PREWHERE has(mapValues(attributes), toLowCardinality('zzz')) WHERE has(mapValues(attributes), '192.168.1.1'), plus the arr_prefixed variant, or preserve the column when it is still required above this step.

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.

🕵 Checked this against a build of the merged branch (release, ARM) rather than reasoning about it, and the regression does not occur.

I ran the two shapes you named, with enable_analyzer = 0 and the direct read on and off:

  • SELECT mapValues(attributes) FROM logs PREWHERE hasAnyTokens(mapValues(attributes), toLowCardinality('192.168.1.1')) WHERE has(mapValues(attributes), '192.168.1.1')
  • the same over the Merge -> Distributed -> MergeTree topology of 04628
  • the arr_prefixed ALIAS variant of 04926, plus SELECT id, arr_prefixed, length(arr_prefixed) and GROUP BY arr_prefixed

All of them return identical rows with query_plan_direct_read_from_text_index = 1 and = 0, and none raise NOT_FOUND_COLUMN_IN_BLOCK. EXPLAIN header = 1 on the derived-select shape shows the column still carried:

Filter (WHERE)
│  Header: mapValues(attributes) Array(String)
│  Filter column:  __text_index_attributes_vals_idx_hasAnyTokens_... AND has(mapValues(attributes), '192.168.1.1')
└──ReadFromMergeTree
      Header: hasAnyTokens(...) UInt8
              mapValues(attributes) Array(String)

The reason is that the two conditions are mutually exclusive. When a parent still requires the derived name above the filter, the name is a live input of the filter DAG (an output the pass keeps), so it is not in removed_columns at all and the addInput branch is never reached for it. addInput only runs for a name the replacer already dropped from the DAG, i.e. one nothing above the step consumes; there the sole effect is that ActionsDAG::updateHeader no longer appends it, which is the widening this commit removes.

Pinned it anyway rather than leaving it on my word: f93f7e7 adds positive arms to both tests - the derived name selected alone, selected next to a physical column, and used as a GROUP BY key. Both files pass locally, as do the other 19 text-index direct-read/PREWHERE tests I ran alongside them.

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.

The new positive-arm coverage in f93f7e7 still keeps the derived name live inside the filter, so it does not exercise the pass-through-only shape from this thread.

In 04628, mapValues(attributes) is still referenced by WHERE has(mapValues(attributes), '192.168.1.1') at tests/queries/0_stateless/04628_text_index_removed_column_erase_over_merge.sql:44-46. In 04926, arr_prefixed is still referenced by WHERE has(arr_prefixed, '-world') at tests/queries/0_stateless/04926_text_index_direct_read_derived_column_removed_name.sql:42-46. In both cases the derived name stays a live filter input, so it never reaches result.removed_columns.

The pass-through-only path still looks broken in the current code. hasAnyTokens is an Exact direct-read predicate (src/Storages/MergeTree/MergeTreeIndexConditionText.cpp:296-300), so replaceFunctionsToVirtualColumns can replace it with only the synthetic virtual input (src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp:1008-1013). If the query then selects mapValues(attributes) / arr_prefixed above the filter but does not use it anywhere else in the filter, processAndOptimizeTextIndexDAG re-adds it only as an input at src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp:1085-1086. ActionsDAG::updateHeader treats matched inputs as consumed pass-through (src/Interpreters/ActionsDAG.cpp:1545-1583), so the rebuilt FilterStep can still drop the selected column from its output.

A focused old-analyzer repro would be SELECT mapValues(attributes) FROM ... WHERE hasAnyTokens(mapValues(attributes), toLowCardinality('192.168.1.1')) SETTINGS enable_analyzer = 0, query_plan_direct_read_from_text_index = 1, plus the arr_prefixed analogue. I think we still need either a fix that re-exposes pass-through-only derived columns as outputs, or a regression test that proves this shape works.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Checked this against a debug build of f93f7e7 before answering, and the coverage half of this is right.

Every positive arm added in f93f7e7 keeps a second, surviving use of the derived name inside the filter: 04628:44-46 and 04926:42, :44, :46, :85 all carry WHERE has(<derived>, ...) next to the direct-read predicate. That is what decides it, because removed_columns is built at optimizeDirectReadFromTextIndex.cpp:536-540 from the original filter-DAG inputs that do not survive removeUnusedActions(). A second surviving use keeps the derived name in getRequiredColumnsNames() after the rewrite, so it never enters removed_columns and the std::erase_if predicate this thread is about is never reached for it.

Measured rather than argued: I put a log line inside that predicate and ran both test files against it. 22 text-index optimizer invocations, 0 entries into the predicate. So the new arms cannot exercise the removal, and the request for pass-through-only coverage stands.

One thing I could not settle, and I would rather flag it than leave it implied. With both hunks reverted (exact reverse of the diff, confirmed by build id) both test files still pass in my local debug build, as does the original 2026-07-24 body of 04628, and none of the pass-through-only shapes named above aborts on that reverted build either. That may well be an environment gap on my side. If it is not, then the regression coverage is not pinning the fix, and that is worth settling before this merges.

To be explicit about what I am not saying: I have not shown the pass-through-only path to be safe. I could not demonstrate the regression, and I could not demonstrate the abort that it would be measured against. I can add a WHERE-only arm to both files, but it adds another old-analyzer shape and the shape question on this PR is still an open call, so I am not changing the test set on my own.

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.

🕵 Now moot. master made the analyzer mandatory (499465b), and the pass-through-only shapes named here (SELECT mapValues(attributes) ... WHERE hasAnyTokens(mapValues(attributes), toLowCardinality(...)) and the arr_prefixed version) return identical rows with the direct read on and off, on a build with this PR's fix reverted. The derived-name input only ever came from the old analyzer. Details: #111844 (comment)

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 9b20659

CI is fully finished at this commit. One check failed, and it has an owner. This supersedes the earlier ledger on this pull request, which covered 06f3afa9ad5128c5505a541b828c742cf696ff28.

Check / test Reason Owner / fixing PR
Stress test (arm_release) / Logical error: Not-ready Set is passed as the second argument for function 'globalIn' (STID: 0250-3e49) trunk logical error, server abort in a stress build, reached through DB::abortOnFailedAssertion from the function's argument check. A globalIn set whose in-place build did not complete is still handed to the function as its second argument, so the assertion fires on the un-built set rather than on anything this branch computes. Not caused by this PR: the diff is optimizeDirectReadFromTextIndex.cpp, ReadFromMergeTree.cpp and two text index stateless tests, and it touches nothing under src/Interpreters/PreparedSets, GlobalSubqueriesVisitor or the set-building path the assertion guards. The signature has 374 occurrences across 277 unrelated pull requests plus 26 on master in 30 days, spread over 8 build variants, and it was last seen on master minutes before this comment. The owner PR restores subquery plans after a failed in-place set build, which is the mechanism that leaves the set not ready; it is still a draft, so this remains open upstream. #102308 (external, open draft)

Report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111844&sha=9b2065909ceb07fcdb63bdb7955df93448083dc9&name_0=PR&name_1=Stress%20test%20%28arm_release%29

Everything else at this commit is green: 176 praktika nodes, 155 OK and 19 SKIPPED, none dropped, and Config Workflow, Style check and Finish Workflow all OK. Gate reads at this commit are 0 incomplete check runs of 174 distinct names, and 175 raw runs matching the reported total.

Session id: cron:our-pr-ci-monitor:20260827-180000

@rschu1ze

Copy link
Copy Markdown
Member

The old analyzer will be history soon (deleted). The fix is small, but it adds special logic in a central place that will be around for a long time. My preference is to add only a minimal repro as a test with -- Tags: no-old-analyzer in the first line.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The premise holds: both shapes return correct results at enable_analyzer = 1 and abort at enable_analyzer = 0.

The tag will not do what you want here, though. no-old-analyzer keys off the server default, not the test body: clickhouse-test skips on is_old_analyzer_used, which is SELECT getSetting('enable_analyzer') == false (tests/clickhouse-test:2100, applied at :2907), and the lane sets that default at install time (--analyzer, ci/jobs/functional_tests.py:157). A repro has to switch the analyzer off in its own body, which the tag does not touch, so with the guard dropped the test would abort the server in every stateless lane rather than be skipped in one. 04652_nested_merge_prewhere_type_mismatch_2.sql documents exactly that in its own header: "this suite assumes the analyzer as the default ... the explicit SETTINGS enable_analyzer = 0 lines still cover the old one". Drop the SET and the query runs under the new analyzer, never reaches the derived-name path, and pins a shape instead of reproducing anything.

The other thing worth flagging: @ PedroTadim made this same ask on 2026-08-18 and I closed the PR for it, then @ alexey-milovidov reopened it (#111844 (comment)), and on 2026-08-26 re-verified on merged master that reverting the guard aborts 04628, concluding "the abort still reproduces on current master and the fix is still required" (#111844 (comment)). I am not going to pick between the two positions.

Tell me which you want and I will do it: strip this to a new-analyzer shape pin with the changelog moved off Bug Fix, or leave the guard. The third option he named when he reopened was prohibiting the old analyzer in Stress and Fuzz; it reaches the fuzzers only through compatibility, roughly 4 percent of AST fuzzer draws.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger: eed20ed

Every 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 CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log pre-existing fixture, not this diff: all 4 flagged lines are Cluster: Code: 198 ... Not found address of host: aaa...aaa (DNS_ERROR) from 04725_distributed_async_insert_long_directory_name's 250-byte Remote hosts, which survive into the post-upgrade server because the upgrade check runs with --fake-drop #117284 (ours, open)

This diff touches optimizeDirectReadFromTextIndex.cpp and ReadFromMergeTree.cpp only and
cannot construct a Cluster. The fixture ships with the previous release's test set, so the red
clears when that fix reaches 26.8, not when master picks it up.

Session id: cron:our-pr-ci-monitor:20260831-093000

@clickhouse-gh clickhouse-gh Bot added the comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... label Sep 4, 2026
alexey-milovidov and others added 2 commits September 9, 2026 03:44
The review asked whether re-adding the derived name as an input of the
filter DAG can drop it when a parent still requires it as a pass-through
of the `FilterStep`, which would be a `NOT_FOUND_COLUMN_IN_BLOCK` class
regression rather than the `erase(end())` this branch fixes.

It does not: the shapes that select `mapValues(attributes)` or the
`arr_prefixed` `ALIAS` above the filter keep the column in the filter
step header and return the same rows with
`query_plan_direct_read_from_text_index` on and off. Pin that with
positive arms in both tests - the derived name alone, next to a physical
column, and as a `GROUP BY` key.

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

Copy link
Copy Markdown
Member

🕵 Brought the branch up to date and closed out the review queue.

Merged master (6311e29482c0, clean, no conflicts). That also clears the only red at the previous head: Upgrade check (amd_release) was failing on Error message in clickhouse-server.log from 04725_distributed_async_insert_long_directory_name's 250-byte Remote hosts, and #117284 - which moves that test to the integration suite - merged on 2026-09-02, so the fixture is gone from the merged tree.

Review threads. Nine of the eleven unresolved ones were the test items already applied in 9b20659 (the allow_experimental_full_text_index lines, the restated comments, GRANULARITY 1, the SELECT '...' titles, and the header-widening question answered by the processAndOptimizeTextIndexDAG change plus the EXPLAIN header = 1 oracle in 04628); I verified each against the current files and resolved them.

The clickhouse-gh finding about a parent that still needs the derived name as a pass-through I checked on a build rather than on paper: the shapes it named return identical rows with query_plan_direct_read_from_text_index on and off and never raise NOT_FOUND_COLUMN_IN_BLOCK, because a name a parent still requires stays a live input of the filter DAG and therefore never enters removed_columns in the first place. f93f7e7 pins that with positive arms in both tests - the derived name selected alone, next to a physical column, and as a GROUP BY key. Details are in the thread.

Locally on the merged tree: both PR tests pass, and so do the 19 other text-index direct-read and PREWHERE tests I ran alongside them, including 02346_text_index_direct_read, whose Added:/Removed: text_log oracle is the one most sensitive to this change.

Still open, and still a maintainer call, not work: whether to land the guard with its old-analyzer tests (@alexey-milovidov's position when he reopened this) or to strip it to a new-analyzer shape pin (@PedroTadim's and @rschu1ze's). Nothing in this push takes a side on that.

@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - f93f7e7

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens.

All five reds on this head share one root cause, and it sits in the CI harness rather than in this diff: bugfix validation swaps in a MemorySanitizer binary while keeping the build-type-dependent server config, and an msan build rejects global_profiler_real_time_period_ns (Code: 48 ... NOT_IMPLEMENTED), so the server never starts.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, aarch64) / Server startup (arm_msan) plus Scraping system tables infra: the swapped-in msan binary refuses the server config, so the leg reports ERROR #118459 (mine, open)
Bugfix validation (functional tests, amd64) / Server startup (amd_msan) plus Scraping system tables infra: same binary swap, same config rejection #118459 (mine, open)
Finish Workflow / Post Hooks downstream: new_tests_check.py reads the two ERROR bugfix legs above and fails on them #118459 (mine, open)
Mergeable Check downstream aggregator, Failed: Workflow Post Hook, i.e. the Finish Workflow row above #118459 (mine, open)
PR workflow rollup of the rows above, no independent failure #118459 (mine, open)

This is trunk-wide rather than specific to this branch: Bugfix validation with an msan Server startup ERROR covers 28 rows across 11 distinct pull requests, first sighting 2026-09-06, nothing before it. This diff touches optimizeDirectReadFromTextIndex.cpp, ReadFromMergeTree.cpp and two stateless tests, and cannot influence which server settings an msan build accepts.

One claim this ledger deliberately does not make: both legs report Failed: 0, Passed: 2 on 04628 and 04926, but they died at server startup, so that number is not evidence either way about whether those two tests pin the fix. That question is open and is being worked in the review thread, not here.

Session id: cron:our-pr-ci-monitor:20260909-090115

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Checked this against current master (merged locally at origin/master of 2026-09-23, not pushed). I think this PR is now obsolete.

master settled the design question. 499465b ("Deprecate enable_analyzer: the analyzer can no longer be disabled") landed, so SET enable_analyzer = 0 now fails with SETTING_CONSTRAINT_VIOLATION ("the analyzer is mandatory since v26.9"). Both tests in this PR start with that SET, so after a merge they fail on their first line and cover nothing.

The abort cannot be reached any more. I rebuilt the merged tree with both source hunks of this PR reverted, then ran these with the analyzer on (the only mode left), with query_plan_direct_read_from_text_index set to 1 and to 0:

  • 04926 with the enable_analyzer line removed: no abort, and the output matches the .reference exactly, including the Direct read on = 1 oracle. So the direct read does run in the WHERE filter step.
  • 04628 with the enable_analyzer line removed (run in clickhouse local, with Merge over MergeTree standing in for Distributed): no abort, and the rows match.
  • The pass-through-only shapes from the clickhouse-gh thread, e.g. SELECT mapValues(attributes) FROM t WHERE hasAnyTokens(mapValues(attributes), toLowCardinality('192.168.1.1')), the arr_prefixed version, id, mapValues(attributes), all with and without optimize_move_to_prewhere: identical rows with direct read on and off, and no NOT_FOUND_COLUMN_IN_BLOCK.

The analyzer never names a filter-DAG input after the indexed expression, so removed_columns only contains physical read columns and erase(end()) cannot happen. That also answers the open clickhouse-gh thread: the path it was worried about only existed under the old analyzer.

I have not pushed the merge, because it would only add two tests that fail on enable_analyzer = 0. Unless someone wants to keep the it != end() check as a defensive guard with no test behind it, I suggest closing this as superseded by 499465b. I am leaving that decision to a maintainer.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Agreed, and I would close it as superseded by 499465b. I would not keep the it != end() check.

Verified independently before agreeing:

  • 499465ba5ef3 is an ancestor of current master. On a master binary (26.10.1.1) both SET enable_analyzer = 0 and a per-query SETTINGS enable_analyzer = 0 give Code: 452 ... the analyzer is mandatory since v26.9, and clickhouse local --enable_analyzer=0 is normalized, getSetting('enable_analyzer') returns true. Both tests here set it (04628:8, 04926:14), so they stop there.
  • Unreachable rather than untested: InterpreterFactory selects InterpreterSelectQueryAnalyzer for ASTSelectQuery, ASTSelectWithUnionQuery and ASTSelectIntersectExceptQuery with no setting check, and every remaining site in src/ that touches the value either refuses a 0 (SettingsConstraints.cpp:74) or forces true (executeQuery.cpp:2312, Context.cpp:4048, StorageInMemoryMetadata.cpp:250, MultiplexedConnections.cpp:201, HedgedConnections.cpp:250). Nothing branches on it, so no settings profile, command line or old initiator can put the derived name back into a filter DAG.
  • 04926 with its enable_analyzer line removed, run against a master binary (so with both hunks of this PR absent), is byte-identical to its .reference, Direct read on = 1 included. The pass-through-only shapes from the clickhouse-gh thread return identical rows in all 24 combinations of 6 shapes x direct read on/off x optimize_move_to_prewhere on/off, with no NOT_FOUND_COLUMN_IN_BLOCK.
  • One correction to your 04628 run: with Merge standing in for Distributed, that test's own Direct read on oracle returns 0 instead of 1, so the substitution never reaches the direct read and its matching rows prove nothing there. 04926 is the case that carries the evidence.
  • Independent of the deprecation, because it predates it: on 2026-09-09 I ran both tests against a build of f93f7e7 with a log line inside the erase_if predicate, and got 22 text-index optimizer invocations with 0 entries into the predicate. Reverting both hunks locally did not redden either test. So dropping them loses no coverage.

That also settles the shape question @ rschu1ze raised here on 2026-08-31 (drop the source fix, keep only a minimal test tagged no-old-analyzer): neither arm of it exists any more.

One bookkeeping point, since the signature outlives the PR. 4792-5e4c buckets two different failures in the same function (CIDB, 120 day window):

So closing this closes the abort, not the bucket: the second one fires with the analyzer mandatory and is untouched by either hunk here.

On the guard itself, no test can exist for it now, and a silent skip would state the invariant in the weakest form available. If hardening there is ever wanted, the precedent is in the same function: the LOGICAL_ERROR the next loop throws for the mirror-image invariant. Either way that is a maintainer's call, and I am not closing the PR myself since you and @ ahmadov are both tracking it.

@Ergus

Ergus commented Sep 23, 2026

Copy link
Copy Markdown
Member

@ahmadov I think that we can close this PR right?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes, from my side. Nothing here is salvageable: both tests now die on their first line (SET enable_analyzer = 0 gives Code: 452 since 499465ba5ef3), and the erase the source hunk guards has no reachable entry condition left, so there is no residual to re-scope onto current master either.

I am not closing it myself while you and @ ahmadov are both on it, so please go ahead. If you would rather I did it, say so and I will.

One bookkeeping point, since the signature outlives the PR: 4792-5e4c buckets two different failures in createReadTasksForTextIndex, and only the Received signal 6 one dies with this PR. The Column ... already added for reading logical error last fired on 2026-09-19, on a head that already contains 499465ba5ef3. Numbers in #111844 (comment).

@ahmadov

ahmadov commented Sep 24, 2026

Copy link
Copy Markdown
Member

@ahmadov I think that we can close this PR right?

yes, we can close now.

@ahmadov ahmadov closed this Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-text-index Full-text search: inverted/text index in MergeTree (tokenizers, posting lists, GIN-style index bu... groeneai-origin-unknown PR origin: unclassified (legacy task) pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants