Bug #31724 | UPDATE not properly using indexes | ||
---|---|---|---|
Submitted: | 20 Oct 2007 7:54 | Modified: | 30 Jul 2010 10:57 |
Reporter: | Ricardo Amorim | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | MySQL Server: MyISAM storage engine | Severity: | S3 (Non-critical) |
Version: | mysql-5.1.22-rc-linux-x86_64-icc-glibc23 | OS: | Linux (Debian 2.6.18-5-amd64) |
Assigned to: | Assigned Account | CPU Architecture: | Any |
[20 Oct 2007 7:54]
Ricardo Amorim
[20 Oct 2007 9:04]
Ricardo Amorim
A better explanation of the issue: According to "6.2.18. Speed of UPDATE Statements" in the documentation, UPDATE and SELECT statements are similar when it comes to query optimization. That said, I expect that UPDATE query "1" and CREATE TABLE (SELECT) query "2" perform the JOIN operation in a similar way. This does not happen as you can see from "vmstat" output. Query "1" does a lot of disk reads while query "2" is mostly CPU bound with ocasional writes to disk. I think that the SELECT query "2" does some kind of caching that is later used by UPDATE query "3". Caching is good, but I expect the behaviour of UPDATE query "1" to be the same as UPDATE query "3". The UPDATE query takes 20+ minutes the first time it is run (without the SELECT caching). I have tried to manually LOAD INDEX INTO CACHE the PRIMARY keys from both tables and then perform the UPDATE but there was _NO_ change from behaviour of query "1". I'd be happy to provide any further information or perform any other test.
[20 Oct 2007 9:51]
Sveta Smirnova
Thank you for the report. Please provvide output of explain select tel.b from dados inner join tel on dados.a = tel.a; and SHOW STATUS for both tables.
[20 Oct 2007 15:23]
Ricardo Amorim
mysql> explain select tel.b from dados inner join tel on dados.a = tel.a; +----+-------------+-----------------+--------+---------------+---------+---------+-----------------------+----------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+--------+---------------+---------+---------+-----------------------+----------+-------------+ | 1 | SIMPLE | dados | index | PRIMARY | PRIMARY | 8 | NULL | 10214373 | Using index | | 1 | SIMPLE | tel | eq_ref | PRIMARY | PRIMARY | 8 | celeste.dados.a | 1 | | +----+-------------+-------+--------+---------------+---------+---------+-----------------------+----------+-------------+ 2 rows in set (0.00 sec) mysql> show table status like 'dados'; +-------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | +-------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | dados | MyISAM | 10 | Dynamic | 10214373 | 52 | 538811000 | 281474976710655 | 171595776 | 0 | NULL | 2007-10-19 18:41:02 | 2007-10-19 18:54:17 | NULL | latin1_swedish_ci | NULL | | | +-------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ mysql> show table status like 'tel'; +------+--------+---------+------------+----------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment | +------+--------+---------+------------+----------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ | tel | MyISAM | 10 | Fixed | 19919306 | 12 | 239031672 | 3377699720527871 | 287178752 | 0 | NULL | 2007-10-19 07:37:47 | 2007-10-19 07:39:54 | NULL | latin1_swedish_ci | NULL | | | +------+--------+---------+------------+----------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+
[30 Jun 2010 10:57]
Sveta Smirnova
Thank you for the feedback. I can not repeat described behavior with test data. Please try current version 5.1.49 and if problem still exists send us output of `show status like 'ha%';` before and after every query.
[30 Jul 2010 23:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".