Repository navigation
[SQL] Reduce SQL compiler stack usage - #7938
Open
mihaibudiu wants to merge 2 commits into
Open
mihaibudiu wants to merge 2 commits into
mihaibudiu wants to merge 2 commits into
Conversation
Contributor
|
What I ran:
@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") + ";");
}
|
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
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 <mbudiu@feldera.com>
mihaibudiu
force-pushed
the
issue7931
branch
from
November 11, 2026 17:35
0f2d4e8 to
f3f5ea2
Compare
This branch has not been deployed
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.
Linked Issue
Fixes #7931
There are two commits:
Checklist