Skip to content

Feature Request: Generate SELECT statements with explicit columns instead of SELECT * #1590

@Neldering

Description

@Neldering

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions