Basically we are very happy with Mysqls performance, similar queries are completed in a split second. Now we face a problem with this query
SELECT dc.id,dmr.art_id
FROM dmr
JOIN dma ON dma.id = dmr.dml_id
JOIN dc ON dc.id = dma.dc_id
WHERE dmr.art_id = 2285
It takes 50 seconds to fetch 5021 rows. A missing index is probably the most common cause for issues like that. So I preceded the query by EXPLAIN and got this query plan which shows that only indexes are used no sequential scans.
The tables dmr and dma have 3 million rows each, dc has 6000 rows.
+----+-------------+-------+--------+-------------------------------+----------------+---------+--------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+-------------------------------+----------------+---------+--------------------+------+-------------+
| 1 | SIMPLE | dmr | ref | FKC33D5199F17E1825,ix_art_ref | ix_art_ref | 5 | const | 5021 | Using where |
| 1 | SIMPLE | dma | eq_ref | PRIMARY,FK8C6E1445153BBDC9 | PRIMARY | 8 | dev.dmr.dml_id | 1 | |
| 1 | SIMPLE | dc | eq_ref | PRIMARY | PRIMARY | 8 | dev.dma.dc_id | 1 | Using index |
+----+-------------+-------+--------+-------------------------------+----------------+---------+--------------------+------+-------------+
What could cause this problems?
MySql Version is 5.5 using InnoDB as engine. (Only default parameters on windows).
EDIT
When I remove the where clause, mysql returns the (huge) result set immediately. The query plan in this case looks like:
+----+-------------+-------+-------+----------------------------+--------------------+---------+------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+----------------------------+--------------------+---------+------------+------+--------------------------+
| 1 | SIMPLE | dc | index | PRIMARY | FKAEB144C64FA71464 | 9 | NULL | 4037 | Using index |
| 1 | SIMPLE | dma | ref | PRIMARY,FK8C6E1445153BBDC9 | FK8C6E1445153BBDC9 | 9 | dev.dc.id | 263 | Using where; Using index |
| 1 | SIMPLE | dmr | ref | FKC33D5199F17E1825 | FKC33D5199F17E1825 | 9 | dev.dma.id | 1 | Using where |
+----+-------------+-------+-------+----------------------------+--------------------+---------+------------+------+--------------------------+
Maybe the tables are very fragmented and MySQL has to go all over the disk to fetch those 5021 rows?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With