简体   繁体   English

如何优化UPDATE查询以获得更好的MySQL性能

[英]how to optimize UPDATE query for better MySQL performance

I have 2 tables in mySQL db... they are very large.. its about 1 million now and soon to be 5 million or so 我在mySQL db中有2个表...它们非常大......现在大约有100万个,很快就会有500万左右

one is jobseeker other is joomla users table 一个是求职者,另一个是joomla用户表

I want to copy or insert IDs into the jobseeker table where the email column of both matches.. 我想将ID复制或插入到jobseeker表中,两者的电子邮件列都匹配。

ie jobseeker email = jos users email. 即求职者电子邮件= jos用户的电子邮件。

I used below query but it takes too much time and puts heavy load on mysql server ....the queries gets stuck and i always end-up restarting mysql ... 我使用下面的查询,但它需要太多的时间,并在mysql服务器上加重...查询卡住了,我总是最终重新启动mysql ...

UPDATE  `jos_jbjobs_jobseeker` 
SET user_id =   ( SELECT jos_users.id
FROM jos_users
WHERE jos_users.email =  jos_jbjobs_jobseeker.email)
WHERE EXISTS
  ( SELECT jos_users.id
    FROM jos_users
    WHERE jos_users.email =  jos_jbjobs_jobseeker.email);

how can I optimize above query to achieve better performance. 如何优化上述查询以获得更好的性能。 Also, I would be interested if it can be executed in batches ie 20000 or 40000 records at time. 此外,如果它可以批量执行,即20000或40000记录,我会感兴趣。

Please advise 请指教

Try this: 尝试这个:

UPDATE
    jos_jbjobs_jobseeker a
    INNER JOIN jos_users b ON a.email = b.email
SET
    a.user_id = b.id

How about this simple query? 这个简单的查询怎么样?

UPDATE jos_jbjobs_jobseeker jjj
JOIN jos_users ju
  ON jjj.email = ju.email
SET jjj.user_id = ju.id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM