Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在cql中使用select和where时出现cassandra错误_Cassandra_Cql_Cqlsh - Fatal编程技术网

在cql中使用select和where时出现cassandra错误

在cql中使用select和where时出现cassandra错误,cassandra,cql,cqlsh,Cassandra,Cql,Cqlsh,我有一个cassandra表,定义如下: CREATE TABLE test.test( id text, time bigint, tag text, mstatus boolean, lonumb int, PRIMARY KEY (id, time, tag) ) 我想使用select选择一列。 我试过: 它给出: code=2200 [Invalid query] message="No indexed columns present in by-columns clause wit

我有一个
cassandra
表,定义如下:

CREATE TABLE test.test(
id text,
time bigint,
tag text,
mstatus boolean,
lonumb  int,
PRIMARY KEY (id, time, tag)
)
我想使用
select
选择一列。 我试过:

它给出:

code=2200 [Invalid query] message="No indexed columns present in by-columns clause with Equal operator"
我也做不到

select * from test where mstatus = true;

作为CQL的一部分,
cassandra
是否支持
where
?如何更正此问题?

您只能在索引列或主键列上使用
WHERE
。要纠正您的问题,您需要创建一个索引

CREATE INDEX iname 
ON keyspacename.tablename(columname)
您可以查看更多信息

但是您必须记住,这个查询必须针对集群中的所有节点运行


或者,如果您将对
lonumb
进行最多的查询,您可能会重新考虑您的表结构。

Jny是正确的,因为
中的
仅对主键中的列有效,或者对已创建辅助索引的列有效。解决此问题的一种方法是为
lonumb
查询创建特定的查询表

CREATE TABLE test.testbylonumb(
  id text,
  time bigint,
  tag text,
  mstatus boolean,
  lonumb  int,
  PRIMARY KEY (lonumb, time, id)
)
现在,此查询将起作用:

select * from testbylonumb where lonumb = 4231; 
它将返回所有CQL行,其中
lonumb
=4231,按
时间排序。我将
id
放在主键上以确保唯一性

select * from test where mstatus = true;
这个比较棘手。低基数列(如布尔)上的索引和键通常被认为是个坏主意。看看是否有其他方法可以为其建模。否则,您可以在
mstatus
上试验二级索引,但仅在指定分区键时使用它(在本例中为
lonumb
),如下所示:

select * from testbylonumb where lonumb = 4231 AND mstatus = true;

也许这不会太糟糕,因为您将它限制在特定的分区内。但我绝对不会在
mstatus

上做
SELECT*
,我通常不喜欢二级索引。但是,如果在同时指定了分区键的查询中使用索引,情况可能不会太糟+1.
select * from testbylonumb where lonumb = 4231 AND mstatus = true;