Cassandra中不可预测的结果错误

时间:2015-03-27 07:27:03

标签: cassandra

我是Cassandra的新手,我在索引方面遇到了一些错误。我在下面运行了一个查询来展示我的所作所为:

cqlsh> SELECT column_name, index_name, index_options, index_type,   component_index  FROM system.schema_columns  WHERE keyspace_name='casslink'AND columnfamily_name='mylink_all';

 column_name | index_name | index_options | index_type | component_index
 crawled |     mylink_all_crawledIndex | {} | COMPOSITES |   0
 detailpage |  mylink_all_detailIndex |   {} | COMPOSITES |  0
 linkurl |  null |   null |    null |   null

设计是linkurl是主键,并且爬网是真/假字段(0/1),detailPage是一种页面类型的分类器。数据已创建,当我尝试使用AND运行查询时,我会看到一条警告:

cqlsh> select linkurl from casslink.mylink_all 
   ... where crawled=1 
   ... and detailpage = 0 limit 10;

Bad Request: Cannot execute this query as it might involve data filtering and
thus may have unpredictable performance. If you want to execute this query despite the 
performance unpredictability, use ALLOW FILTERING

我认为这基本上是一个错误。我只想根据crawled = 1和detailpage = 0选择记录。在较旧的SQL类型的数据库中,这是相当标准的。但这似乎在卡桑德拉引起了一个问题。

在这个例子中有没有更好的索引和选择方法?

2 个答案:

答案 0 :(得分:0)

您正在对不是分区键的列执行选择。它是一个索引列,但据我所知,它只有2个潜在值,而索引或分区键没有。 在这种情况下,我建议添加另一个表格,该表格仅包含已抓取的链接并从中进行选择。

至于你在SQL类型的数据库中做的标准,Cassandra不是一个,数据建模和查询规则是非常不同的,其中一些是:

  • 查询模型,而不是数据
  • 可以反规范化
  • 索引不是 快

这里有一篇关于Cassandra数据建模的好的入门文章:https://www.datastax.com/documentation/cql/3.1/cql/ddl/ddl_music_service_c.html

答案 1 :(得分:0)

我最后做的是将两个值连接到一个字段中,因此一个字段现在有4个值。这似乎有效。