【发布时间】:2022-07-19 00:17:39
【问题描述】:
[用户在YugabyteDB Community Slack上发布的问题]
对于给定的以下架构:
CREATE TABLE IF NOT EXISTS public.item_data
(
item_id uuid NOT NULL,
id2 integer NOT NULL,
create_date timestamp without time zone NOT NULL,
modified_date timestamp without time zone NOT NULL,
CONSTRAINT item_data_pkey PRIMARY KEY (item_id, id2)
);
我们在 yugabyte 设置中有 48 个平板电脑。所以,第一个哈希范围是 [0, 1395)
DELETE 查询的执行时间如下:
查询 1(使用 yb_hash_code()):
EXPLAIN ANALYZE DELETE FROM item_data x WHERE yb_hash_code(x.item_id)>=0 and yb_hash_code(x.item_id)<1395 and x.item_id = any in the arrayOfItemIds - taking 2 seconds of execution time
查询 2:
EXPLAIN ANALYZE DELETE FROM item_data x WHERE x.item_id = any in the listOfItemIds - taking 2 milli seconds of execution time
DELETE是写操作,所以,查询计划包括:
- 为给定的 WHERE 子句查找分片。
- 在分片领导上执行查询
- 复制分片追随者的更改
- 回复客户
WHERE 子句中的yb_hash_code() 应该避免第 1 步,这样对吗?
为什么查询 2 的执行速度比查询 1 快?尽管查询 1 使用 yb_hash_code()
【问题讨论】:
标签: yugabytedb