MYSQL query performs very slow

前端 未结 8 1263
一个人的身影
一个人的身影 2020-12-10 01:52

I have developed a user bulk upload module. There are 2 situations, when I do a bulk upload of 20 000 records when database has zero records. Its taking about 5 hours. But w

8条回答
  •  不思量自难忘°
    2020-12-10 02:37

    Indexes are your friend.

    UPDATE User ... WHERE id = ... -- Desperately needs an index on ID, probably PRIMARY KEY.

    Similarly for renameSource.

    SELECT * 
    FROM `User` `t` 
    WHERE `t`.`firstName`='Franck' 
      AND `t`.`lastName`='ALLEGAERT ' 
      AND `t`.`dateOfBirth`='1971-07-29' 
      AND (userType NOT IN ("1")) 
    LIMIT 1;
    

    Needs INDEX(firstName, lastName, dateOfBirth); the fields can be in any order (in this case).

    Look at each query to see what it needs, then add that INDEX to the table. Read my Cookbook on building indexes.

提交回复
热议问题