sql - Eliminate mysql file sort in update query -


i have such table use implement queue in mysql:

 create table `queue` (   `id` int(10) unsigned not null auto_increment,   `queue_name` varchar(255) not null,   `inserted` timestamp not null default current_timestamp on update current_timestamp,   `inserted_by` varchar(255) not null,   `acquired` timestamp null default null,   `acquired_by` varchar(255) default null,   `delayed_to` timestamp null default null,   `priority` int(11) not null default '0',   `value` text not null,   `status` varchar(255) not null default 'new',   primary key (`id`),   key `queue_index` (`acquired`,`queue_name`,`priority`,`id`) ) engine=innodb auto_increment=1 default charset=utf8 

my problem mysql use filesort when run update. execution slow (5s 800k rows in table).

describe update queue set acquired = "test" acquired null , queue_name = "q1" order priority, id limit 1;
 +----+-------------+-------+-------+---------------+-------------+---------+-------------+--------+-----------------------------+ | id | select_type | table | type  | possible_keys | key         | key_len | ref         | rows   |                       | +----+-------------+-------+-------+---------------+-------------+---------+-------------+--------+-----------------------------+ |  1 | simple      | queue | range | queue_index   | queue_index | 772     | const,const | 409367 | using where; using filesort | +----+-------------+-------+-------+---------------+-------------+---------+-------------+--------+-----------------------------+ 

what strange, when run select query same conditions , order columns filesort not used:

describe select id queue acquired null , queue_name = "q1" order priority, id limit 1;
 +----+-------------+-------+------+---------------+-------------+---------+-------------+--------+--------------------------+ | id | select_type | table | type | possible_keys | key         | key_len | ref         | rows   |                    | +----+-------------+-------+------+---------------+-------------+---------+-------------+--------+--------------------------+ |  1 | simple      | queue | ref  | queue_index   | queue_index | 772     | const,const | 409367 | using where; using index | +----+-------------+-------+------+---------------+-------------+---------+-------------+--------+--------------------------+ 

(query time 0s)

does know how avoid using filesort in update query or how increase performance?

regards, matzz

after discussion @ mysql forum (http://forums.mysql.com/read.php?24,620908,620908#msg-620908) reported bug http://bugs.mysql.com/bug.php?id=74049 (which verified). issue bypassed using select update:

set @update_id := -1; select (select @update_id := id) queue acquired null , queue_name = "q1" order priority, id limit 1; update; update queue set acquired = "test" id = @update_id; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -