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