Skip to content

PG client: evict cached statements on schema change for tables with 10+ columns - #1752

Open
Meemaw wants to merge 1 commit into
eclipse-vertx:masterfrom
Meemaw:fix-schema-change-pattern-multi-digit
Open

Meemaw wants to merge 1 commit into
eclipse-vertx:masterfrom
Meemaw:fix-schema-change-pattern-multi-digit

Conversation

@Meemaw

@Meemaw Meemaw commented Oct 8, 2026

Copy link
Copy Markdown

Fixes #1751

TABLE_SCHEMA_CHANGE_ERROR_MESSAGE_PATTERN matched the column counts with \d, which is a single digit, and String.matches requires the whole message to match. So bind message has 10 result formats but query has 11 columns never matched. The stale cached statement was never evicted, and every later execution on the connection failed with the same error until the connection was closed.

This changes both counts to \d+.

Test

PreparedStatementCachedTest#testPreparedQueryCacheRefreshOnWideTableSchemaChangeAfterReparse uses a 10-column table and adds an 11th column. Against plain Postgres, a cached statement fails with cached plan must not change result type instead, so the test simulates what a proxy such as RDS Proxy does: it re-prepares the statement under the same name with DEALLOCATE / PREPARE. The first execution fails with the 08P01 error, and the next one must succeed.

Without the fix, the second execution fails again with bind message has 10 result formats but query has 11 columns. With it, all PreparedStatement*Test tests pass.

TABLE_SCHEMA_CHANGE_ERROR_MESSAGE_PATTERN matched the column counts with
\d, a single digit, and String.matches requires a full match. So
"bind message has 10 result formats but query has 11 columns" never
matched, the stale cached statement was never evicted, and every later
execution on the connection failed with the same error until the
connection was closed.

Postgres reports this error when a proxy such as RDS Proxy parses the
named statement again after the schema change, before the client binds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Meemaw <ematej.snuderl@gmail.com>
@vietj vietj added this to the 5.2.2 milestone Oct 8, 2026
@tsegismont tsegismont modified the milestones: 5.2.2, 5.3.0 Oct 9, 2026

@tsegismont tsegismont left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @Meemaw , this looks good to me, but it would be great if we could address the regexp compilation concern.

private PgEncoder encoder;

private static final String TABLE_SCHEMA_CHANGE_ERROR_MESSAGE_PATTERN = "bind message has \\d result formats but query has \\d columns";
private static final String TABLE_SCHEMA_CHANGE_ERROR_MESSAGE_PATTERN = "bind message has \\d+ result formats but query has \\d+ columns";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While we're at it, can you convert this to a compiled pattern?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PG client: cached prepared statement is never evicted after a schema change on tables with 10+ columns

3 participants