Skip to content

fix(calcite): keep push-down VALUES under the JVM's 64 KB method limit - #569

Merged
dfa1 merged 2 commits into
mainfrom
fix/values-64kb-limit
Oct 19, 2026
Merged

dfa1 merged 2 commits into
mainfrom
fix/values-64kb-limit

Conversation

@dfa1

@dfa1 dfa1 commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Found while trying the jdbc:vortex: driver (#568) in IntelliJ against a 100M-row file.

Bug

The sort (ORDER BY ... LIMIT) and grouped-aggregate push-downs answer with a literal VALUES. Calcite compiles the whole VALUES into one Java method, and the JVM refuses a method over 64 KB of bytecode, so the query failed with Code grows beyond 64 KB. The grouped cap (10,000 groups) and the sort cap (1,000 rows) counted rows only, not columns.

  • group by a string column with 3,000 groups and count(*) failed; 2,000 groups passed.
  • select * ... order by x limit 1000 over 9 columns failed; limit 500 passed. IntelliJ's grid sorts with order by ... limit 500.

Fix

A shared budget of 4,000 literal cells (rows x columns). Measured on a mixed-type table: 4,500 cells compile, 6,000 do not. Above the budget the rule leaves the plan to Calcite's own scan/sort, which is slower but correct.

Tests

ValuesCodegenLimitTest: over the cap the query falls back and returns the full, correct result; under the cap it is still pushed down. 4 of its 6 cases fail without the fix.

No vortex-jni cross-check: this is Calcite code generation in the Java adapter, nothing is read or written differently.

🤖 Generated with Claude Code

The sort and grouped-aggregate rules answer with a literal VALUES, which
Calcite compiles into one Java method. Past about 5,000 cells the JVM
refuses it ("Code grows beyond 64 KB") and the query failed outright: a
GROUP BY with 3,000 groups, or ORDER BY ... LIMIT 1000 over 9 columns, as an
IDE grid issues. Cap the push-down at 4,000 cells (rows x columns, measured:
4,500 compile, 6,000 do not) and leave bigger results to Calcite's own scan.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ALUES cap

Review of #570 found two flaws in the cap:
- the sort rule counted fetch + offset rows, but only the rows after the
  offset become literals, so LIMIT 100 OFFSET 900 over a wide table fell back
  to Calcite's slow sort though it fits (it was pushed down before the cap);
- the grouped rule checked the cap after groupedFold had scanned the whole
  file, so 2,000 to 10,000 groups paid for two scans. groupedFold now takes the
  limit and gives up as soon as it is exceeded.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dfa1
dfa1 merged commit 338b5f6 into main Oct 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant