Skip to content

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Oct 17, 2025

This commit disables running EXPLAIN ANALYZE stmts via pausable portals model even if it's enabled. Previously, this led to a crash since different assumptions of how EXPLAIN ANALYZE is handled at the connExecutor level were broken, but it also doesn't make much sense to actually support this. After all, the result rows can only be produced after the query execution effectively completed, which contradicts the spirit of the pausable portal feature.

I briefly looked into making it work, but it doesn't seem worth it. There is a fundamental contradiction right now that we defer finishing the instrumentationHelper (which populates the output of EXPLAIN ANALYZE), and it currently happens after we close the commandResult in which we can write the output.

Fixes: #137597.

Release note (bug fix): Previously, CockroachDB would crash when executing EXPLAIN ANALYZE statements with the pausable portal model (meaning that it was run via the extended PGWire protocol using Parse, Bind, Execute, when multiple_active_portals_enabled session variable is enabled). The bug has been present since 23.2 and is now fixed.

@yuzefovich yuzefovich requested review from a team, ZhouXing19 and michae2 October 17, 2025 20:28
@yuzefovich yuzefovich requested review from a team as code owners October 17, 2025 20:28
@yuzefovich yuzefovich added backport-25.3.x Flags PRs that need to be backported to 25.3 backport-25.4.x Flags PRs that need to be backported to 25.4 labels Oct 17, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the disable-portal-analyze branch from 4c723cc to 54ceb43 Compare October 17, 2025 20:30
@yuzefovich yuzefovich added the backport-25.2.x Flags PRs that need to be backported to 25.2 label Oct 17, 2025
Copy link
Collaborator

@ZhouXing19 ZhouXing19 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for looking into this!


subtest explain_analyze

# Regression test that EXPLAIN ANALYZE doesn't run throught the pausable portal
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Regression test that EXPLAIN ANALYZE doesn't run throught the pausable portal
# Regression test that EXPLAIN ANALYZE doesn't run through the pausable portal

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

This commit disables running EXPLAIN ANALYZE stmts via pausable portals
model even if it's enabled. Previously, this led to a crash since
different assumptions of how EXPLAIN ANALYZE is handled at the
connExecutor level were broken, but it also doesn't make much sense to
actually support this. After all, the result rows can only be produced
_after_ the query execution effectively completed, which contradicts the
spirit of the pausable portal feature.

I briefly looked into making it work, but it doesn't seem worth it.
There is a fundamental contradiction right now that we defer finishing
the instrumentationHelper (which populates the output of EXPLAIN
ANALYZE), and it currently happens after we close the commandResult in
which we can write the output.

Release note (bug fix): Previously, CockroachDB would crash when
executing EXPLAIN ANALYZE statements with the pausable portal model
(meaning that it was run via the extended PGWire protocol using Parse,
Bind, Execute, when `multiple_active_portals_enabled` session variable
is enabled). The bug has been present since 23.2 and is now fixed.
@yuzefovich yuzefovich force-pushed the disable-portal-analyze branch from 54ceb43 to a4d8381 Compare October 17, 2025 22:59
Copy link
Member Author

@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.

Note that if someone actually tries to run EXPLAIN ANALYZE via pausable portal, pause it, run some other statements via pausable portals, and then resume the EXPLAIN ANALYZE, then the behavior could be confusing (we probably will error on the first other stmt), but given the feature is in the preview, it seems acceptable to me.

TFTR!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @michae2 and @ZhouXing19)


subtest explain_analyze

# Regression test that EXPLAIN ANALYZE doesn't run throught the pausable portal
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@craig
Copy link
Contributor

craig bot commented Oct 17, 2025

@craig craig bot merged commit d3e894c into cockroachdb:master Oct 17, 2025
22 of 24 checks passed
Copy link

blathers-crl bot commented Oct 17, 2025

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #137597: branch-release-25.2, branch-release-25.3, branch-release-25.4.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link

blathers-crl bot commented Oct 17, 2025

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from a4d8381 to blathers/backport-release-25.2-155655: POST https://api.github.com/repos/yuzefovich/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 25.2.x failed. See errors above.


error creating merge commit from a4d8381 to blathers/backport-release-25.3-155655: POST https://api.github.com/repos/yuzefovich/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 25.3.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@yuzefovich yuzefovich deleted the disable-portal-analyze branch October 17, 2025 23:49
ZhouXing19 pushed a commit to ZhouXing19/cockroach that referenced this pull request Oct 21, 2025
155655: sql: don't run EXPLAIN ANALYZE via pausable portals r=yuzefovich a=yuzefovich

This commit disables running EXPLAIN ANALYZE stmts via pausable portals model even if it's enabled. Previously, this led to a crash since different assumptions of how EXPLAIN ANALYZE is handled at the connExecutor level were broken, but it also doesn't make much sense to actually support this. After all, the result rows can only be produced _after_ the query execution effectively completed, which contradicts the spirit of the pausable portal feature.

I briefly looked into making it work, but it doesn't seem worth it. There is a fundamental contradiction right now that we defer finishing the instrumentationHelper (which populates the output of EXPLAIN ANALYZE), and it currently happens after we close the commandResult in which we can write the output.

Fixes: cockroachdb#137597.

Release note (bug fix): Previously, CockroachDB would crash when executing EXPLAIN ANALYZE statements with the pausable portal model (meaning that it was run via the extended PGWire protocol using Parse, Bind, Execute, when `multiple_active_portals_enabled` session variable is enabled). The bug has been present since 23.2 and is now fixed.

Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-25.2.x Flags PRs that need to be backported to 25.2 backport-25.3.x Flags PRs that need to be backported to 25.3 backport-25.4.x Flags PRs that need to be backported to 25.4 backport-failed target-release-26.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: v24.2.5: "commandResult used after being released" with EXPLAIN ANALYZE and pausable portals

3 participants