fix: return proper error instead of assertion when portal format codes are too short (#173071) - #173072
Open
waterWang wants to merge 2 commits into
Open
Conversation
… codes are too short (cockroachdb#173071)
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
|
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.
Summary
Fixes #173071
When a portal prepared from an
EXECUTEwrapper outlives a result-shape change, the format codes sized at Bind time (from the wrapper's frozen column count) may not cover the columns the plan actually produces at Execute time. This causes an assertion failure inGetFormatCode():Root Cause
The
EXECUTEhandler inexecStmtInOpenStatereplaces the wrapper statement with the inner prepared statement's data. The inner statement'sExpectedTypesis refreshed from the re-prepared inner statement, so the plan-time guard passes. However, the format codes on the portal were sized at Bind time from the wrapper's frozenColumns, which may still reflect the old schema.Changes
pkg/sql/pgwire/command_result.go: Changederrors.AssertionFailedftoerrors.NewfinGetFormatCode()— the mismatch is a recoverable error, not an assertion violation.pkg/sql/conn_executor.go: IninitStatementResult(), whenGetFormatCode()returns an error (format codes too short for the result columns), convert it to apgcode.FeatureNotSupportederror (0A000 cached plan must not change result type) — matching the error code returned by the non-EXECUTEBind-time guard.Reproduction
See the test case in the issue:
PREPARE bar AS SELECT * FROM v WHERE id = 1→ALTER TABLE v ADD COLUMN b INT→DEALLOCATE bar; PREPARE bar AS SELECT * FROM v, b→EXECUTE baron a portal bound before the DDL.Impact
Intermittent
XX000internal errors surfaced to application clients using the extended query protocol (server-side prepared statements) on long-lived pooled connections after schema migrations.