cassandra - 错误请求 : No indexed columns present in by-columns clause with Equal operator : CQL error?

标签 cassandra cql cql3

我在 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.

我在这里做错了什么吗?

我的用例一般是 -
  • 给我任何employee_name的一切?
  • 告诉我过去 5 分钟内发生了什么变化的所有信息?
  • 给我任何employee_name 的最新employee_id 和值?
  • 给我任何employee_name 的所有employee_id?

  • 我正在运行 Cassandra 1.2.11

    最佳答案

    一般规则很简单:“您只能按属于键的列进行查询”。作为解释,所有其他查询都需要对表进行完整扫描,这可能意味着要进行大量数据筛选。

    有一些事情可以修改这个规则:

  • 对基数较低的列使用二级索引(更多详细信息 here)
  • 定义多列键(例如 PRIMARY KEY (col1, col2) ;这将允许像 col1 = value1col1 = value1 and col2 COND 之类的查询)
  • 使用 ALLOW FILTERING在查询中。这将导致警告,因为 Cassandra 将不得不筛选大量数据并且没有性能保证。更多详情请见details of ALLOW FILTERING in CQLthis SO thread
  • 关于cassandra - 错误请求 : No indexed columns present in by-columns clause with Equal operator : CQL error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19756368/

    相关文章:

    cassandra - WSO2 BAM 数据库,而不是 Cassandra

    cassandra - 在 Cassandra 中为 map 中的元素选择 TTL

    cassandra - Cassandra 表中的多列

    cassandra - 了解 cassandra 的内部数据存储

    java - 无法使用 Scala 从 Cassandra DB 的原始数据类型映射读取数据

    cassandra - 带有 SELECT LIMIT 1 的墓碑警告

    cassandra - 如何将csv文件导入cassandra

    java - Kundera for Cassandra - 按行键删除记录

    java - 复合键的 Cassandra CQL 分页

    java - com.datastax.driver.core.exceptions.InvalidQueryException 使用 Datastax Java 驱动程序