我有以下代码
@Indexed
@PrimaryKeyColumn(name = "x", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
@Column(value="x")
private String x;
@Indexed
@PrimaryKeyColumn(name = "code", ordinal = 2, type = PrimaryKeyType.PARTITIONED)
@Column(value="code")
private String code;
@Query(value = "select * from customers where code = ?0")
Optional<Customer> findByCode(String code);当这段代码被执行时,我会得到Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING。
有没有一种方法可以仅仅通过spring-data-cassandra来避免这种情况?我不想在查询中添加ALLOW FILTERING。我尝试在code列上创建一个单独的索引,但是没有解决这个问题。我认为它停留在spring数据配置上。如果我在cqlsh中执行相同的查询,它可以工作。
发布于 2017-10-04 23:29:30
除非创建索引或使用ALLOW FILTERING,否则必须在查询上指定分区键
使用允许过滤执行查询可能不是一个好主意,因为它可能会占用大量计算资源,并且可能因为超时而不返回任何结果。不要在生产环境中使用允许筛选请阅读有关使用允许筛选的datastax文档
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter
发布于 2020-02-05 15:41:02
在使用非sql数据库时,您需要正确设计数据以避免过滤。您可以添加辅助索引来优化特定字段的检索。更多详细信息请访问:https://docs.datastax.com/en/archived/cql/3.3/cql/cql_using/useSecondaryIndex.html
如果您确定查询是您需要的,那么您可以在@Query注释上使用allowFiltering参数来显式地指示使用ALLOW FILTERING。
@Query(value = "select * from customers where code = ?0", allowFiltering = true)
Optional<Customer> findOneByCode(String code);https://stackoverflow.com/questions/46568533
复制相似问题