【发布时间】:2022-07-20 00:58:46
【问题描述】:
[用户在YugabyteDB Community Slack上发布的问题]
我们在使用 YSQL 的 postgresql (yugabyte DB 2.8.3) 中有以下模式:
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';
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)
);
目标:
步骤 1) 从 table1 中选择 item_id's WHERE modified_date
步骤 2) 从表 item_data 中删除,其中 item_id = 步骤 1 中的任何 item_id
目前我们使用查询
SELECT item_id FROM table1 WHERE modified_date < $1
SELECT 查询可以将yb_hash_code(item_id) 与 SELECT 查询一起应用吗?因为 table1 在 item_id 上被索引?提高 SELECT 查询的性能
目前我们执行:
DELETE FROM item_data x WHERE x.item_id IN the listOfItemIds(provided in Step1 above).
使用给定的listOfItemIds,我们可以使用yb_hash_code(item_id) 来提高DELETE 操作的性能吗?
【问题讨论】:
标签: yugabytedb