Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

efficient update job query #66

Open
ghazel opened this issue Feb 17, 2016 · 0 comments
Open

efficient update job query #66

ghazel opened this issue Feb 17, 2016 · 0 comments

Comments

@ghazel
Copy link

ghazel commented Feb 17, 2016

The query, which can take several seconds:

UPDATE `delayed_jobs` SET `delayed_jobs`.`locked_at` = '2016-02-17 05:20:59', `delayed_jobs`.`locked_by` = 'host:mine pid:60282' WHERE ((run_at <= '2016-02-17 05:20:59.484088' AND (locked_at IS NULL OR locked_at < '2015-02-17 05:20:59.484102') OR locked_by = 'host:mine pid:60282') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1

My indexes:

Create Table: CREATE TABLE `delayed_jobs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `priority` int(11) NOT NULL DEFAULT '0',
  `attempts` int(11) NOT NULL DEFAULT '0',
  `handler` text NOT NULL,
  `last_error` text,
  `run_at` datetime DEFAULT NULL,
  `locked_at` datetime DEFAULT NULL,
  `failed_at` datetime DEFAULT NULL,
  `locked_by` varchar(191) DEFAULT NULL,
  `queue` varchar(191) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `delayed_jobs_priority` (`priority`,`run_at`),
  KEY `index_delayed_jobs_on_priority_and_run_at` (`priority`,`run_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1154052 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED

EXPLAIN says:

+----+-------------+--------------+-------+---------------+---------+---------+------+-------+-----------------------------+  
| id | select_type | table        | type  | possible_keys | key     | key_len | ref  | rows  | Extra                       |  
+----+-------------+--------------+-------+---------------+---------+---------+------+-------+-----------------------------+  
|  1 | SIMPLE      | delayed_jobs | index | NULL          | PRIMARY | 4       | NULL | 57281 | Using where; Using filesort |  
+----+-------------+--------------+-------+---------------+---------+---------+------+-------+-----------------------------+  
1 row in set (0.00 sec) 
@ghazel ghazel changed the title efficient job query efficient update job query Feb 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant