Skip to content

Preserve AS in CAST expressions during normalization - #113

Open
joelmarcotte wants to merge 1 commit into
joel.marcotte/cte-normalizationfrom
joel.marcotte/cast-normalization
Open

joelmarcotte wants to merge 1 commit into
joel.marcotte/cte-normalizationfrom
joel.marcotte/cast-normalization

Conversation

@joelmarcotte

Copy link
Copy Markdown
Contributor

Summary

  • Preserve the AS type separator in PostgreSQL CAST(expression AS type), including spaced and nested casts.
  • Continue removing projection and table aliases, including aliases inside a scalar subquery in a cast.
  • Reserve a small amount of extra builder capacity for short statements so the corrected output does not add an allocation in the simple case.

Stacked on #112 (joel.marcotte/cte-normalization).

Validation

  • go test ./... -count=1
  • go vet ./...
  • git diff --check
  • Focused benchmark on Apple M5 Pro, Go 1.27.1, seven samples: simple cast 485 to 531 ns/op (+9.4%), nested cast 777 to 847 ns/op (+9.0%), no-cast control 656 to 675 ns/op (+2.9%). Host load varied across runs, so timings are approximate. All focused cases remain at 6 allocs/op; the simple cast uses 352 B/op versus 320 B/op because the output retains AS integer.
  • Existing BenchmarkNormalizer samples for Escaping, Grouping, and Complex retained their baseline bytes/op and allocs/op.
  • Allocation profile shows no allocation in the CAST context. A forced-GC probe of three rounds of 500,000 CTE/cast normalizations had heap deltas of +16.6 KB during warmup, then -1.4 KB and -1.6 KB.

Compatibility

Normalized CAST output now includes AS type; query signatures derived from it may change. There are no dependency or public API changes.

@joelmarcotte
joelmarcotte requested a review from a team as a code owner September 30, 2026 18:15
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