How can I further optimize a derived table query which performs better than the JOINed equivalent?

后端 未结 4 1756
庸人自扰
庸人自扰 2020-12-08 11:07

UPDATE: I found a solution. See my Answer below.

My Question

How can I optimize this query to minimize my downtime? I need to update over

4条回答
  •  忘掉有多难
    2020-12-08 11:41

    This will let you have read-only access for duration of changes:

    create table_new (new schema);
    insert into table_new select * from table order by primary_key_column;
    rename table to table_old;
    rename table_new to table;
    -- recreate triggers if necessary
    

    When inserting data to InnoDB tables it's crucial that you do this in primary key's order (otherwise with large datasets it's few orders of magnitude slower).

提交回复
热议问题