Answer the question
In order to leave comments, you need to log in
How to optimize update in mysql?
There is a table:
CREATE TABLE test.sites_list (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
url varchar(255) NOT NULL COMMENT 'Домен',
reg varchar(100) DEFAULT NULL COMMENT 'Регистратор',
domain_created date DEFAULT NULL COMMENT 'Дата регистрации домена',
last_http_code int(11) NOT NULL COMMENT 'Последний статус ответа сервера',
created_at timestamp DEFAULT CURRENT_TIMESTAMP COMMENT 'Время создания',
updated_at timestamp DEFAULT '0000-00-00 00:00:00',
status int(11) NOT NULL COMMENT 'Статус',
marker varchar(255) NOT NULL DEFAULT '',
proc varchar(255) DEFAULT NULL,
PRIMARY KEY (id),
INDEX domainCreated_updatedAt (domain_created, updated_at),
INDEX Status_Proc_dCreated (status, proc, domain_created, updated_at),
INDEX UpdatedAt_Status (updated_at, status)
)
ENGINE = INNODB
AUTO_INCREMENT = 19795014
AVG_ROW_LENGTH = 447
CHARACTER SET utf8
COLLATE utf8_general_ci;
UPDATE `sites_list` SET `proc` = '2cc16b53f60654d97bcfb265eb0082a4' WHERE `status` = 0 AND `proc` = '' ORDER BY `domain_created` DESC, `updated_at` LIMIT 50;
Answer the question
In order to leave comments, you need to log in
INDEX Status_Proc_dCreated (status, proc, domain_created, updated_at),
Here are all indexes:
INDEX domainCreated_updatedAt (domain_created, updated_at),
INDEX Status_Proc_dCreated (status, proc, domain_created, updated_at),
INDEX UpdatedAt_Status (updated_at, status)
The cards say that it could be a different sort order in the ORDER BY. Try ORDER BY `domain_created` DESC, `updated_at` DESC
if the application logic allows.
In general, it would be nice to see
EXPLAIN SELECT * FROM `sites_list`
WHERE `status` = 0 AND `proc` = ''
ORDER BY `domain_created` DESC, `updated_at` LIMIT 50
EXPLAIN SELECT * FROM `sites_list`
WHERE `status` = 0 AND `proc` = ''
ORDER BY `domain_created` DESC, `updated_at` LIMIT 50
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question