0

我是卡桑德拉的新手。我有一个带有复合主键的表。表的描述是

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使用条件和id范围条件以及severity条件来查询表

所以当我尝试以下查询时

select * from testtable where foid in (5,6) and id>10 and severity in (5);

我收到错误消息

select * from testtable where foid in (5,6) and id>10 and severity in (5);

甚至severity列上的相等条件对我来说就足够了,但这也行不通。

有什么方法可以实现相同的

我也尝试过使用二级索引,但这severitycategory没有给我带来任何积极的影响。

4

1 回答 1

1

您需要连续限制主键,因此以下将起作用:

select * from testtable where foid in (1) and id=2 and severity<20 ;

但这不会:

select * from testtable where foid in (1) and id>10 and severity=3;

如何使查询的限制更少(正如您在问题中所建议的那样),如下所示

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,上的 IN 操作severity不起作用):

select * from testtable2 where foid in (5,6) and severity=5 and id>10;

(使用 cql 测试 [cqlsh 4.0.1 | Cassandra 2.0.1 | CQL 规范 3.1.1 | Thrift 协议 19.37.0])

于 2013-10-17T11:18:39.060 回答