Conversation
A table-source unnest over a labeled composite array should expose the individual tuple fields. Keep one physical ProjectSet output per array element and project the labeled fields into the table-source scope. Restrict this to the resolved built-in single-array generator overload so same-named UDFs retain their output contract. Add a data-driven regression that fails on the unmodified baseline and passes with the change; the optbuilder suite passes. Production patch generated with Codex CLI through MetamorphicRepair. Fixes cockroachdb#98352 Release note (backward-incompatible change): A single-array unnest call used as a table source now expands labeled composite values into individual columns, rather than returning one tuple-valued column. Queries using SELECT * from that table source may therefore return more columns. The number of array elements returned is unchanged.
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
unnest(ARRAY[t.*])is used as a table source, a labeled row value should expose its fields as separate columns. The query in #98352 currently returns the two columns fromtplus one tuple-valuedunnestcolumn. This change returns four scalar columns while preserving the three result rows.The single-array
unnestgenerator still emits one physical datum per array element. Changing only the declared output columns would leave the optimizer's column IDs out of sync with the executor. Instead, this patch keeps the single tuple column inProjectSetand adds a projection above it to extract each labeled field. The scope exposes those projected fields as the table-source columns.The special case is selected using the resolved built-in generator overload and its single array argument. A user-defined function named
unnesttherefore does not acquire the built-in's output layout. An assertion checks that the Zip output and scope refer to the same single physical column before the projection is constructed.The data-driven regression records the expanded columns and the projection above
ProjectSetfor the reported lateral query.Validation
bazel test //pkg/sql/opt/optbuilder:optbuilder_test --test_arg=-test.run=^TestBuilder$/^srfs$passed.8812064afailed: the plan retained one tuple column instead of the two field projections.bazel test //pkg/sql/opt/optbuilder:optbuilder_testpassed.The repair harness also executed the reported query and equivalents, checking all four INT8 columns and the three ordered result rows. The checks do not establish exhaustive compatibility for NULL composite values, alias lists or arbitrary same-named UDFs.
Fixes #98352
Release note (backward-incompatible change): A single-array unnest call used as a table source now expands labeled composite values into individual columns, rather than returning one tuple-valued column. Queries using SELECT * from that table source may therefore return more columns. The number of array elements returned is unchanged.