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

Why CQL is suggesting me to use ALLOW FILTERING on update?

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

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,一些概念对我来说是新的。

这是我的 table 的架构:

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

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

谢谢。

您不能在 where 子句中使用值列(不允许过滤,但再次允许过滤不是一个神奇的词,它只会给数据库带来大量负载)- 这适用于所有类型的查询和不只是 Select 个查询。

对您来说更好的选择是移动 user_name 作为主键(分区键)。

有了它 table 你可以执行这样的查询。

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