Repository navigation
[fix](variant) Keep integer element_at indexes out of variant sub-column paths - #67955
Conversation
…umn paths VariantSubPathPruning turned element_at(element_at(v, 'items'), 1) into the storage sub-column items.1, so the scan looked up a missing object key and returned NULL for every integer index on a stored VARIANT column (DORIS-28435). An integer index selects an array element, so the sub-path now stops at the last object key and the index is applied to the extracted value at runtime. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
…T arrays Filters with an integer index read the object-key prefix and apply the index at runtime, like projections. Add FE UT and regression cases for a pushed-down comparison, IS NULL, a string key after the index, a filter that also reads the object-key sub-column items.1, a TopN, and MATCH on such a path, which is rejected because the path is not a storage sub-column. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
run buildall |
FE UT Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
TPC-H: Total hot run time: 16980 ms |
TPC-DS: Total hot run time: 82764 ms |
ClickBench: Total hot run time: 14.74 s |
…riantPruningLogicTest testVariantNumericIndexSubPath still expected the storage sub-column arr.0.x for v['arr'][0]['x']. With integer indexes kept out of sub-column paths the scan reads arr, while the access path keeps the whole expression. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
run buildall |
|
/review |
There was a problem hiding this comment.
Review result: request changes
One P2 performance issue remains: when an integer-index expression crosses a project alias (including reachable UNION ALL and materialized/multi-use CTE producer shapes), the helper for an upper string-key access is built from the unreplaced expression and keeps the full root VARIANT column live. The inline comment has the concrete plan tree and fix direction.
Critical checkpoint conclusions
- Goal and proof: The string-only storage-path guard correctly stops direct paths before integer selectors, and direct projection/filter trees retain the integer and later keys for runtime evaluation. The changed unit/regression cases cover positive, negative, zero, out-of-range, null/missing/non-array values, numeric-looking string keys, post-index keys, filters, TopN, and MATCH rejection. The alias-boundary scan-slot behavior is not covered.
- Scope and clarity: The production change is small and focused; the test additions are relevant. MAIN-1 is the only remaining defect.
- Concurrency and lifecycle: The rewrite uses per-invocation context and adds no shared mutable state, threads, locks, static initialization dependencies, ownership, or special lifecycle behavior.
- Configuration and compatibility: No configuration, persisted state, storage format, symbol, or FE-BE protocol field changes are introduced. Existing VARIANT integer runtime evaluation and existing descriptor fields are reused, so no rolling-upgrade compatibility issue was found.
- Parallel paths and conditions: Direct filter, join, sort, TopN, partition-TopN, generate, window, and aggregate replacers recursively preserve the safe prefix plus runtime suffix. Project helpers propagated through aliases/CTEs/UNION ALL are the uncovered parallel path called out inline. The
StringLikeLiteralcondition matches object-key semantics; all other selector shapes conservatively stop storage-path extraction. - Tests and expected results: The new expected output is internally consistent and deterministic, and the error case uses the required test form. No result-file discrepancy was found. Per the review-runner contract I did not build or run tests; the author's reported FE unit, regression, and manual results were assessed as claims rather than independent execution.
- Observability: No new distributed or operational path needs additional logs or metrics.
- Transactions, persistence, and writes: Not applicable; this is a query-planner/read-path rewrite and test-only data setup.
- FE-BE propagation: No new variable is added.
column_paths=['items']remains separate from logical all/predicate access paths, and the OLAP reader selects theitemspayload fromcolumn_paths; numeric access-path segments do not recreate the original object-key bug. - Performance: Direct expressions gain the intended sub-column read, but MAIN-1 can force full-document reads across project/CTE/UNION boundaries and should be fixed before merge.
- Other risks: Selector coercion, MATCH behavior, access-path transport, row-ID fetch, and expected outputs were rechecked; no additional distinct issue was substantiated.
Review completion
No additional user focus was provided. The review converged after two full rounds: round two's normal implementation review, normal test review, and separate risk-focused review all returned NO_NEW_VALUABLE_FINDINGS. Every other candidate was dismissed with code evidence or deduplicated into the single inline comment.
| } else if (key instanceof Literal && key.getDataType().isIntegerLikeType()) { | ||
| subPath.add(((Literal) key).getStringValue()); | ||
| } else { | ||
| if (!(key instanceof StringLikeLiteral)) { |
There was a problem hiding this comment.
[P2] Preserve the rewritten prefix across project aliases
A project boundary can undo the pruning introduced here. A reduced producer shape, reachable through UNION ALL or a materialized/multi-use CTE, is:
Project(x['k'])
UNION ALL
Project(v['items'][1] AS x)
Scan(v)
This return-null path makes the lower project call pushDownToProject(context, projection). Although its ordinary x projection is rewritten to element_at(items_slot, 1), pushDownToProject reads the original projection.child(0) and builds the requested x['k'] helper as v['items'][1]['k']. The helper therefore keeps the full root v slot live, so large documents are read in full even though the scan also exposes items_slot. Later column/operative-slot passes retain that explicit root input. Please build the helper from the recursively replaced child, or replace the constructed expression through elementAtToSlotMap, and add a UNION/CTE alias-boundary plan assertion that the root VARIANT scan slot is absent.
FE Regression Coverage ReportIncrement line coverage |
TPC-H: Total hot run time: 16701 ms |
TPC-DS: Total hot run time: 82002 ms |
ClickBench: Total hot run time: 14.73 s |
What problem does this PR solve?
Issue Number: None
Related PR: #60847
Problem Summary:
On a stored VARIANT column,
element_atwith an integer index returns NULL when it is applied to an array that was itself extracted withelement_at, for exampleelement_at(element_at(v, 'items'), 1)orv['items'][1]on a row holding{"items": [2, 3, 4]}. The same expressions on a constant VARIANT value return the element.VariantSubPathPruningpushes anelement_atchain on a VARIANT slot down to the scan as a storage sub-column path. #60847 made it accept integer literals as path segments too, so the query above reads the sub-columnitems.1(subColPath=[items, 1]inEXPLAIN VERBOSE). Storage sub-paths address object keys only, so the scan looks for an object key1underitems, finds none, and returns NULL instead of indexing the array. WithSET disable_nereids_rules = 'VARIANT_SUB_PATH_PRUNING'the same query returns the right value.This PR stops the storage sub-path at the last string key. An integer index is no longer added to the path, so the scan reads
items(subColPath=[items]) andelement_atapplies the index to the extracted value at runtime, with the same 1-based and negative-index semantics as for a constant value. String keys are still pushed down. Filters go through the same rewrite, so a predicate such asCAST(v['items'][1] AS INT) = 2also readsitemsand evaluates the index in the scan.Release note
Fix
element_atwith an integer index (for exampleelement_at(v['items'], 1)) returning NULL for an array inside a VARIANT column.Check List (For Author)
Test
Regression test
Unit Test
Manual test (add detailed scripts or steps below)
No need to test or manual test. Explain why:
FE UT:
PruneNestedColumnTest(64 tests, including the newtestVariantIntegerIndexStopsSubColumnPathfor projections andtestVariantIntegerIndexPredicateStopsSubColumnPathfor filters, a string key after the index, and an object-key sub-column spelled like the index),VariantPruningLogicTest(14),ExprToSqlTest(117),DescriptorToThriftConverterTest(22) andLogicalOlapScanTest(6) pass.VariantPruningLogicTest.testVariantNumericIndexSubPathnow expects the sub-columnarrinstead ofarr.0.xforv['arr'][0]['x']; its access path is unchanged../run-regression-test.sh --run -d variant_p0 -s regression_test_variant_element_at: passed. The cases cover indexes 1, -1, 0 and out of range, a nested array, an array of objects, a JSON null element, an integer index on an object, a missing path, a string key that looks like a number and constant VARIANT values, plus filters: a pushed-down comparison,IS NULL, a string key after the index, a filter that also reads the object-key sub-columnitems.1, a TopN, and MATCH on a path with an integer index. The expected output was reviewed row by row../run-regression-test.sh --run -d nereids_rules_p0 -s topn_lazy_nested_column_pruning: passed; it applies an integer index to a typed VARIANT array path.Manual, on a single-node cluster built from master:
element_at(element_at(v, 'items'), 1)returned NULL withsubColPath=[items, 1]before the change; after it, indexes 1, -1 and['items'][2]return 2, 4 and 3 withsubColPath=[items]. Filters with integer indexes (comparison,IN,IS [NOT] NULL, a string key after the index, a mix with object-key paths, index 0) were run as a plain filter, with another index projected, under a TopN, asCOUNT(*)and inside anINsubquery, on six tables: one segment, one rowset per row,itemsin the sparse column (variant_max_subcolumns_count= 1), an inverted index on the column, and MOW and MOR unique keys after an update. All 390 results matched the same queries withVARIANT_SUB_PATH_PRUNINGdisabled and onparse_to_variant()of the source JSON text. Point queries on a MOW table with a row store and joins on an integer-index expression returned the expected rows as well.Behavior changed:
On a stored VARIANT column an integer index no longer reads the object key with the same digits:
element_at(v['items'], 1)on{"items": {"1": "x"}}returns NULL, as it does for a VARIANT value computed at runtime, andMATCHon a path with an integer index (v['items'][2] MATCH_ANY 's') is rejected with "Only support match left operand is SlotRef", because that path is no longer a storage sub-column. A string key (v['items']['1']) still reads the object key.Does this need documentation?
Check List (For Reviewer who merge this PR)
🤖 Generated with Claude Code