Conversation
A SETOF VOID SQL function currently exposes the result of its final statement as a NULL row. Mark that result for discard while still executing the body. Scalar VOID and non-VOID set-returning functions retain their existing behavior. Add an execution regression for SELECT-list and FROM-clause calls, body side effects, scalar VOID and SETOF INT. The regression fails on the unmodified baseline and passes with this change. Production patch generated with Codex CLI through MetamorphicRepair. Fixes cockroachdb#103119 Release note (backward-incompatible change): SQL functions declared RETURNS SETOF VOID no longer produce a row from their final body statement. Applications relying on that row should use a scalar VOID function when one return row is required. Function bodies still execute, including their side effects.
|
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.
Selecting from a SQL UDF declared
RETURNS SETOF VOIDcurrently exposes a NULL row from its finalSELECT NULL. This change makes that function produce no result rows, while still executing its body.The existing
DiscardLastStmtResultpath already runs the final statement without adding its output to the routine's result buffer.buildUDFnow selects that path for a set-returning routine whose result family is VOID, as well as for routines that use an explicit result buffer. Checking both properties keeps scalar VOID functions and non-VOID set-returning functions on their existing paths.The issue explicitly leaves open whether CockroachDB should adopt PostgreSQL's behavior here. This PR implements that compatibility choice; it does not assume that the API decision has already been made.
The regression exercises calls in both the SELECT list and FROM clause, checks that a volatile function still performs an INSERT, and checks scalar VOID and SETOF INT results.
Validation
bazel test //pkg/sql:sql_test --test_arg=-test.run=^TestSetReturningVoidCardinality$passed.8812064afailed because each SETOF VOID call returned[[NULL]]instead of an empty result.The earlier broad
//pkg/sql:sql_testrun did not complete cleanly on this machine.TestTenantStatementTimeoutAdmissionQueueCancellationalso timed out when run alone on the unmodified baseline. Other resource-related failures passed when rerun with one job. I am reporting the focused regression results here, not a clean full SQL-suite pass.Fixes #103119
Release note (backward-incompatible change): SQL functions declared RETURNS SETOF VOID no longer produce a row from their final body statement. Applications relying on that row should use a scalar VOID function when one return row is required. Function bodies still execute, including their side effects.