我在 CQL 中有下表-
create table test (
employee_id text,
employee_name text,
value text,
last_modified_date timeuuid,
primary key (employee_id)
);
我像这样在上表中插入了几条记录,我将在我们的实际用例场景中插入这些记录-
insert into test (employee_id, employee_name, value, last_modified_date) values ('1', 'e27', 'some_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('2', 'e27', 'some_new_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('3', 'e27', 'some_again_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('4', 'e28', 'some_values', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('5', 'e28', 'some_new_values', now());
现在我正在做选择查询 - 给我所有的employee_id 为employee_name
e27
.select employee_id from test where employee_name = 'e27';
这是我得到的错误 -
Bad Request: No indexed columns present in by-columns clause with Equal operator
Perhaps you meant to use CQL 2? Try using the -2 option when starting cqlsh.
我在这里做错了什么吗?
我的用例一般是 -
我正在运行 Cassandra 1.2.11
最佳答案
一般规则很简单:“您只能按属于键的列进行查询”。作为解释,所有其他查询都需要对表进行完整扫描,这可能意味着要进行大量数据筛选。
有一些事情可以修改这个规则:
PRIMARY KEY (col1, col2)
;这将允许像 col1 = value1
和 col1 = value1 and col2 COND
之类的查询)ALLOW FILTERING
在查询中。这将导致警告,因为 Cassandra 将不得不筛选大量数据并且没有性能保证。更多详情请见details of ALLOW FILTERING in CQL和 this SO thread 关于cassandra - 错误请求 : No indexed columns present in by-columns clause with Equal operator : CQL error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756368/