Skip to content
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: do not drop a CALL statement with unused OUT params #143173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DrewKimball
Copy link
Collaborator

This commit fixes a bug that could cause the routine invocation for a PL/pgSQL CALL statement to be dropped if the stored proc had out params that were all unused by the calling routine. The fix is simple - just add an optimization barrier if the called procedure is volatile.

Fixes #143171

Release note (bug fix): Fixed a bug existing since PL/pgSQL CALL statements were introduced in v24.1, where the called procedure could be dropped if it had OUT parameters that were not used by the calling routine.

@DrewKimball DrewKimball added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x Flags PRs that need to be backported to 25.1 labels Mar 19, 2025
@DrewKimball DrewKimball requested a review from a team as a code owner March 19, 2025 23:43
@DrewKimball DrewKimball requested review from yuzefovich and removed request for a team March 19, 2025 23:43
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! :lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)


-- commits line 7 at r1:
Roughly speaking, only "volatile" functions can have side effects, and that's why we need to ensure their invocations don't get optimized away via the barrier, right?


pkg/ccl/logictestccl/testdata/logic_test/plpgsql_call line 484 at r1 (raw file):

SELECT * FROM xy;
----

nit: this shouldn't be empty now 😃

This commit fixes a bug that could cause the routine invocation for a
PL/pgSQL CALL statement to be dropped if the stored proc had out params
that were all unused by the calling routine. The fix is simple - just
add an optimization barrier if the called procedure is volatile (and may
have side effects).

Fixes cockroachdb#143171

Release note (bug fix): Fixed a bug existing since PL/pgSQL CALL statements
were introduced in v24.1, where the called procedure could be dropped if
it had OUT parameters that were not used by the calling routine.
Copy link
Collaborator Author

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFYR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @yuzefovich)


-- commits line 7 at r1:

Previously, yuzefovich (Yahor Yuzefovich) wrote…

Roughly speaking, only "volatile" functions can have side effects, and that's why we need to ensure their invocations don't get optimized away via the barrier, right?

Yes, exactly. I added a bit to the commit message.


pkg/ccl/logictestccl/testdata/logic_test/plpgsql_call line 484 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: this shouldn't be empty now 😃

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x Flags PRs that need to be backported to 25.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plpgsql: call statement is dropped if OUT parameters are not used
3 participants