GeezerVison is showing github.com — [SQL] Reduce SQL compiler stack usage by mihaibudiu · Pull Request #7938 · feldera/feldera
Conversation
mihaibudiu
commented
Nov 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Linked Issue
Fixes #7931
There are two commits:
- increase stack size for the SQL compiler from 2MB to 512MB. This seems much, but the compiler is single-threaded.
- convert long chains of UNION/INTERSECT into balanced trees (only if this change does not modify the semantics of the query) after parsing
Checklist
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
What I ran: ./build.sh, then mvn test -Dtest=BalanceSetOperationsTests,NegativeParserTests: all pass. I also ran the jar on the issue's 3000-branch repro and on a chain of 3000 string literals, with and without -Xss512m. I did not run cargo check on pipeline-manager; that change is one argument.
| QA case (not covered by the PR's tests) |
Result |
Issue repro, 3000-branch UNION ALL, default test stack |
✅ compiles (~14 s) |
300-branch INTERSECT / INTERSECT ALL |
✅ correct output |
UNION chain mixing NOT NULL and nullable columns |
✅ |
Long chain with mixed types inside an IN (…) subquery (fallback path) |
✅ |
Long chain inside a CTE (CteToLocalViews path) |
✅ |
3000 string literals of different lengths (CHAR(n)) |
❌ Stack overflow at default stack; ✅ with -Xss512m (see inline) |
- missing (medium): None of the cases in the table are in the PR's tests.
INTERSECT/INTERSECT ALL in particular now go through a new N-ary LogicalIntersect path with no test. Please add at least the issue repro, INTERSECT, and the fallback-in-subquery case. The tests I used:
@Test public void intersectLong() {
var ccs = this.getCCS("CREATE TABLE t (x INT);\nCREATE VIEW v AS " +
chain(300, i -> "SELECT x FROM t", "INTERSECT") + ";");
ccs.stepWeightOne("INSERT INTO t VALUES(1),(1),(2);", " x\n---\n 1\n 2");
}
@Test public void mixedInSubquery() {
var ccs = this.getCCS("CREATE TABLE t (b BIGINT, d DOUBLE);\nCREATE VIEW v AS SELECT b FROM t WHERE b IN (" +
chain(200, i -> i == 150 ? "SELECT d FROM t" : "SELECT b FROM t", "UNION ALL") + ");");
ccs.stepWeightOne("INSERT INTO t VALUES(5, 1);", " b\n---\n 5");
}
@Test public void issue3000() {
this.getCC("CREATE TABLE t (id BIGINT NOT NULL, v BIGINT);\nCREATE MATERIALIZED VIEW u AS " +
chain(3000, i -> "SELECT id, v + " + i + " AS v FROM t", "UNION ALL") + ";");
}
- commit quality (medium): The subject of the first commit runs past 72 characters (GitHub cuts it off with
…). The body of the second commit is only Fixes #7931; it should say why the chains are balanced and why mixed types fall back to the left-deep form. The PR description says the stack is 256 MB, but the code and the commit both use 512 MB.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The parser builds a left-deep tree for a chain of set operations, and
the compiler and Calcite recurse once per level, so a view with a
UNION ALL of about 2,500 queries overflows the default stack. Chains
of more than 100 queries become balanced trees, log2(N) levels deep,
and each tree becomes one n-ary set operation.
SQL types a chain in the left-deep grouping. When the column types
need casts that depend on the grouping, the statement is validated
again in the left-deep form. Types that differ only in nullability,
and strings of different lengths, give the same result in every
grouping.
Fixes #7931
Signed-off-by: Mihai Budiu <[email protected]>
This branch has not been deployed
No deployments
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|