optbuilder: handle unnest returning a tuple#85069
optbuilder: handle unnest returning a tuple#85069craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Currently, the return types of SRFs that return multiple columns are represented as tuples with labels. The tuple labels are used to decide whether or not to create a single output column for the SRF, or multiple. The `unnest` function can return a single column if it has a single argument, and the type of that column can be a tuple with labels. This could cause the old logic to mistakenly create multiple output columns for `unnest`, which could lead to panics down the line and incorrect behavior otherwise. This commit adds a special case for `unnest` in the `optbuilder` to only expand tuple return types if there is more than one argument (implying more than one output column). Other SRFs do not have the same problem because they either always return the same number of columns, cannot return tuples, or both. Fixes cockroachdb#58438 Release note (bug fix): Fixed a bug existing since release 20.1 that could cause a panic in rare cases when the unnest function was used with a tuple return type.
rytaft
left a comment
There was a problem hiding this comment.
Nice work! Are you confident that
unnest is the only function that behaves this way?
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)
|
(also please add labels to backport to 22.1 and 21.2 -- thanks!) |
|
TFTR!
It's hard to be absolutely certain since it requires manually looking through the functions, but I'm fairly confident. This bug requires an |
rytaft
left a comment
There was a problem hiding this comment.
Sounds good (if we find such a function we can always handle it later, anyway)
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)
|
bors r+ |
|
Build succeeded: |
Currently, the return types of SRFs that return multiple columns are
represented as tuples with labels. The tuple labels are used to decide
whether or not to create a single output column for the SRF, or multiple.
The
unnestfunction can return a single column if it has a single argument,and the type of that column can be a tuple with labels. This could cause the
old logic to mistakenly create multiple output columns for
unnest, whichcould lead to panics down the line and incorrect behavior otherwise.
This commit adds a special case for
unnestin theoptbuilderto only expandtuple return types if there is more than one argument (implying more than one
output column). Other SRFs do not have the same problem because they either
always return the same number of columns, cannot return tuples, or both.
Fixes #58438
Release note (bug fix): Fixed a bug existing since release 20.1 that could
cause a panic in rare cases when the unnest function was used with a
tuple return type.