为什么CQL建议我在更新时使用ALLOW FILTERING?

时间:2019-05-05 05:00:32

标签: cql

我的简单更新查询抛出以下错误。

InvalidRequest: Error from server: code=220 [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"

据我所知,ALLOW FILTERING添加了索引,它通常用于SELECT查询。我试图了解此错误背后的原因。但是找不到任何东西。另外,我刚刚开始学习CQL,对我来说,很少有新概念。

这是我的表的架构:

CREATE TABLE blogplatform.users (
    user_id int PRIMARY KEY,
    active_status int,
    password text,
    user_name text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
    AND comment = ''
    AND compaction = {'class': 'SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';

我要执行的查询:

UPDATE users SET active_status = 0 WHERE user_name='Heath';

输出:

InvalidRequest: Error from server: code=220 [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"

我什至尝试在查询中添加ALLOW FILTERING:

UPDATE users SET active_status = 0 WHERE user_name='Heath' ALLOW FILTERING;

输出:

SyntaxException: line 1:59  : syntax error...

有人可以解释一下为什么我在简单更新时遇到此错误。另外,任何人都可以指导我解决此错误。

谢谢。

1 个答案:

答案 0 :(得分:1)

您不能在where子句中使用值列(没有允许过滤,但再次允许过滤不是一个神奇的词,它只会给数据库增加很多负担)-这适用于所有类型的查询,而不仅仅是选择查询。

更好的选择是将用户名作为主键(PARTITION KEY)。

使用该表,您可以执行类似的查询。

UPDATE users SET active_status = 0 WHERE user_name='Heath';