MySQL Forums
Forum List  »  Optimizer & Parser

primary key vs covered index
Posted by: marcin kot
Date: November 30, 2016 09:55AM

hi, why mysql 5.7 using primary key instead of covering index ?

table:
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id_dok | int(11) | NO | PRI | NULL | |
| lp | int(11) | NO | PRI | NULL | |
| naz | varchar(20) | NO | | NULL | |
| rozm | int(8) | NO | | NULL | |
| opis | varchar(50) | YES | MUL | NULL | |
| oso_dod | int(6) | NO | | NULL | |
| dat_dod | datetime | NO | | NULL | |
| mimetype | varchar(20) | NO | | NULL | |
| plik | mediumblob | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+

indexes:
Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dokumenty | 0 | PRIMARY | 1 | id_dok | A | 2088 | NULL | NULL | | BTREE | | |
| dokumenty | 0 | PRIMARY | 2 | lp | A | 2368 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i | 1 | opis | A | 134 | NULL | NULL | YES | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i | 2 | naz | A | 1534 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i | 3 | dat_dod | A | 1867 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i | 4 | oso_dod | A | 1867 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 1 | id_dok | A | 1928 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 2 | lp | A | 2180 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 3 | opis | A | 2180 | NULL | NULL | YES | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 4 | naz | A | 2180 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 5 | dat_dod | A | 2180 | NULL | NULL | | BTREE | | |
| dokumenty | 1 | dokumenty_multi_i2 | 6 | oso_dod | A | 2187 | NULL | NULL | | BTREE | | |

query:
explain SELECT lp,opis,naz ,dat_dod,oso_dod FROM dokumenty WHERE id_dok=37399;

+----+-------------+-----------+------------+------+----------------------------+---------+---------+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-----------+------------+------+----------------------------+---------+---------+-------+------+----------+-------+
| 1 | SIMPLE | dokumenty | NULL | ref | PRIMARY,dokumenty_multi_i2 | PRIMARY | 4 | const | 1 | 100.00 | NULL |
+----+-------------+-----------+------------+------+----------------------------+---------+---------+-------+------+----------+-------+

Options: ReplyQuote


Subject
Views
Written By
Posted
primary key vs covered index
1066
November 30, 2016 09:55AM
552
December 01, 2016 01:39AM
562
December 01, 2016 03:38AM
588
December 01, 2016 03:57AM
526
December 01, 2016 04:16AM
463
December 01, 2016 04:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.