首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring-data-cassandra: InvalidQueryException:无法执行此查询...使用允许筛选

spring-data-cassandra: InvalidQueryException:无法执行此查询...使用允许筛选
EN

Stack Overflow用户
提问于 2017-10-04 23:23:00
回答 2查看 2.3K关注 0票数 2

我有以下代码

代码语言:javascript
复制
  @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中执行相同的查询,它可以工作。

EN

回答 2

Stack Overflow用户

发布于 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

票数 3
EN

Stack Overflow用户

发布于 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

代码语言:javascript
复制
@Query(value = "select * from customers where code = ?0", allowFiltering = true)
Optional<Customer> findOneByCode(String code);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46568533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档