cassandra ALLOW FILTER 的工作原理

本文详细探讨了Cassandra数据库中ALLOW FILTERING的工作原理,包括其在查询优化、数据分布和性能影响等方面的关键点。通过对实际案例的分析,揭示了如何恰当使用这一特性以避免潜在问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建一下一个table: 

CREATE TABLE ruling_stewards (
  steward_name text,
  king text,
  reign_start int,
  event text,
  PRIMARY KEY (steward_name, king, reign_start)
);
当用
SELECT * FROM ruling_stewards
  WHERE king = 'none'
  AND reign_start >= 1500
  AND reign_start < 3000 LIMIT 10 ALLOW FILTERING;
时,会报错误: 

Bad Request: 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, 为啥呢 ?官方的解释是:
ALLOW FILTERING will probably become less strict as we collect more statistics on our data. For example, if we knew that 90% of entries have no king we would know that finding 10 such entries should be relatively inexpensive.
加了ALLOW FILTERING 后,cassandra会根据已经创建好的统计表,查询那些NODE 上最有可能有king这个cluster, 然后到最有可能的node上去找满足条件的entries。 如果没有加ALLOW FILTERING , 那就是盲找,这个查询代价非常高。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值