[opt](nereids) Reuse identical uncorrelated scalar subqueries referencing the same CTE - #66781
Open
LLLLLL302311 wants to merge 1 commit into
Open
[opt](nereids) Reuse identical uncorrelated scalar subqueries referencing the same CTE#66781LLLLLL302311 wants to merge 1 commit into
LLLLLL302311 wants to merge 1 commit into
Conversation
…cing the same CTE
commit 56598d9a7a81157c12b3226702d114d6cf70a694
Author: lijinghan.1029 <lijinghan.1029@jd.com>
Date: Fri Aug 14 17:54:54 2026 +0800
(nereids) Reuse identical uncorrelated scalar subqueries referencing the same CTE
When a query contains many structurally-identical uncorrelated scalar
subqueries that reference the same CTE (e.g. (SELECT dt FROM deal_dt)
repeated hundreds of times), SubqueryToApply generated one LogicalApply
per occurrence, blowing up the Nereids optimization search space and
causing the planner to time out.
This change groups such reusable scalar subqueries within the same
LogicalFilter/LogicalProject by (cteId, cte name, projection, data type,
nullable) and builds a single Apply for the representative, letting the
other occurrences reuse its output. Correlated subqueries, subqueries
needing type coercion, DISTINCT/multi-column projections and non-CTE
subqueries are excluded to preserve semantics.
LLLLLL302311
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
August 14, 2026 10:46
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
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 query contains many structurally-identical uncorrelated scalar subqueries
that reference the same CTE (e.g.
(SELECT dt FROM deal_dt)repeated hundreds oftimes),
SubqueryToApplygenerated oneLogicalApplyper occurrence. This blew upthe Nereids optimization search space and caused the planner to time out
(
Nereids cost too much time), while these queries planned fine on the legacy optimizer.This PR groups reusable scalar subqueries within the same
LogicalFilter/LogicalProjectby
(cteId, cte name, projection, data type, nullable)and builds a singleApplyfor arepresentative, letting the other occurrences reuse its output. Correlated subqueries,
subqueries needing type coercion,
DISTINCT/multi-column projections and non-CTEsubqueries are excluded to preserve semantics.
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?