GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [SQL] Reduce SQL compiler stack usage by mihaibudiu · Pull Request #7938 · feldera/feldera

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Unit tests added/updated

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mythical-fred-oss[bot]
mythical-fred-oss Bot reviewed Nov 11, 2026
View reviewed changes
Comment thread ...c/main/java/org/dbsp/sqlCompiler/compiler/frontend/calciteCompiler/BalanceSetOperations.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mythical-fred-oss

mythical-fred-oss Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mihaibudiu added 2 commits November 11, 2026 08:56
@mihaibudiu
[SQL] Run the compiler with a 512 MB stack; report stack overflows
5d07578
Signed-off-by: Mihai Budiu <[email protected]>
@mihaibudiu
[SQL] Balance long chains of UNION and INTERSECT
f3f5ea2
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]>
@mihaibudiu
mihaibudiu force-pushed the issue7931 branch from 0f2d4e8 to f3f5ea2 Compare November 11, 2026 17:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mythical-fred-oss mythical-fred-oss[bot] mythical-fred-oss[bot] left review comments

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

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[SQL] StackOverflowError when a view is a UNION ALL of about 2,500 or more branches

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@mihaibudiu
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.