在rowkey和集群列中具有in条件的cassandra cql查询

在rowkey和集群列中具有in条件的cassandra cql查询,cassandra,cql,Cassandra,Cql,我是卡桑德拉的新手。我有一个带有复合主键的表。表的说明如下所示 CREATE TABLE testtable ( foid bigint, id bigint, severity int, category int, ack boolean, PRIMARY KEY (foid, id, severity, category) ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND

我是卡桑德拉的新手。我有一个带有复合主键的表。表的说明如下所示

CREATE TABLE testtable (
  foid bigint,
  id bigint,
  severity int,
  category int,
  ack boolean,
  PRIMARY KEY (foid, id, severity, category)
) WITH
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='NONE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};
我的要求是,我需要查询带有
foid
with in条件和
id
with range条件和
severity
with in条件的表

所以当我尝试下面的查询时

select * from testtable where foid in (5,6) and id>10 and severity in (5);
我收到的错误消息是

从测试表中选择*,其中foid在(5,6)中,id>10,严重性在(5)中

或者,即使是
严重性
列上的同等条件对我来说也足够了,这也不起作用

有没有办法做到这一点


我也尝试了
严重性
类别
的二级索引,但没有给我任何积极的信息。

您需要依次限制主键,因此以下操作将起作用:

select * from testtable where foid in (1) and id=2 and severity<20 ;
让查询变得不那么严格(如您在问题中所建议的)怎么样

select * from testtable where foid in (5,6) and id>10
在客户端对结果进行排序

另一种(可能更具吸引力的)解决方案是根据执行查询的方式对密钥进行排序,例如

CREATE TABLE testtable2 (
  foid bigint,
  severity int,
  id bigint,
  category int,
  ack boolean,
  PRIMARY KEY (foid, severity, id, category)
)
允许您这样进行查询(请注意,
severity
上的相等操作,
severity
上的IN操作将不起作用):


(使用cql[cqlsh 4.0.1 | Cassandra 2.0.1 | cql规范3.1.1 |节俭协议19.37.0]进行测试)

我也想到了与您描述的相同的场景。最后一个解决方案本身也适用于某些场景。因为过滤的严重性列的包含是根据需要进行的,并且是动态的。在某些情况下,我不会使用严重性列。如你所说,我正在尝试执行查询,限制foid和id,并在客户端进行排序,以进行剩余过滤
CREATE TABLE testtable2 (
  foid bigint,
  severity int,
  id bigint,
  category int,
  ack boolean,
  PRIMARY KEY (foid, severity, id, category)
)
select * from testtable2 where foid in (5,6) and severity=5 and id>10;