Cassandra Range Search on Secondary Index with Allow Filtering

↘锁芯ラ 提交于 2019-12-13 20:05:59

问题


I'm playing with Cassandra 3. I added a secondary index on a column of integer, then I want to do a range query. First it threw an error:

InvalidRequest: code=2200 [Invalid query] message="No supported secondary index found for the non primary key columns restrictions"

So I added 'Allow Filtering'

cqlsh:mykeyspace> SELECT * FROM test ;

id | id2 | age | extra
----+-----+-----+-------
  1 |   1 |   1 |     1
  2 |   2 |   2 |     2

(2 rows)
cqlsh:mykeyspace > CREATE INDEX test_age on test (extra) ;
cqlsh:mykeyspace > select * FROM test WHERE extra < 2 ALLOW FILTERING ;

 id | id2  | age | extra
----+------+-----+-------
  1 |    1 |   1 |     1
  2 | null |   2 |  null

(2 rows)

Why would this happen? Is this by design or is it a bug?


回答1:


With Cassandra 3.0+, you'll want to investigate Materialized Views - they're designed to be a more functional version of secondary indexes, working around most of the traditional downfalls.

You almost never want to use traditional secondary indexes in high-read production environments, and ALLOW FILTERING is generally awful.




回答2:


The answer is that Secondary Indexes are a bit of an anti-pattern. They do not behave like Indexes in an RDBMS and are there mostly to support analytics requests. They essentially require all nodes to be queried and have much different response characteristics than normal Cassandra partition key lookups. To dissuade their casual use, "ALLOW FILTERING" was added to make sure that the user would know that they are not doing a normal C* lookup.



来源:https://stackoverflow.com/questions/34540883/cassandra-range-search-on-secondary-index-with-allow-filtering

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!