Skip to content

Commit c9381d1

Browse files
tolbertamolim7t
authored andcommitted
JAVA-1227: Document "SELECT *" issue with prepared statement (apache#703)
1 parent 86a6a45 commit c9381d1

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [improvement] JAVA-1198: Document that BoundStatement is not thread-safe.
1616
- [improvement] JAVA-1200: Upgrade LZ4 to 1.3.0.
1717
- [bug] JAVA-1232: Fix NPE in IdempotenceAwareRetryPolicy.isIdempotent.
18+
- [improvement] JAVA-1227: Document "SELECT *" issue with prepared statement.
1819

1920

2021
### 3.0.2

faq/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ session.execute(batch);
8888
```
8989

9090

91+
### Why do my 'SELECT *' `PreparedStatement`-based queries stop working after a schema change?
92+
93+
Both the driver and Cassandra maintain a mapping of `PreparedStatement` queries to their
94+
metadata. When a change is made to a table, such as a column being added or dropped, there
95+
is currently no mechanism for Cassandra to invalidate the existing metadata. Because of this,
96+
the driver is not able to properly react to these changes and will improperly read rows after
97+
a schema change is made.
98+
99+
See [Prepared statements](../manual/statements/prepared) for more information.
100+
101+
91102
### Can I get the raw bytes of a text column?
92103

93104
If you need to access the raw bytes of a text column, call the

manual/statements/prepared/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,27 @@ Changing the driver's defaults should be done with care and only in
241241
specific situations; read each method's Javadoc for detailed
242242
explanations.
243243
244+
### Avoid preparing 'SELECT *' queries
245+
246+
Both the driver and Cassandra maintain a mapping of `PreparedStatement` queries to their
247+
metadata. When a change is made to a table, such as a column being added or dropped, there
248+
is currently no mechanism for Cassandra to invalidate the existing metadata. Because of this,
249+
the driver is not able to properly react to these changes and will improperly read rows after
250+
a schema change is made.
251+
252+
Therefore it is currently recommended to not create prepared statements
253+
for 'SELECT *' queries if you plan on making schema changes involving
254+
adding or dropping columns. Alternatively you should list all columns of interest
255+
in your statement, i.e.: `SELECT a, b, c FROM tbl`.
256+
257+
This will be addressed in a future release of both Cassandra and the driver. Follow
258+
[CASSANDRA-10786] and [JAVA-1196] for more information.
259+
244260
[PreparedStatement]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/PreparedStatement.html
245261
[BoundStatement]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/BoundStatement.html
246262
[setPrepareOnAllHosts]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/QueryOptions.html#setPrepareOnAllHosts-boolean-
247263
[setReprepareOnUp]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/QueryOptions.html#setReprepareOnUp-boolean-
248264
[execute]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/Session.html#execute-com.datastax.driver.core.Statement-
249265
[executeAsync]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/Session.html#executeAsync-com.datastax.driver.core.Statement-
266+
[CASSANDRA-10786]: https://issues.apache.org/jira/browse/CASSANDRA-10786
267+
[JAVA-1196]: https://datastax-oss.atlassian.net/browse/JAVA-1196

0 commit comments

Comments
 (0)