문제

SET @variable1 = (SELECT id FROM table2);
update vars set unq=1 where id IN @variable1

how to perform the above query. because there are one million rows and sub query taking too much time for update. so how to save all ids of table2 in var and use in second query.

도움이 되었습니까?

해결책

When in with a subquery takes too long, try rewriting with a join:

update vars join
       table2
       on vars.id = table2.id
    set unq = 1;

An index on table2.id would help speed up performance as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top