Skip to content

fix(pretty-print): normalize WITH locations and ON TRUE joins in the generic pass - #801

Open
edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/normalize-parent-independent
Open

edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/normalize-parent-independent

Conversation

@edjubert

Copy link
Copy Markdown

What

Two normalizations move from a hand-written recursive walk into the generic clear_location pass, which visits every node whatever its parent:

  1. WithClause.location is now cleared like the other location fields.
  2. The INNER JOIN ... ON TRUE / CROSS JOIN equivalence is applied wherever a JoinExpr appears.

normalize_join_expr and its 80 lines of per-parent recursion are deleted.

Why

normalize_join_expr enumerated the parents it knew how to descend through: SelectStmt, RangeSubselect, ViewStmt, DeleteStmt, SubLink.
Any other parent hid the join from normalization, and the round-trip guard then reported a false difference - the printer spells a CROSS JOIN as INNER JOIN ON TRUE, so the two ASTs must compare equal for the statement to be formattable at all.

CREATE TABLE ... AS SELECT is exactly such a parent.
Both of these statements were refused before this PR and format correctly after it:

CREATE TABLE s.t AS
SELECT a.id, b.label
FROM s.a
	CROSS JOIN s.b;
CREATE TABLE s.t AS
WITH c AS (
	SELECT x.a FROM s.x ORDER BY x.a
)
SELECT c.a FROM c;

Putting both rules in the generic pass removes the class of bug rather than adding CreateTableAsStmt to a list that will be incomplete again next time.

Tests

Two new fixtures with snapshots at widths 80 and 100. normalize_coverage.rs loses the entry for the deleted function.

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