Skip to content

fix(deparser): support ALTER STATISTICS ... RENAME TO - #391

Merged
pyramation merged 2 commits into
mainfrom
fix/deparser-alter-statistics-rename
Nov 21, 2026
Merged

pyramation merged 2 commits into
mainfrom
fix/deparser-alter-statistics-rename

Conversation

@pyramation

@pyramation pyramation commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

ALTER STATISTICS s1 RENAME TO s2 threw Unsupported RenameStmt renameType: OBJECT_STATISTIC_EXT. It now emits STATISTICS and handles qualified names through the same List path as types and domains. Fixtures cover plain, schema-qualified and quoted names.

This is a fresh version of the rename part of #370, part of constructive-io/constructive-planning#2555. SET STATISTICS DEFAULT / IF EXISTS are separate bugs, tracked in the epic.


libpg-query and parser opened this PR for Dan
Implemented in session Triage stale open PRs and issues in parser repos
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Improved formatting for ALTER STATISTICS ... RENAME TO statements with unqualified names, schema-qualified names, and quoted schema or statistics identifiers. Formatted SQL now keeps these names correctly separated and quoted, making rename statements clearer to read across these naming styles.

@luxor-code-review

luxor-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR extends the deparser to handle the renameType statement branch for statistics objects so ALTER STATISTICS ... RENAME TO ... round-trips correctly, and adds fixtures and tests covering both the standard and pretty-print output paths.

Files Change
packages/deparser/src/deparser.ts Adds handling of OBJECT_STATISTIC_EXT in the rename statement rendering to emit ALTER STATISTICS <name> RENAME TO <newname>.
__fixtures__/generated/generated.json, __fixtures__/kitchen-sink/misc/alter-statistics-rename.sql Adds the generated AST fixture and kitchen-sink SQL fixture for the new statement.
packages/deparser/__tests__/kitchen-sink/misc-alter-statistics-rename.test.ts Adds a kitchen-sink round-trip test for ALTER STATISTICS ... RENAME.
packages/deparser/__tests__/pretty/alter-statistics-rename.test.ts + snapshot Adds a pretty-print test with its recorded snapshot.

Reviewed commit: 4ddf1b4

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The deparser now handles ALTER STATISTICS ... RENAME TO statements. It emits the STATISTICS keyword and formats statistics names, including qualified and quoted names. Fixtures and tests cover these name forms.

Changes: Statistics Rename

Layer / File(s) Summary
Statistics rename support
packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/alter-statistics-rename.sql, packages/deparser/__tests__/kitchen-sink/misc-alter-statistics-rename.test.ts, packages/deparser/__tests__/pretty/alter-statistics-rename.test.ts
RenameStmt now emits STATISTICS for statistics objects and formats qualified names with dotted, conditionally quoted identifiers. Fixtures and tests cover unqualified, public-qualified, and quoted names.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to 80264

This adds support for ALTER STATISTICS ... RENAME TO in the deparser, with fixtures covering plain, schema-qualified and quoted names. No concrete defects were found, so the merge risk is minimal.

Security architecture risk: Minimal · up to 80264

The change adds SQL rendering support while retaining existing identifier quoting. The inspected path returns SQL text rather than executing it, and no introduced security, ownership, or failure-containment risk was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly established exposure is newly supported SQL generation for caller-supplied statistics-rename ASTs. Actual database execution, credentials, authorization, and tenant scope depend on consumers not established by the supplied relationship evidence.

Trust Boundaries and Controls

  • inferred — Caller-controlled names enter SQL identifier positions through the existing quoting control rather than raw interpolation in the added List branch. The inspected change enables rendering, not an authorization bypass; no execution boundary is crossed within RenameStmt itself.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the deparser now supports ALTER STATISTICS ... RENAME TO. The raw summary confirms that RenameStmt maps OBJECT_STATISTIC_EXT to the STATISTICS keyword and that the fix…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the deparser now supports ALTER STATISTICS ... RENAME TO. The raw summary confirms that RenameStmt maps OBJECT_STATISTIC_EXT to the STATISTICS keyword and that the fixtures and tests cover the rename statements. The title is specific, concise, and matches the PR objectives. It does not mention the separate SET STATISTICS DEFAULT or IF EXISTS bugs, which the PR does not claim to address.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4ddf1b4 and 8026412.

Files ignored due to path filters: 2

  • __fixtures__/generated/generated.json is excluded by !**/generated/**, !__fixtures__/generated/**
  • packages/deparser/__tests__/pretty/__snapshots__/alter-statistics-rename.test.ts.snap is excluded by !**/*.snap, !**/__snapshots__/**
Files selected for processing: 1

  • packages/deparser/src/deparser.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@pyramation
pyramation merged commit 5ba55f0 into main Nov 21, 2026
23 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