| Bug #31724 | UPDATE not properly using indexes | ||
|---|---|---|---|
| Submitted: | 20 Oct 2007 9:54 | Modified: | 14 Nov 2007 11:37 |
| Reporter: | Ricardo Amorim | ||
| Status: | Analyzing | ||
| Category: | Server: MyISAM | 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: | Sveta Smirnova | Target Version: | |
[20 Oct 2007 9:54]
Ricardo Amorim
[20 Oct 2007 11: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 11: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 17: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 | |
|
+------+--------+---------+------------+----------+----------------+-------------+------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+
