Skip to content

fix(lint)!: make max_function_call_depth the exact limit in every linted dialect - #268

Closed
kvlonge wants to merge 5 commits into
mainfrom
fix/lint-call-depth-all-dialects
Closed

kvlonge wants to merge 5 commits into
mainfrom
fix/lint-call-depth-all-dialects

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

max_function_call_depth only bounded lint on Snowflake, DuckDB and SQLite. The Postgres, BigQuery and Databricks parsers ignored it:

  • a limit of 3 or 64 still linted 100 nested calls;
  • BigQuery and Databricks refused about 198 calls, and Postgres 299, whatever the setting;
  • at 512 they linted 512 calls, which the AST-depth guard refuses in the other three.

Changes

  • Before parsing, lint checks tokens against the call limit and the fixed 512 parenthesis ceiling in every dialect. Below 512, N nested calls lint and N+1 are refused with E_GUARD_FUNCTION_NESTING_DEPTH_EXCEEDED.
  • Breaking: the native path runs the existing 512 AST-depth guard, as the shared parser does. Postgres, BigQuery and Databricks now refuse any tree past 512 levels, such as 600 UNION ALL operands or :: casts, as Snowflake and DuckDB already did.
  • When the refused SQL calls something, the AST-depth refusal adds: "The maximum is 512. The statement and every expression around the calls also count toward that limit, so at 512 a bare SELECT can nest at most 511 calls, and fewer fit inside an alias, comparison or CTE." Other refusals keep the bare text.
  • The three native parsers' recursion bounds rise from 200, 200 and 300 to 600, so the setting decides first.

Verification

  • A lint test pins, in all six dialects: limits 3, 64 and 256 exact; at 512, 511 calls lint bare, 510 aliased or compared, 509 in a CTE, one more is refused with the note, and 600 UNION ALL operands get the bare refusal. It fails on main in the three native dialects.
  • A fixture harness's empty relation is not counted as a call.
  • The native depth tests move past 600 levels on a 2 MiB thread; 590 TRIM( calls parse in 0.37 s (release).
  • make check-ci on the head.

…ed dialect

Lint passed the call-depth limit to the shared parser only, so Postgres, BigQuery and Databricks
ignored it: a limit of 3 or 64 still linted 100 nested calls, and their native parsers refused at
fixed depths below the documented ceiling (about 198 calls on BigQuery and Databricks, 299 on
Postgres).

Lint now checks the lexed tokens against the configured call depth and the 512-level parenthesis
ceiling before parsing, in every dialect, so N nested calls lint and N+1 are refused with the
function-nesting error. The BigQuery, Databricks and Postgres parsers' recursion bounds rise from
200, 200 and 300 to 600, past SQLQuack's fixed 512-call ceiling, so the configured limit decides
first.
…red parser does

At a limit of 512, Postgres, BigQuery and Databricks linted 512 nested calls, because their
native path skipped the AST-depth guard that refuses the same statement in Snowflake, DuckDB and
SQLite. The native path now runs that depth guard on its result, so every dialect refuses at the
same point with the same error.

A refusal at the ceiling now says why fewer than 512 calls fit: the maximum is 512, and the
statement and every expression around the calls also count toward that limit, so at 512 a bare
SELECT can nest at most 511 calls, and fewer fit inside an alias, comparison or CTE.
…epth

In a fixture harness, lint reads FROM <empty_relation>() as a bare relation by blanking its
parentheses before parsing. The new pre-parse depth check ran on the original tokens, so the
blanked parentheses counted as one more call level: at a limit of 1, one call around a subquery
reading the empty relation was refused. The check now reads the blanked text's tokens, as the
parse does.
@kvlonge
kvlonge enabled auto-merge November 19, 2026 02:00
@kvlonge
kvlonge disabled auto-merge November 19, 2026 02:04
… something

At the 512 ceiling, every tree-depth refusal said how many nested calls fit, even for SQL with no
call, such as a long UNION ALL chain. The note now follows E_GUARD_AST_DEPTH_EXCEEDED only when the
statement holds a call; other refusals keep the bare guard text. Lint and the shared parse entry
point decide the same way, from the statement's tokens.

BREAKING CHANGE: lint now refuses a Postgres, BigQuery or Databricks statement whose tree nests
past 512 levels, as Snowflake, DuckDB and SQLite already did, so 600 UNION ALL operands or 600
`::` casts no longer lint in those dialects.
@kvlonge kvlonge changed the title fix(lint): make max_function_call_depth the exact limit in every linted dialect fix(lint)!: make max_function_call_depth the exact limit in every linted dialect Nov 19, 2026
…ceiling

parse_source_within, which convert and check use, refuses 600 UNION ALL operands at the 512
ceiling with the guard's own text and no note about nested calls.
@kvlonge
kvlonge enabled auto-merge November 19, 2026 02:26
@kvlonge
kvlonge disabled auto-merge November 19, 2026 02:43

kvlonge commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #269: the merge queue rebases, so the commit that makes lint refuse native trees past 512 levels needs ! in its own subject. Same tree, reworded commits.

@kvlonge kvlonge closed this Nov 19, 2026
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