und*_*ble 5 cassandra cql3 cassandra-2.0
我正在使用cassandra 2.1.10.所以首先我要清楚我知道二级索引是cassandra中的反模式.但是出于测试目的,我试图遵循:
CREATE TABLE test_topology1.tt (
a text PRIMARY KEY,
b timestamp
) WITH 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'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
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 = '99.0PERCENTILE';
CREATE INDEX idx_tt ON test_topology1.tt (b);
Run Code Online (Sandbox Code Playgroud)
当我运行以下查询时,它给了我错误.
cqlsh:test_topology1> Select * from tt where b>='2016-04-29 18:00:00' ALLOW FILTERING;
InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'b >= <value>'"
Run Code Online (Sandbox Code Playgroud)
虽然这个Blog说允许过滤可以用来查询二级索引.Cassandra安装在Windows机器上.
Cassandra 2.2.x 及之前版本不允许对二级索引列进行范围查询。然而,正如文章《深入了解 CQL WHERE 子句》所指出的那样,如果允许过滤,则在非索引列上允许使用它们:
二级索引直接查询仅支持 =、CONTAINS 或 CONTAINS KEY 限制。
[..]
二级索引查询允许您使用 =、>、>=、<= 和 <、使用过滤对非索引列进行 CONTAINS 和 CONTAINS KEY 限制来限制返回的结果。
因此,给定表结构和索引
CREATE TABLE test_secondary_index (
a text PRIMARY KEY,
b timestamp,
c timestamp
);
CREATE INDEX idx_inequality_test ON test_secondary_index (b);
Run Code Online (Sandbox Code Playgroud)
以下查询失败,因为不等式测试是在索引列上完成的:
SELECT * FROM test_secondary_index WHERE b >= '2016-04-29 18:00:00' ALLOW FILTERING ;
InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'b >= <value>'"
Run Code Online (Sandbox Code Playgroud)
但以下方法有效,因为不等式测试是在非索引列上完成的:
SELECT * FROM test_secondary_index WHERE b = '2016-04-29 18:00:00' AND c >= '2016-04-29 18:00:00' ALLOW FILTERING ;
a | b | c
---+---+---
(0 rows)
Run Code Online (Sandbox Code Playgroud)
如果您在 column 上添加另一个索引c,这仍然有效,但仍然需要该ALLOW FILTERING术语,这对我来说意味着在这种情况下不使用列 c 上的索引。
| 归档时间: |
|
| 查看次数: |
4364 次 |
| 最近记录: |