DB2,优化更新查询
DB2, optimize an update query
我有这个查询:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
这个查询没有结束。
可以不写吗?
我使用了这个查询并且有效:
merge into product a using (select distinct product_id ,TSINSERT from h_product where tsinsert is not null order by product_id ) b
on (a.product_id = b.product_id )
when matched then update set a.tsinsert = b.TSINSERT;
对于此查询:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
您想要 h_product(product_id, tsinsert)
上的索引。我很惊讶查询没有 where
子句,因为这会在没有匹配项时将 a.tsinsert
设置为 NULL
。
我有这个查询:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
这个查询没有结束。 可以不写吗?
我使用了这个查询并且有效:
merge into product a using (select distinct product_id ,TSINSERT from h_product where tsinsert is not null order by product_id ) b
on (a.product_id = b.product_id )
when matched then update set a.tsinsert = b.TSINSERT;
对于此查询:
update product a
set a.tsinsert = (select b.tsinsert
from h_product b
where b.tsinsert is not null and
a.product_id = b.product_id);
您想要 h_product(product_id, tsinsert)
上的索引。我很惊讶查询没有 where
子句,因为这会在没有匹配项时将 a.tsinsert
设置为 NULL
。