Skip to content

sql: expand stars directly inside ROW expressions - #175302

Open
Alignyx wants to merge 2 commits into
cockroachdb:masterfrom
Alignyx:fix-26619-row-star-expansion
Open

sql: expand stars directly inside ROW expressions#175302
Alignyx wants to merge 2 commits into
cockroachdb:masterfrom
Alignyx:fix-26619-row-star-expansion

Conversation

@Alignyx

@Alignyx Alignyx commented Sep 12, 2026

Copy link
Copy Markdown

Summary

Expand stars that are direct children of an explicit ROW(...) constructor into the enclosing row expression, matching PostgreSQL tuple semantics.

Fixes #26619

Root cause

The expression visitor normally replaces one expression with one expression. For ROW((pg_get_keywords()).*), the star expands to several columns, but the visitor cannot splice those columns into the parent tuple. The expanded value was therefore retained as a nested tuple-valued expression and later rendered as a single string-like field. PostgreSQL instead replaces the direct star with the expanded fields, producing one row with the expected columns.

The syntax distinction matters: an explicit ROW(...) constructor has different expansion semantics from shorthand tuple expressions. Applying the splice to every tuple would change existing behavior for shorthand tuples and regress the counterexample covered by the surrounding name-resolution logic.

Change

Handle tree.Tuple nodes before the ordinary child walk:

  1. Restrict the new behavior to tuples marked as explicit rows.
  2. Normalize direct variable names before checking for AllColumnsSelector or TupleStar children.
  3. Expand each direct star with the existing expandStar implementation and append all resulting expressions to the enclosing row.
  4. Continue walking non-star children normally.
  5. Rebuild the tuple while preserving its explicit labels and original tuple metadata.

Nested stars and shorthand tuples continue through the existing path. The change is limited to direct-star expansion inside ROW(...), so it fixes the reported case without changing unrelated tuple construction.

Validation

  • Reproduced SELECT ROW((pg_get_keywords()).*) and verified that the expanded fields form the enclosing row instead of a nested string-like value.
  • Verified shorthand tuple behavior remains unchanged.
  • Ran the affected optimizer/name-resolution module tests, native regression checks, held-out checks, and the full regression suite.

@Alignyx
Alignyx requested a review from a team as a code owner September 12, 2026 12:35
@Alignyx
Alignyx requested review from ZhouXing19 and removed request for a team September 12, 2026 12:35
@blathers-crl

blathers-crl Bot commented Sep 12, 2026

Copy link
Copy Markdown

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added the O-community Originated from the community label Sep 12, 2026
Cover the pg_get_keywords reproduction, tuple and relation stars, mixed fields, nested rows, NULL fields, and labeled tuple access. Keep explicit controls for non-star children and shorthand tuple nesting.

Release note: None
@blathers-crl

blathers-crl Bot commented Sep 13, 2026

Copy link
Copy Markdown

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: star expansion inside ROW is incorrect

1 participant