【问题标题】:Cassandra Select query returns allow filtering even if the column is in primary key即使列在主键中,Cassandra Select 查询返回也允许过滤
【发布时间】:2020-12-01 18:58:02
【问题描述】:

我创建了一个类似这样的订单表

create_query1 = CREATE TABLE IF NOT EXISTS orders
    (status text, city text, company text, country_id text, created_at timestamp,
    customer_address_id text, customer_id text, discount_amount float, discount_invoiced float, email text,
    entity_id text, firstname text, free_shipping float, grand_total_final float, is_qty_decimal float,
    is_virtual text, item_id text, lastname text, method text, name text, no_discount float,order_id text,
    original_price float, parent_id text, postcode text, price float, price_incl_tax float,
    product_id text, product_type text, qty_ordered float, qty_shipped float, quote_item_id text,PRIMARY KEY ((order_id), created_at ))

当我查询类似的东西时

SELECT * from orders where created_at >= '2019-01-31 20:55:43' and created_at <= '2019-05-13 13:58:15'

我收到此错误

Error from server: code=2200 [Invalid query] message="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"

我在这里做错了什么? Cassandra 不适合这种类型的查询吗?

【问题讨论】:

    标签: select cassandra primary-key cql


    【解决方案1】:

    查询看起来正确,但您在查询中使用的表名与您创建的表名不同。

    【讨论】:

    • Opps 抱歉,复制了 wring 查询,我在同一张表上应用了查询
    • 你在查询中是否提到了id?没有id,它需要允许过滤,因为它是分区键
    • 不,我没有提到id,我想根据日期检索所有订单,这样做的投注方式是什么?
    • 如果表比较小,可以在上面的查询后面加上ALLOW FILTERING,这样就可以了。否则,您需要更改主键。您可以创建另一列,该列仅存储订单的月份和年份,例如 09-2020。将其替换为主键中的 order_id 并将此列包含在查询的 where 子句中。因此您的主键应该看起来像主键((newColumn ),orderid,createdat)
    • 但是一个月内会有很多订单,因为主键应该是唯一的,那不影响吗?
    猜你喜欢
    • 1970-01-01
    • 2018-11-24
    • 2021-09-10
    • 2020-07-19
    • 2018-09-18
    • 1970-01-01
    • 2017-07-23
    • 2019-01-13
    • 2018-08-31
    相关资源
    最近更新 更多