[fix](subquery) Preserve generate child outputs for subqueries - #67807
Merged
morrySnow merged 1 commit intoSep 11, 2026
Conversation
### What problem does this PR solve? Problem Summary: When a table-generating function contains a scalar subquery, NormalizeGenerate inserts a project that materializes the subquery. That project previously exposed only the new subquery aliases and discarded every output from the original child. As a result, an outer projection could no longer read base-table columns, and a generator expression that also referenced a base-table column had a missing input slot. The normalization project now preserves the original child output before appending the subquery aliases. Existing slots keep their identities and order, while the generator can still consume the materialized subquery slots. Unit and regression coverage exercise both outer-output and generator-input dependencies. ### Release note Fix LATERAL VIEW analysis failures when a generating function combines scalar subqueries with base-table columns. ### Check List (For Author) - Test: Unit Test and Regression Test - Behavior changed: Yes. Valid LATERAL VIEW queries retain the base-table slots required above and inside the generator. - Does this need documentation: No
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 10, 2026 11:20
Contributor
Author
|
run buildall |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
TPC-H: Total hot run time: 16854 ms |
Contributor
TPC-DS: Total hot run time: 83227 ms |
Contributor
ClickBench: Total hot run time: 14.89 s |
starocean999
approved these changes
Sep 11, 2026
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.
What problem does this PR solve?
Problem Summary:
When a table-generating function contains a scalar subquery,
NormalizeGenerateinserts aLogicalProjectto materialize the subquery result. That project exposed only the new scalar-subquery aliases and discarded every output from the original child. Consequently, a projection above theLATERAL VIEWcould no longer resolve base-table columns. A generating expression that referenced both a base-table column and the scalar subquery also lost its input slot.For example, both of these valid forms failed analysis:
What is changed and how does it work?
The materialization project now retains the original child outputs, in their existing order, before appending aliases for scalar-subquery results. This preserves the child slots and their expression IDs for both the generator and projections above it, while later projection pruning can still remove unused internal slots.
Focused unit tests cover both dependencies: a base-table column consumed above the generate node, and a base-table column consumed inside the generating expression. A result regression covers the same two query shapes end to end.
Release note
Fix analysis failures for
LATERAL VIEWgenerating functions that combine scalar subqueries with base-table columns.Check List (For Author)
NormalizeGenerateTest(2 tests)nereids_p0/test_generate_subquery_output