【问题标题】:Cassandra select query failureCassandra 选择查询失败
【发布时间】:2019-02-14 12:47:02
【问题描述】:

我们有一张桌子:

CREATE TABLE table (
    col1 text,
    col2 text,
    col3 timestamp,
    cl4 int,
    col5 timestamp,
    PRIMARY KEY (col1, col2, col3, col4)
) WITH CLUSTERING ORDER BY (col2 DESC, col3 DESC,col4 DESC) 

当我尝试从这个表中查询时:

select * from table where col1 = 'something' and col3 < 'something' 
  and col4= 12 limit 5 ALLOW FILTERING;
select * from table where col1 = 'something' and col4 < 23 
  and col3 >= 'something' ALLOW FILTERING;

我总是得到错误:Clustering column "col4" cannot be restricted (preceding column "col3" is restricted by a non-EQ relation)

我尝试通过创建 col4、col3、col2 来更改表创建,但第二个查询不起作用并引发类似错误。
解决此问题的任何建议/建议。

我们正在:Cassandra 3.0.17.7。

【问题讨论】:

  • 请阅读 - ClusteringColumns
  • 如果您的查询不打算使用col2,那么为什么要将它作为集群列呢?将其从您的 PRIMARY KEY def 中取出(或使其成为最后一个聚类列),然后您就不需要 ALLOW FILTERING

标签: cassandra cassandra-3.0


【解决方案1】:

您只能在查询分区的最后一列使用不等式条件。

例如,您可以使用col1 = val and col2 &lt;= ...col1 = val and col2 = val2 and col3 &lt;= ...col1 = val and col2 = val2 and col3 = val3 and col4 &lt;= ...,但您不能对多个列执行不相等条件 - 这就是 Cassandra 读取数据的方式。

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 2017-08-22
    • 1970-01-01
    • 2016-05-18
    • 1970-01-01
    • 2017-03-30
    • 2017-03-12
    • 2016-08-28
    • 1970-01-01
    相关资源
    最近更新 更多