gpt4 book ai didi

scylla - 为什么键前缀优化不适用于聚集列上的二级索引?

转载 作者:行者123 更新时间:2023-12-02 06:22:25 27 4
gpt4 key购买 nike

Scylla DB 为二级索引实现了所谓的“key prefix optimization ”,如果指定了主键的一部分,则可以消除过滤。例如。可以在表 A 上执行 SELECT * FROM A WHERE a = 'a' AND b = 'a' AND d = 'a';

CREATE TABLE A (
a text,
b text,
c text,
d text,
PRIMARY KEY(a,b,c)
);
CREATE INDEX A_index ON A (d);

但是如果A.d是一个聚类列,它就不起作用。例如。如下表B所示。

CREATE TABLE B (
a text,
b text,
c text,
d text,
PRIMARY KEY(a,b,c,d)
);
CREATE INDEX B_index ON B (d);

上面的 SELECT 查询失败并出现错误:

InvalidRequest: 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"

ScyllaDB 3.0.1。

最佳答案

感谢您找到一个有趣的极端案例:)

问题在于第二个查询限制了聚类列(b, d),它本身并不形成聚类键前缀。当然,d 已建立索引,因此应该发生的是在键前缀优化中使用 a 并使用 d 作为索引列。

相反,它错误地判定 (b, d) 不形成前缀,因此将其从优化候选中丢弃,而不考虑 d 有索引.

这种简化将得到修复,我在这里创建了一个错误跟踪器问题:https://github.com/scylladb/scylla/issues/4178

关于scylla - 为什么键前缀优化不适用于聚集列上的二级索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54463049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com