-
Notifications
You must be signed in to change notification settings - Fork 311
Description
Summary:
Spring Data Cassandra's CassandraQueryCreator currently generates SELECT * queries by default. This can lead to performance issues and make applications more vulnerable to schema changes, especially when working with wide tables or older versions of Cassandra or its driver that lack robust schema handling.
Problem Statement:
Using SELECT * in generated queries causes the following issues:
-
Query execution and deserialization are slower
-
Schema changes (e.g., adding new columns) may introduce bugs or unexpected behavior
-
Older Cassandra drivers (prior to 4.x) are less tolerant of schema drift
Proposed Solution:
Update CassandraQueryCreator to generate queries with explicitly listed columns based on the entity’s mapped fields. The framework already has access to this metadata via the mapping context.
Optionally, this behavior could be toggled via a configuration property, such as:
spring.data.cassandra.query.explicit-columns=true
Benefits:
-
Reduced query execution time and network I/O
-
Increased stability in environments with schema changes
-
Better compatibility with older Cassandra versions and drivers
-
Follows best practices for Cassandra query design
Environment:
-
Spring Data Cassandra: 4.1.x
-
Cassandra: 3.x / 4.x
-
Cassandra Java Driver: 4.14 and earlier
Affected class: org.springframework.data.cassandra.repository.query.CassandraQueryCreator
Related:
While Spring Data 4.x offers improved schema handling, this change would benefit users on legacy stacks or where upgrading the Cassandra driver is not feasible.