弹簧数据卡桑德拉:InvalidQueryException:不能执行这个查询使用...允许过滤的
问题描述:
我有以下代码弹簧数据卡桑德拉:InvalidQueryException:不能执行这个查询使用...允许过滤的
@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
列上创建一个单独的索引,但这并没有解决问题。我认为它停止在春季数据配置。如果我在cqlsh
中执行相同的查询,它将起作用。
答
您必须对您的查询指定分区键,除非你创建索引或使用允许过滤的
执行的查询与允许过滤可能不是一个好主意,因为它可以使用大量的计算资源,并可能由于超时而不返回任何结果。不要在生产中使用允许过滤阅读有关使用允许过滤的datastax文档
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter