Bug #44445 | Problem using index when selecting all columns | ||
---|---|---|---|
Submitted: | 23 Apr 2009 19:24 | Modified: | 19 Aug 2009 8:52 |
Reporter: | Kiriakos Tsourapas | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1.31-log, 5.0, 5.1, azalea bzr | OS: | Linux |
Assigned to: | CPU Architecture: | Any | |
Tags: | BKA |
[23 Apr 2009 19:24]
Kiriakos Tsourapas
[23 Apr 2009 21:15]
MySQL Verification Team
Thank you for the bug report. Yes you are using a quite older server version and our procedure to verify a bug is with the current source and lasted released version so would be nice if you try to test with latest released version on test environment and if the issue is still observed then could you please provide the dump file of the offended table (create table plus insert data statements) and your my.cnf file if for purposes test is relevant. Thanks in advance.
[27 Apr 2009 17:16]
Kiriakos Tsourapas
Hi again, I have imported the data to version 5.1.31 The problem persists. Here is the table : ---------------------------------- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` bigint(20) unsigned NOT NULL DEFAULT '0', `msisdn` varchar(20) NOT NULL, `state` varchar(5) NOT NULL, `timeperformed` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `blob_id` bigint(20) unsigned NOT NULL, `caller` varchar(20) NOT NULL, `media` longblob NOT NULL, `duration` double NOT NULL, PRIMARY KEY (`id`,`msisdn`,`state`,`timeperformed`) USING BTREE, KEY `blob_idx` (`blob_id`), KEY `idx_Main` (`msisdn`,`state`,`timeperformed`,`caller`), KEY `idx_Reverse` (`caller`,`timeperformed`,`state`,`msisdn`), KEY `cleanerIdx` (`timeperformed`,`state`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ---------------------------------- There are two problems : Problem #1 : The following select takes 30 seconds to complete : select id, caller from voicemessages where timeperformed < '2009-04-15 15:57:45' and state = '1' limit 1 while if I try without the caller, it returns immediately : select id from voicemessages where timeperformed < '2009-04-15 15:57:45' and state = '1' limit 1 Please find attached the logs showing the time it takes to execute the queries and the explain of each statement. Problem #2: The following statement, returns in completely different times, depending where I execute it from. It returns instantly from linux mysql command line, but takes 45 seconds from MySQL Browser. Both command line and browser are connected with LAN to the server. select id, blob_id from voicemessages where timeperformed < '2009-04-15 15:57:45' and state = '1' limit 1; I included the explain of this statement in the logs.
[27 Apr 2009 17:16]
Kiriakos Tsourapas
Logs showing explain statement and times of execution
Attachment: MySQLBug44445.log (application/octet-stream, text), 1.93 KiB.
[27 Apr 2009 17:34]
Kiriakos Tsourapas
I re-post the "show create" of the table. One of the indexes was wrong in the previous submission. This is the one where the tests were performed DROP TABLE IF EXISTS `voice2sms`.`voicemessages`; CREATE TABLE `voice2sms`.`voicemessages` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `msisdn` varchar(20) NOT NULL, `state` varchar(5) NOT NULL, `timeperformed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `blob_id` bigint(20) unsigned NOT NULL, `caller` varchar(20) NOT NULL, `media` longblob NOT NULL, `duration` double NOT NULL, PRIMARY KEY (`id`,`msisdn`,`state`,`timeperformed`) USING BTREE, KEY `blob_idx` (`blob_id`), KEY `idx_Main` (`msisdn`,`state`,`timeperformed`,`caller`), KEY `idx_Reverse` (`caller`,`timeperformed`,`state`,`msisdn`), KEY `cleanerIdx` (`timeperformed`,`state`,`id`,`blob_id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=1415518 DEFAULT CHARSET=latin1; Thank you in advance for you help.
[14 Aug 2009 16:31]
Sveta Smirnova
Thank you for the report. Verified as described: mysql> select * from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1' limit 1; +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | id | msisdn | state | timeperformed | blob_id | caller | media | duration | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | 121 | f the Embedded MySQ | 1 | 2009-08-14 17:04:11 | 120 | e | | -859765344 | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ 1 row in set (13.73 sec) mysql> select id from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1' limit 1; +-----+ | id | +-----+ | 121 | +-----+ 1 row in set (2.95 sec) mysql> select * from voicemessages where id in (select id from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1') limit 1; +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | id | msisdn | state | timeperformed | blob_id | caller | media | duration | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | 121 | f the Embedded MySQ | 1 | 2009-08-14 17:04:11 | 120 | e | | -859765344 | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ 1 row in set (0.31 sec) mysql> explain select * from voicemessages where id in (select id from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1') limit 1; +----+--------------------+---------------+----------------+--------------------+---------+---------+------+---------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------------+---------------+----------------+--------------------+---------+---------+------+---------+--------------------------+ | 1 | PRIMARY | voicemessages | ALL | NULL | NULL | NULL | NULL | 1024000 | Using where | | 2 | DEPENDENT SUBQUERY | voicemessages | index_subquery | PRIMARY,cleanerIdx | PRIMARY | 8 | func | 10240 | Using index; Using where | +----+--------------------+---------------+----------------+--------------------+---------+---------+------+---------+--------------------------+ 2 rows in set (0.01 sec) Since version 5.4.4 workaround does not work: mysql> select * from voicemessages where id in (select id from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1') limit 1; +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | id | msisdn | state | timeperformed | blob_id | caller | media | duration | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ | 121 | f the Embedded MySQ | 1 | 2009-08-14 13:04:11 | 120 | e | | -859765344 | +-----+---------------------+-------+---------------------+---------+--------+-------+------------+ 1 row in set (8.33 sec) mysql> explain select * from voicemessages where id in (select id from voicemessages where timeperformed < '2009-09-15 15:57:45' and state = '1') limit 1; +----+-------------+---------------+-------+--------------------+------------+---------+------+---------+---------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------------+-------+--------------------+------------+---------+------+---------+---------------------------------------+ | 1 | PRIMARY | voicemessages | ALL | PRIMARY | NULL | NULL | NULL | 1024000 | | | 1 | PRIMARY | voicemessages | range | PRIMARY,cleanerIdx | cleanerIdx | 4 | NULL | 1023999 | Using where; Using index; Materialize | +----+-------------+---------------+-------+--------------------+------------+---------+------+---------+---------------------------------------+ 2 rows in set (0.01 sec)
[19 Aug 2009 8:52]
Sveta Smirnova
Same results with BKA