Details
Description
The optimizer chooses the wrong path for a query that should use the primary key:
MariaDB [cs0275577]> explain SELECT d.id, d.dname, c.id, c.cname, c.state FROM deployment d join host c on d.id=c.deployment_id order by c.id limit 1; |
+------+-------------+-------+------+-----------------------+-----------------------+---------+----------------+-------+---------------------------------+ |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | |
+------+-------------+-------+------+-----------------------+-----------------------+---------+----------------+-------+---------------------------------+ |
| 1 | SIMPLE | d | ALL | PRIMARY | NULL | NULL | NULL | 97470 | Using temporary; Using filesort | |
| 1 | SIMPLE | c | ref | cluster_fk_deployment | cluster_fk_deployment | 767 | cs0275577.d.id | 6 | |
|
+------+-------------+-------+------+-----------------------+-----------------------+---------+----------------+-------+---------------------------------+ |
2 rows in set (0.001 sec) |
MariaDB [cs0275577]> explain SELECT d.id, d.dname, c.id, c.cname, c.state FROM host c straight_join deployment d on d.id=c.deployment_id order by c.id limit 1; |
+------+-------------+-------+--------+-----------------------+---------+---------+---------------------------+------+-------+ |
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | |
+------+-------------+-------+--------+-----------------------+---------+---------+---------------------------+------+-------+ |
| 1 | SIMPLE | c | index | cluster_fk_deployment | PRIMARY | 767 | NULL | 1 | | |
| 1 | SIMPLE | d | eq_ref | PRIMARY | PRIMARY | 767 | cs0275577.c.deployment_id | 1 | | |
+------+-------------+-------+--------+-----------------------+---------+---------+---------------------------+------+-------+ |
2 rows in set (0.000 sec) |
 |
MariaDB [cs0275577]> SELECT d.id, d.dname, c.id, c.cname, c.state FROM deployment d join host c on d.id=c.deployment_id order by c.id limit 1; |
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
| id | dname | id | cname | state |
|
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
| 4f8cc10b-83ca-41d3-b5b4-9cc74e1292da | depl-73221 | 00000122-e6b5-499d-993f-8052a9272cf3 | cluster-14 | RUNNING |
|
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
1 row in set (25.254 sec) |
 |
MariaDB [cs0275577]> SELECT d.id, d.dname, c.id, c.cname, c.state FROM host c straight_join deployment d on d.id=c.deployment_id order by c.id limit 1; |
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
| id | dname | id | cname | state |
|
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
| 4f8cc10b-83ca-41d3-b5b4-9cc74e1292da | depl-73221 | 00000122-e6b5-499d-993f-8052a9272cf3 | cluster-14 | RUNNING |
|
+--------------------------------------+------------+--------------------------------------+------------+---------+ |
1 row in set (0.002 sec) |
Covering indexes did not help the query.
Attachments
Issue Links
- relates to
-
MDEV-28246 Optimizer uses all partitions during an update in MariaDB 10.6.x but not in 10.2.x
- Closed