Repository navigation
Conversation
|
Workflow [PR], commit [b909b10] AI ReviewSummaryThis draft extends text-index rewrites past a Findings❌ Blockers
Final VerdictChanges requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+19.18 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units31 translation units recompiled, 313 s compile time in total, 31 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
87ffe4a to
a842f13
Compare
| if (step.hasOutputHeader()) | ||
| { | ||
| for (const auto & column : *step.getOutputHeader()) | ||
| if (auto it = tracked.find(column.name); it != tracked.end()) |
There was a problem hiding this comment.
getOutputHeader() is too coarse to mean "pass-through". ActionsDAG::updateHeader() removes an input column when the DAG produces a new output with the same name, so an ExpressionStep like SELECT lower(s) AS s ... still has s in the output header even though the original scan column is gone. This loop re-adds s to tracked_columns, and a later post-JOIN hasToken(s, ...) is rewritten with the base table's text-index metadata against the recomputed value. The PR description explicitly says recomputed values such as lower(s) AS s must keep the default tokenizer, so this needs to follow only true pass-through inputs (for example via matchInputPositionsToHeader(...).passthrough), not every matching output-header name.
| bool hasIndexForColumn(const String & column_name) const { return header.has(column_name) || column_name == normalized_index_column_name; } | ||
| bool hasIndexForColumn(const String & column_name) const | ||
| { | ||
| String unqualified = stripJoinTableQualifier(column_name); |
There was a problem hiding this comment.
hasIndexForColumn now fixes only the bare-column case. traverseFunctionNode still probes strings like lower(__table1.text), mapKeys(__table1.m) / mapValues(__table1.m), and JSON subcolumns still go through tryMatchNodeToJSONIndex with names like __table1.json.path, so these existing text-index carriers are still unmatched above a JOIN. The new rewrite therefore still falls back to the default tokenizer for expression, Map, and JSON text indexes. The qualifier normalization has to remove analyzer table prefixes inside the full serialized carrier (or in each Map / JSON helper path), not only when the whole string starts with __tableN..
|
|
||
| if (!filter_step && !expression_step) | ||
| { | ||
| if (typeid_cast<const JoinStep *>(step) || typeid_cast<const JoinStepLogical *>(step)) |
There was a problem hiding this comment.
This pass runs in optimizeTreeSecondPass(), after convertLogicalJoinToPhysical() has already turned many joins into physical steps. Lookup joins become FilledJoinStep, and inequality joins become IEJoinStep, but this branch only recognizes JoinStep / JoinStepLogical. For those join implementations the walk still stops at the join, so the original "predicate stranded above the JOIN" wrong-result bug survives unchanged. Please treat the other physical join steps as join boundaries too instead of enumerating only these two types.
| if (!need_transform_function && !direct_read_from_text_index) | ||
| return replacement; | ||
|
|
||
| if (tracked_columns && !isHaystackTracked(function_node, *tracked_columns)) |
There was a problem hiding this comment.
tracked_columns is only used as a membership set here, but trackColumnsThroughStep() preserves more information than that: after a pre-JOIN rename it holds x -> s. A query like
SELECT *
FROM (SELECT s AS x, gid FROM t) AS a
INNER JOIN b ON a.gid = b.gid
WHERE hasAnyTokens(x, ['alpha beta']) OR b.cat = 'x'still reaches selectConditions() with the haystack serialized as x, so MergeTreeIndexConditionText probes x against the index header and finds nothing. The post-JOIN predicate then falls back to the default tokenizer, which is the same wrong-result hole this PR is trying to close. Please feed the tracked scan-side name back into the matcher instead of using tracked_columns only as a boolean guard.
| const String filter_column_name = filter_step ? filter_step->getFilterColumnName() : String{}; | ||
|
|
||
| TextIndexDAGReplacer replacer( | ||
| step_dag, text_index_infos, /*direct_read_from_text_index=*/ false, /*is_filter_dag=*/ filter_step != nullptr, |
There was a problem hiding this comment.
This new past-JOIN path still does not reproduce text-index preprocessor semantics when the index was discovered only via collectTextIndexInjectInfos() (for example SETTINGS use_skip_indexes = 0, or when the whole predicate stays above the JOIN). processTextIndexFunction() only wraps the haystack when condition.info->index != nullptr, so for TYPE text(tokenizer = splitByNonAlpha, preprocessor = lower(s)) a stranded predicate like hasToken(s, 'hello') OR b.category = 'x' is still executed as raw hasToken(s, 'hello') here and stays wrong for rows containing HELLO. The new comment says this helper applies the same rewrite as below the JOIN, but today it only guarantees tokenizer/postprocessor. It needs a preprocessor-capable inject-only path as well.
|
This PR AS IS fixes the issue BUT with the limitation of not working with parallel replicas. I can solve it with an analyzer pass instead , because I like more that solution because will be simpler and even smaller than this PR. A 3-argument call is invisible to index analysis, so injecting universally trades wrong results for full scans on every text-index query. This is exactly what #115348 will solve. |
| const String filter_column_name = filter_step ? filter_step->getFilterColumnName() : String{}; | ||
|
|
||
| TextIndexDAGReplacer replacer( | ||
| step_dag, text_index_infos, /*direct_read_from_text_index=*/ false, /*is_filter_dag=*/ filter_step != nullptr, |
There was a problem hiding this comment.
collectTextIndexInjectInfos() makes the post-JOIN SELECT-list case reachable, but applyTextIndexInjectPastJoin() still constructs the replacer with is_filter_dag = false for every ExpressionStep. processTextIndexFunction() gates apply_preprocessor on is_filter_dag, so a query like SELECT hasToken(p.val, 'hello') above a JOIN on TYPE text(tokenizer = splitByNonAlpha, preprocessor = lower(val)) is still left as the raw two-argument call and returns 0 for HELLO. Please drive the preprocessor injection for post-JOIN ExpressionSteps too, and add a focused SELECT-list regression for a preprocessed index.
Closes: #115999
Related: #108808
Related: #113154
Related: #116197
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
hasAnyTokens,hasAllTokens,hasPhraseandhasTokensilently returning wrong results on a column with atextindex when the predicate cannot be evaluated before aJOIN.These functions are rewritten during planning to match what the index stores: its tokenizer,
preprocessorandpostprocessor. #113154 made that rewrite reach steps above the scan, but it stops at aJOIN. A predicateOR-ed with a condition on the other table is evaluated after the join and was left unrewritten, falling back tosplitByNonAlpha. Withtokenizer = arraythe index keepsalpha beta gammaas one token whilesplitByNonAlphasplits it into three, so matching rows disappeared:returned row 2 where rows 1 and 2 match.
The walk now crosses a JOIN and applies the same rewrite beyond it. This also fixes a call in the SELECT list above a JOIN, which returned 0.
Past a join the rewrite is restricted to columns still known to come from the scanned table: the other side can have a column of the same name that the index does not describe. Such a column keeps the default tokenizer, as does a recomputed value (
lower(s) AS s,arrayJoin, aggregation). Reading the index directly stays below the join, being a per-granule answer.Two supporting changes: a column is followed through a step's output header as well as its DAG, since a step can carry it as a pass-through the DAG never mentions; and matching a column to an index ignores the
__tableN. prefix added above a join, which is sound only with the restriction above.Workflow [PR]
Sync PR [sync-upstream/pr/116339]