New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plpgsql: don't exit early when SELECT INTO returns no rows #115650
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 10 of 10 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @rharding6373)
pkg/sql/opt/norm/factory.go
line 469 at r1 (raw file):
// ConstructOneRowValues constructs a Values operator with zero columns and one // row. func (f *Factory) ConstructOneRowValues() memo.RelExpr {
nit: Just brainstorming some different name options: ConstructZeroColRow
? ConstructSingleNullaryRowValues
? Or use the same name of the custom func ConstructNoColsRows
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @DrewKimball)
Previously, a SELECT INTO statement that returned zero rows wouldn't call the continuation, since the continuation is called as a projection. This patch adds a RIGHT JOIN with a zero-column one-row Values operator to ensure that SELECT INTO statements are correctly null-extended when the underlying SQL statement returns no rows. See the postgres docs: ``` https://www.postgresql.org/docs/16/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW ``` Fixes cockroachdb#114826 Release note (bug fix): Fixed a bug that existed only in pre-release versions v23.2.0-beta.1 and v23.2.0-beta.2 which could cause PLpgSQL routines with SELECT INTO syntax to return early.
8cd7c8f
to
f83b13a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)
pkg/sql/opt/norm/factory.go
line 469 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
nit: Just brainstorming some different name options:
ConstructZeroColRow
?ConstructSingleNullaryRowValues
? Or use the same name of the custom funcConstructNoColsRows
.
Keeping ConstructNoColsRow
is a good idea, I'll do that.
TFTRs! bors r+ |
Build succeeded: |
Previously, a SELECT INTO statement that returned zero rows wouldn't call the continuation, since the continuation is called as a projection. This patch adds a RIGHT JOIN with a zero-column one-row Values operator to ensure that SELECT INTO statements are correctly null-extended when the underlying SQL statement returns no rows. See the postgres docs:
Fixes #114826
Release note (bug fix): Fixed a bug that existed only in pre-release versions v23.2.0-beta.1 and v23.2.0-beta.2 which could cause PLpgSQL routines with SELECT INTO syntax to return early.