Conversation
When a table schema expands (e.g., adding a column) between executions of a prepared statement that returns rows (such as `SELECT *` or a write with `RETURNING *`), client drivers re-execute the statement using the number of result format codes negotiated during the initial parse/describe phase. When Spanner returned more columns than the client provided format codes for, `IntermediatePortalStatement.getResultFormatCode(index)` threw an `ArrayIndexOutOfBoundsException`. Because Spanner had already executed and committed the statement, the client received a fatal error despite the write succeeding on the database. This change: - Bounds-checks `index` in `getResultFormatCode(int)` and defaults out-of-bounds columns to text format (0). - Updates `getParameterFormatCode(int)` to check single-code mode before bounds checking, safely defaulting out-of-bounds parameter indices to 0.
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of PGAdapter when handling concurrent schema changes. Specifically, it updates IntermediatePortalStatement to safely handle out-of-bounds indices for parameter and result format codes, preventing potential ArrayIndexOutOfBoundsException errors when columns are added or dropped. Additionally, it refactors DescribeResult to use a static factory method and introduces comprehensive unit and integration tests to verify these scenarios. I have no feedback to provide as there are no review comments to evaluate.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of PGAdapter when handling concurrent schema changes by safely managing out-of-bounds parameter and result format codes in IntermediatePortalStatement. It also introduces a static factory method and a new constructor in DescribeResult to simplify instantiation, along with comprehensive unit and integration tests verifying these changes. The review feedback suggests renaming the parameters argument to givenParameterTypes in the new DescribeResult factory method and constructor to avoid confusion with the class field of the same name and to improve code clarity.
…prepared-statement
17a84c4 to
df68d48
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces safety checks and robust handling for out-of-bounds parameter and result format codes in IntermediatePortalStatement. It also adds a static factory method 'of' to DescribeResult with null preconditions, and updates IntermediatePreparedStatement to use it. Additionally, comprehensive unit and integration tests are added to verify behavior during concurrent schema changes (expansion and contraction) and with mixed or out-of-bounds format codes. I have no feedback to provide as there are no review comments.
When a table schema expands (e.g., adding a column) between executions of a prepared statement that returns rows (such as
SELECT *or a write withRETURNING *), client drivers re-execute the statement using the number of result format codes negotiated during the initial parse/describe phase.When Spanner returned more columns than the client provided format codes for,
IntermediatePortalStatement.getResultFormatCode(index)threw anArrayIndexOutOfBoundsException. Because Spanner had already executed and committed the statement, the client received a fatal error despite the write succeeding on the database.This change:
indexingetResultFormatCode(int)and defaults out-of-bounds columns to text format (0).getParameterFormatCode(int)to check single-code mode before bounds checking, safely defaulting out-of-bounds parameter indices to 0.Fixes b/562754971