The following SQL has a preparing time of 30+ second. Is the SQL which is wrong, or the fact that I have close to one million result in the database? Can this SQL be optimized not to have it in preparing for that long?
UPDATE url_source_wp SET hash="ASDF2"
WHERE (url_source_wp.id NOT IN (
SELECT url_done_wp.url_source_wp FROM url_done_wp WHERE url_done_wp.url_group = 4)
)
AND (hash IS NULL) LIMIT 50
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `url_done_wp` ADD INDEX `url_wp_idx_url_group` (`url_group`);
ALTER TABLE `url_source_wp` ADD INDEX `url_wp_idx_hash_id` (`hash`,`id`);
SELECT
url_source_wp.hash
FROM
url_source_wp
WHERE
(
url_source_wp.id NOT IN (
SELECT
url_done_wp.url_source_wp
FROM
url_done_wp
WHERE
url_done_wp.url_group = 4
)
)
AND (
url_source_wp.hash IS NULL
) LIMIT 50