Skip to content

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

Merged
tsegismont merged 1 commit into
eclipse-vertx:masterfrom
Meemaw:fix-schema-change-pattern-multi-digit
Oct 12, 2026
Merged

tsegismont merged 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
Contributor

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.

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

@Meemaw
Meemaw force-pushed the fix-schema-change-pattern-multi-digit branch from 2e09cf3 to c1729d6 Compare October 12, 2026 10:14
@vietj

vietj commented Oct 12, 2026

Copy link
Copy Markdown
Member

@Meemaw can you make it a single commit and follow the message format for your commit specified here ? https://github.com/eclipse-vertx/vert.x/blob/master/CONTRIBUTING.md#commit-message

See eclipse-vertx#1751

Motivation:

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.

Modifications:

Match the column counts with \d+ and precompile the pattern.

Add a test that uses a 10-column table, adds an 11th column, and
re-prepares the named statement with DEALLOCATE / PREPARE to simulate
the proxy.

Result:

The cached statement is evicted after the first failure, and the next
execution succeeds.

Assisted-by: Anthropic Claude (claude-opus-5-5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Meemaw <ematej.snuderl@gmail.com>
@Meemaw
Meemaw force-pushed the fix-schema-change-pattern-multi-digit branch from c1729d6 to 942d238 Compare October 12, 2026 12:31
@Meemaw

Meemaw commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@vietj Done: squashed into a single commit and reworded the message to the Motivation / Modifications / Result format.

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

LGTM, thanks

@tsegismont

Copy link
Copy Markdown
Member

@Meemaw would you mind sending PRs for 5.2 and 4.x branches? Thank you

@tsegismont
tsegismont merged commit 630888b into eclipse-vertx:master Oct 12, 2026
20 checks passed
tsegismont added a commit that referenced this pull request Oct 15, 2026
…1752) (#1753)

See #1751

Motivation:

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.

Modifications:

Match the column counts with \d+ and precompile the pattern.

Add a test that uses a 10-column table, adds an 11th column, and
re-prepares the named statement with DEALLOCATE / PREPARE to simulate
the proxy.

Result:

The cached statement is evicted after the first failure, and the next
execution succeeds.

Assisted-by: Anthropic Claude (claude-opus-5-5)

Signed-off-by: Meemaw <ematej.snuderl@gmail.com>
Co-authored-by: Matej Šnuderl <ematej.snuderl@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
tsegismont added a commit that referenced this pull request Oct 15, 2026
…1752) (#1754)

See #1751

Motivation:

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.

Modifications:

Match the column counts with \d+ and precompile the pattern.

Add a test that uses a 10-column table, adds an 11th column, and
re-prepares the named statement with DEALLOCATE / PREPARE to simulate
the proxy.

Result:

The cached statement is evicted after the first failure, and the next
execution succeeds.

Assisted-by: Anthropic Claude (claude-opus-5-5)

Signed-off-by: Meemaw <ematej.snuderl@gmail.com>
Co-authored-by: Matej Šnuderl <ematej.snuderl@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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