【问题标题】:Using yb_hash_code in select query in YugabyteDB在 YugabyteDB 的选择查询中使用 yb_hash_code
【发布时间】:2022-07-19 00:20:10
【问题描述】:

[用户在YugabyteDB Community Slack上发布的问题]

对于下面给出的架构:

CREATE TABLE IF NOT EXISTS public.table1(
customer_id uuid NOT NULL ,

item_id uuid NOT NULL ,

kind character varying(100) NOT NULL ,

details character varying(100) NOT NULL ,
created_date timestamp without time zone NOT NULL,
modified_date timestamp without time zone NOT NULL,

CONSTRAINT table1_pkey PRIMARY KEY (customer_id, kind, item_id)

);

CREATE UNIQUE INDEX IF NOT EXISTS unique_item_id ON table1(item_id);

CREATE UNIQUE INDEX IF NOT EXISTS unique_item ON table1(customer_id, kind) WHERE kind='NEW' OR kind='BACKUP';

我们看到yb_hash_code() 在 SELECT 查询中表现更好:

EXPLAIN ANALYZE select item_id from table1 WHERE yb_hash_code(item_id) >= 0 and yb_hash_code (item_id) < 1395 and modified_date < date '2022-04-08';
Planning Time: 7.967 ms
Execution Time: 82.929 ms
EXPLAIN ANALYZE select item_id from table1 WHERE modified_date < date '2022-04-08';
Planning Time: 0.054 ms
Execution Time: 4618.350 ms
EXPLAIN ANALYZE select item_id from table1 WHERE yb_hash_code(item_id) >= 0 and yb_hash_code(item_id) <=65535 and modified_date < date '2022-04-08';
Planning Time: 0.073 ms
Execution Time: 4565.615 ms
EXPLAIN ANALYZE select item_id from table1 WHERE yb_hash_code(item_id) >= 0 and yb_hash_code(item_id) < 1490 and modified_date < date '2022-04-08';
Planning Time: 0.148 ms
Execution Time: 84.737 ms

但是,您是否建议在上述#12094 修复后开始使用yb_hash_code()SELECT 查询?

【问题讨论】:

    标签: yugabytedb


    【解决方案1】:

    我猜这两个查询需要 4 秒进行 Seq Scan。 yb_hash_code() 仅针对 IndexScan 被下推。见[YSQL] yb_hash_code() not pushed down to SeqScan · Issue #12096 · yugabyte/yugabyte-db ·

    我认为您可以强制执行索引扫描的第三个提示,yb_hash_code() 将被按下。但是,也许您正试图对yb_hash_code() 做太多事情。它是针对特定情况引入的,例如在读取所有行时进行一些并行化。

    分布式数据库的目标是在逻辑上像使用数据库一样使用它,而无需关心分布。当需要特定的放置考虑时,我们有分区和表空间。

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2022-07-19
      • 1970-01-01
      • 2019-10-06
      • 2021-11-01
      • 2016-10-08
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多