Add failing test: batch scan corrupted in cache_statement mode#2524
Merged
jackc merged 1 commit intojackc:masterfrom Mar 22, 2026
Merged
Add failing test: batch scan corrupted in cache_statement mode#2524jackc merged 1 commit intojackc:masterfrom
jackc merged 1 commit intojackc:masterfrom
Conversation
sendBatchExtendedWithDescription passes eqb.ResultFormats to SendQueryStatement by reference. The next Build call reuses the backing array (reset sets len=0, append overwrites), corrupting the stored format codes for earlier queries. The server sends binary data (Bind was encoded correctly), but the local scan plan uses the corrupted text format code. Introduced in v5.9.0 by c3a1750 ("pgx batch uses SendQueryStatement"), part of "Skip Describe Portal for cached prepared statements reducing network round trips". The previous SendQueryPrepared path sent Describe Portal, so the server's RowDescription provided correct format codes regardless of the stored slice contents. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Owner
|
Good catch. Should have a fix in a few minutes. |
jackc
added a commit
that referenced
this pull request
Mar 22, 2026
Copy ResultFormats slice before passing to SendQueryStatement, which stores it for later use. The extended query builder reuses the backing array on the next loop iteration, corrupting format codes stored for earlier queries in the batch. Fixes the bug exposed by the test in #2524. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
Thanks for the great bug report. It was easy to fix with the failing test. Fix released in v5.9.1. |
Contributor
Author
|
@jackc Thanks for the quick fix! |
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.
sendBatchExtendedWithDescriptionpasseseqb.ResultFormatstoSendQueryStatementby reference. The nextBuildcall reuses the backing array, corrupting the stored format codes for earlier queries. The server sends binary data (Bindwas encoded correctly), but the local scan plan uses the corrupted text format code.Exposed in v5.9.0 by c3a1750 (
pgx batch uses SendQueryStatement), part ofSkip Describe Portal for cached prepared statements reducing network round trips. The previousSendQueryPreparedpath sent Describe Portal, so the server'sRowDescriptionprovided correct format codes regardless of the stored slice contents.@jackc This happened when we updated to 5.9.0. As the test describes, I think it classifies as a bug? I haven't dug into how to fix it yet though, maybe that's immediately obvious to you?
Test fails reproducing the problem we have:
It shows that it tries to parse the binary wire encoding for
1astextsince the second query in the pipeline usestext.