CREATE TABLE test (
type text,
scope text,
name text,
version text,
alias text,
deleted boolean,
PRIMARY KEY ((type, scope, name), version)
) WITH read_repair_chance = 0.0
AND dclocal_read_repair_chance = 0.1
AND gc_grace_seconds = 864000
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', 'min_threshold' : 4, 'max_threshold' : 32 }
AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.LZ4Compressor' }
AND default_time_to_live = 0
AND speculative_retry = '99.0PERCENTILE'
AND min_index_interval = 128
AND max_index_interval = 2048;
CREATE INDEX test_alias ON test (alias);
CREATE INDEX test_type_index ON test (type);
此選擇不起作用:與低基數列選擇:在受限的列中沒有二級索引支持爲運營商提供
select *
from test
where type = 'type'
and scope='scope'
and name='name'
and deleted = false
allow filtering;
,給我:
No secondary indexes on the restricted columns support the provided operators: com.datastax.driver.core.exceptions.InvalidQueryException: No secondary indexes on the restricted columns support the provided operators.
此選擇作品:
select *
from test
where type = 'type'
and scope='scope'
and deleted = false
allow filtering;
這種選擇也適用:
select *
from test
where type = 'type'
and scope='scope'
and name='name'
allow filtering;
這種選擇也適用:
select *
from test
where type = 'type'
and scope='scope'
and name='name'
and version='version'
allow filtering;
任何想法?我不想在低基數列上創建索引,但我不明白爲什麼在某些情況下該查詢有效(當我通過主鍵和附加字段刪除兩個字段進行篩選時)。
卡桑德拉版本:2.1.14
如果我的理解是正確的,有沒有可能在查詢中使用條件與複合分區鍵和其他領域內的共同所有的鍵。但我沒有找到任何解釋......
你的cassandra版本是什麼? –
專業提示:需要允許篩選和/或二級索引的查詢不會擴展。構建您的表以適應您的查詢,並且此問題消失。 – Aaron
Cassandra版本:2.1.14 –