Skip to content

fix(rules): end the SQLCLEAN053 ON scan at a PIVOT USING list - #24

Merged
kvlonge merged 2 commits into
mainfrom
fix/pivot-using-clause
Nov 1, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/pivot-using-clause

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Why

SQLBuild now runs the SQLClean Rules by default. Two engine issues surfaced in its compiler corpus and cold compile benchmarks:

  • SQLCLEAN053 reported DuckDB PIVOT ... ON status USING MAX(amount) as an aggregate inside a join condition. The ON clause scan did not stop at USING, so it ran into the pivot aggregates.
  • The null comparison check scanned backwards from every comparison to find its clause. On long queries that is quadratic: 12.5 ms of one 83 KB file's lint time went to this check alone.

Changes

  • USING ends the clause in the SQLCLEAN053 scan. A real aggregate in a join ON beside a pivot still reports.
  • assignment_operators finds SET assignments in one forward pass that tracks the latest clause opener per depth. Same stop set and same-depth rule as before.

Verification

  • New SQLCLEAN053 cases: the pivot case fails without the fix and passes with it; the join ON aggregate next to a pivot still reports.
  • Across 3000 compiled SQLBuild benchmark models with every Rule enabled, diagnostics are byte-identical before and after the perf change. Lint time drops by about 17% (largest file 27.8 ms to 16.5 ms). Cost per KB is now flat from small to 83 KB files.
  • cargo fmt --check, clippy -D warnings, cargo test --all, ruff, ty, fensu check (0 faults), the docs skill check and the hygiene scan pass.

BEGIN_COMMIT_OVERRIDE
fix(rules): end the SQLCLEAN053 ON scan at a PIVOT USING list
perf(rules): find SET assignments in one forward pass
END_COMMIT_OVERRIDE

A DuckDB PIVOT ... ON list is followed by USING aggregates, which the
ON clause scan treated as aggregates inside a join condition.
The null comparison check scanned backwards from every comparison to
find its clause, which is quadratic in long queries.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sqlclean with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3f844e4
Status:⚡️  Build in progress...

View logs

@kvlonge
kvlonge merged commit aed227a into main Nov 1, 2026
4 of 5 checks passed
@kvlonge kvlonge mentioned this pull request Nov 1, 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