mysql中INSERT SELECT查询中的索引

时间:2017-05-05 17:19:55

标签: mysql mysql-python

我有一个mysql查询:

insert into `my_table`
select *
from (
    select 1 as id, 2 as b, 3 as c from dual 
    union all
    select 1, 5, 6 from dual 
    union all
    select 1, 8, 9 from dual
    ) as t
where not exists (
        select id
        from `my_table`
        where id = 1;
    )

如果尚未在表中插入,我想以原子方式插入对应于id的一堆行。但是这个查询出现在mysql的慢速日志中,所以我想知道在这个锁定查询期间sql如何处理索引?

有没有办法提高此查询性能?

0 个答案:

没有答案