我有一个性能很差的查询(我继承了)并且我不太清楚如何优化它...据我所知,它将第二列的值设置为第一列的值PLUS另一个表中找到关系的值。
update table1 set
col2 = col1 || coalesce ((
select table2.the_column_wanted from table2 where table2.fk = table1.pk and
table2.flag = 'Y'))
where flag = 'Y' and pk in ( select distinct fk from table2 );
答案 0 :(得分:0)
确切的速度问题取决于您的表格的特征,但一般情况下我会针对此类问题调查MERGE
。像这样:
MERGE INTO table1 USING table2
ON table1.pk = table2.fk and
table1.flag = 'Y' and
table2.flag = 'Y'
WHEN MATCHED THEN UPDATE SET
table1.col2 = table1.col1 || table2.the_column_wanted;
写的查询非常值得怀疑。你应该好好看看你“继承”的所有代码。