[improvement](parser) Factor common EXPLAIN and CTE prefixes - #67427
Merged
englefly merged 1 commit intoSep 2, 2026
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
11 tasks
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: Query and DML dispatch repeatedly predicted optional EXPLAIN and CTE prefixes across queryOrDmlStatement, dmlStatement, and query. Consume the common prefix once, dispatch the remaining query or DML body, and pass the prefix contexts to the FE plan builder while preserving non-explainable statements and nested source CTEs. In the original parser-only JMH validation, CTE INSERT improves from 48.439 to 42.907 us/op (-11.4%) and EXPLAIN CTE INSERT improves from 48.032 to 42.356 us/op (-11.8%); CTE SELECT remains flat at +0.5%.
### Release note
None
### Check List (For Author)
- Test: Unit Test and manual performance/semantic validation
- Maven parser and benchmark package: 107 tests passed
- FE targeted parser tests: 111 tests passed
- Tracked SQL corpus: 4,610 files, Legacy and ANSI modes, with byte-identical parse/error signatures
- Reused the original P1 JMH parser-only baseline and candidate comparison; the replayed functional patch has the same stable patch ID
- Behavior changed: No
- Does this need documentation: No
morrySnow
force-pushed
the
codex/antlr4-parser-optimization-todo
branch
from
September 2, 2026 08:39
5e0eadb to
3745781
Compare
Contributor
Author
|
run buildall |
morrySnow
marked this pull request as ready for review
September 2, 2026 08:41
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 2, 2026 08:41
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Sep 2, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#67427 Problem Summary: The grammar allowed both querySpecification and its outer query to consume ORDER BY and LIMIT clauses, which introduced full-context ambiguity. Assign each clause group to exactly one owner according to ANSI mode and query level, preserve baseline first-error positions, and adapt the FE visitor to the new labeled contexts. LL_EXACT fallback and ambiguity for the target decisions drop to zero. Ordered SELECT end-to-end latency improves by 7.2% in legacy mode and 6.2% in ANSI mode; parser-only latency improves by 6.5% and 2.8% respectively. The plain SELECT control has no regression above the 3% threshold. ### Release note None ### Check List (For Author) - Test: Unit Test and manual performance/semantic validation - Maven parser and benchmark package: 238 tests passed - FE QueryOrganizationPlanTest and NereidsParserTest: 90 tests passed - Tracked SQL corpus: 4,610 files with identical parse/error signatures in both modes - Reused the original LL_EXACT profile, invalid-SQL matrix, and JMH comparison; the P2 functional patch has the same stable patch ID - Behavior changed: No - Does this need documentation: No
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
TPC-H: Total hot run time: 16717 ms |
Contributor
TPC-DS: Total hot run time: 81903 ms |
Contributor
ClickBench: Total hot run time: 14.7 s |
Contributor
FE Regression Coverage ReportIncrement line coverage |
Contributor
|
PR approved by anyone and no changes requested. |
Contributor
|
PR approved by at least one committer and no changes requested. |
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Sep 2, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#67427 Problem Summary: The grammar allowed both querySpecification and its outer query to consume ORDER BY and LIMIT clauses, which introduced full-context ambiguity. Assign each clause group to exactly one owner according to ANSI mode and query level, preserve baseline first-error positions, and adapt the FE visitor to the new labeled contexts. LL_EXACT fallback and ambiguity for the target decisions drop to zero. Ordered SELECT end-to-end latency improves by 7.2% in legacy mode and 6.2% in ANSI mode; parser-only latency improves by 6.5% and 2.8% respectively. The plain SELECT control has no regression above the 3% threshold. ### Release note None ### Check List (For Author) - Test: Unit Test and manual performance/semantic validation - Maven parser and benchmark package: 238 tests passed - FE QueryOrganizationPlanTest and NereidsParserTest: 90 tests passed - Tracked SQL corpus: 4,610 files with identical parse/error signatures in both modes - Reused the original LL_EXACT profile, invalid-SQL matrix, and JMH comparison; the P2 functional patch has the same stable patch ID - Behavior changed: No - Does this need documentation: No
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Sep 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#67427 Problem Summary: The grammar allowed both querySpecification and its outer query to consume ORDER BY and LIMIT clauses, which introduced full-context ambiguity. Assign each clause group to exactly one owner according to ANSI mode and query level, preserve baseline first-error positions, and adapt the FE visitor to the new labeled contexts. LL_EXACT fallback and ambiguity for the target decisions drop to zero. Ordered SELECT end-to-end latency improves by 7.2% in legacy mode and 6.2% in ANSI mode; parser-only latency improves by 6.5% and 2.8% respectively. The plain SELECT control has no regression above the 3% threshold. ### Release note None ### Check List (For Author) - Test: Unit Test and manual performance/semantic validation - Maven parser and benchmark package: 238 tests passed - FE QueryOrganizationPlanTest and NereidsParserTest: 90 tests passed - Tracked SQL corpus: 4,610 files with identical parse/error signatures in both modes - Reused the original LL_EXACT profile, invalid-SQL matrix, and JMH comparison; the P2 functional patch has the same stable patch ID - Behavior changed: No - Does this need documentation: No
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Sep 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#67427 Problem Summary: The grammar allowed both querySpecification and its outer query to consume ORDER BY and LIMIT clauses, which introduced full-context ambiguity. Assign each clause group to exactly one owner according to ANSI mode and query level, preserve baseline first-error positions, and adapt the FE visitor to the new labeled contexts. LL_EXACT fallback and ambiguity for the target decisions drop to zero. Ordered SELECT end-to-end latency improves by 7.2% in legacy mode and 6.2% in ANSI mode; parser-only latency improves by 6.5% and 2.8% respectively. The plain SELECT control has no regression above the 3% threshold. ### Release note None ### Check List (For Author) - Test: Unit Test and manual performance/semantic validation - Maven parser and benchmark package: 238 tests passed - FE QueryOrganizationPlanTest and NereidsParserTest: 90 tests passed - Tracked SQL corpus: 4,610 files with identical parse/error signatures in both modes - Reused the original LL_EXACT profile, invalid-SQL matrix, and JMH comparison; the P2 functional patch has the same stable patch ID - Behavior changed: No - Does this need documentation: No
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?
Issue Number: None
Related PR: None
Problem Summary: The SQL grammar repeatedly predicts the optional
EXPLAINand CTE prefixes inqueryOrDmlStatement,dmlStatement, andquery, causing long adaptive lookahead for CTE DML. This change consumes the common prefix once, dispatches the remaining query or DML body, and passes the prefix contexts to the FE plan builder. It preserves non-explainable LOAD/EXPORT/REPLAY/COPY/TRUNCATE branches, nested source CTEs, error positions, and FE command semantics.This is now an independent PR based directly on
master. The seven functional, test, and benchmark files have the same stable patch ID (db03fbcb3a0ca4cfee8a1422bc78e7f753e6ae51) as the original P1 commit. Only the TODO status update that depended on the earlier roadmap PR was omitted.Benchmark
The benchmark results below are reused from the original P1 validation because the replayed functional patch is identical. The benchmark measures the public parser facade and a pre-tokenized parser-only path; lower latency is better.
-prof gcd7f44fcfedd; benchmark jar SHA-2562e33becac22a27d8c40eec7c821c506cbc9bcedfda277725fa8fee40c6d351165e0eadb13e9; benchmark jar SHA-256743c133321dbb1a2283ea1836e5a9568a14ecc2ae350b2fc239d354d7988b423fe/fe-sql-parser-benchmark/src/main/java/org/apache/doris/sqlparser/benchmark/QueryOrDmlCommonPrefixBenchmark.javaLonger parser-only target run
Public-facade control cases from the standard run
The previous grammar performs about 56 tokens of top-level lookahead for a long CTE and then about 62 more tokens in the DML decision. Factoring the prefix removes the repeated prediction, which accounts for the CTE INSERT gains. CTE SELECT remains flat within overlapping confidence intervals, and target allocation changes remain below 1%. The standard end-to-end long-CTE forks were noisy, so this PR makes no precise end-to-end long-CTE or whole-FE latency claim.
Semantic differential
masterat049410596f4d; parser jar SHA-256923ed2a22142ee9b5dcfefbba5766b9696a653a4218e8208e42a61270e9d986f3e43f2e025f4152d109a692ba68985c512a155fc2f21345a550911b1ef29af8f*.sqlfiles; manifest SHA-256567e209d57e5eaf6546ff03bf887437b8d647ed5f7ecb85bc657b987dd04be10897b6167aa718d5d14887c1752d4bd849cb1c55f7926b474e5dd2f9562a26fbdRelease note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)