spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
379 stars 311 forks source link

Apply query options as bind markers to avoid new `PreparedStatement` creation #1401

Closed chringwer closed 1 year ago

chringwer commented 1 year ago

There is an overloaded version of UpdateStart usingTimestamp(@NonNull BindMarker bindMarker) that should probably be used here in order to avoid having a new prepared statement to be created for each timestamp.

https://github.com/spring-projects/spring-data-cassandra/blob/e950084f993edea049c9dbd540515bd686b6066d/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/QueryOptionsUtil.java#L171

I was alerted by warnings logged from the cassandra nodes like: 157 prepared statements discarded in the last minute because cache limit reached (10 MB)

Verified that this is due to the timestamp not being specified as a BindMarker but as a literal value. This can be observed by inspecting the output of select * from system.prepared_statements ;.

mp911de commented 1 year ago

Thanks for bringing this up. I agree that in the context of prepared statements, this behavior could be better. QueryOptionsUtil isn't aware of whether the statement is being used with bind markers and how values are bound to these. That being said, such a change requires a bit more thought to find a way for a generic approach, similar to StatementBuilder.