【发布时间】:2016-09-07 04:32:48
【问题描述】:
我使用 Cassandra 3.0.5。
我在同时使用 ORDER BY 和 IN 时遇到问题。
架构:
CREATE TABLE my_status.user_status_updates (
username text,
id timeuuid,
body text,
PRIMARY KEY (username, id))
WITH CLUSTERING ORDER BY (id ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
查询:
SELECT username, id, UNIXTIMESTAMPOF(id), body
FROM user_status_updates
WHERE username IN ('carol', 'dave')
ORDER BY id DESC
LIMIT 2;
InvalidRequest: code=2200 [Invalid query] message="不能对同时使用 ORDER BY 和 IN 限制的分区键的查询进行分页;您必须删除 ORDER BY 或 IN 并对客户端进行排序,或者禁用分页这个查询”
我确信我已经看到有人在没有错误的情况下查询此问题,所以我知道有办法解决这个问题。我需要做什么才能使此查询正常工作,还是同时查询 ORDER BY 和 IN 效率低?
【问题讨论】:
-
架构看起来如何?
-
由于您只要求返回 2 行,因此删除查询中的
ORDER BY子句似乎是一种快速的解决方法。 -
“学习 Apache Cassandra 第二版”一书中的确切查询存在此问题。书中没有提到任何错误或必须关闭分页。我已将此问题提交到 packt publishing 的勘误表中。
标签: cassandra