【问题标题】:Why DELETE query with yb_hash_code() degrades performance in YugabyteDB?为什么使用 yb_hash_code() 的 DELETE 查询会降低 YugabyteDB 的性能?
【发布时间】: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是写操作,所以,查询计划包括:

  1. 为给定的 WHERE 子句查找分片。
  2. 在分片领导上执行查询
  3. 复制分片追随者的更改
  4. 回复客户

WHERE 子句中的yb_hash_code() 应该避免第 1 步,这样对吗?

为什么查询 2 的执行速度比查询 1 快?尽管查询 1 使用 yb_hash_code()

【问题讨论】:

    标签: yugabytedb


    【解决方案1】:

    这里,因为item_id是主键,YugabyteDB确定了正确的平板电脑,所以你不需要用哈希码过滤。

    但是你是对的,添加标准不应该增加更多的工作。执行计划显示。我的猜测是,您看到 Rows Removed by Index Recheck 大约有 1/48 的行。这意味着当在 hash_code 上有谓词时,另一个谓词没有被下推。

    这里有个问题:https://github.com/yugabyte/yugabyte-db/issues/12094

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2022-07-19
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      相关资源
      最近更新 更多