.
Bonjour,
Sur MySQL 5.7, j'ai ajouté sur une table en innoDB un index qui boost un max un select.
Il est bien utilisé sur une recherche d'une quinzaine de jours (environ) mais pas au delà !!!
Pourquoi ??! Une limitation ? de quoi ?
Comment faire pour levé cette limitation ?
Sinon comment savoir quand utiliser un autre index (moins bon) ?
(MySQL ne choisit pas le bon...)
Voir ci-dessous:
J'ai essayé avec différent intervalle de longueur et de plage de date,
c'est toujours AUX ENVIRONS de 15 jours que l'index idPlus n'est plus pris en compte.
GRRRrrr !
Merci.
PRESENTATION TABLE
------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 mysql> show columns from Mes; +--------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+------------------+------+-----+---------+----------------+ | idx | int(10) unsigned | NO | PRI | NULL | auto_increment | | rep | int(11) | YES | MUL | NULL | | | ind | tinyint(4) | YES | | NULL | | | dtA | datetime(3) | YES | | NULL | | | val | float | YES | | NULL | | | infoI1 | int(11) | YES | | NULL | | | infoS1 | varchar(30) | YES | | NULL | | | dyA | int(10) unsigned | YES | MUL | 0 | | +--------+------------------+------+-----+---------+----------------+ 8 rows in set (0.01 sec)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 mysql> show index from Mes; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------ | mes | 0 | PRIMARY | 1 | idx | A | 13097815 | NULL | NULL | | BTREE | mes | 1 | idMes | 1 | rep | A | 33 | NULL | NULL | YES | BTREE | mes | 1 | idMes | 2 | ind | A | 33 | NULL | NULL | YES | BTREE | mes | 1 | idDyA | 1 | dyA | A | 85 | NULL | NULL | YES | BTREE | mes | 1 | idPlus | 1 | dyA | A | 8242 | NULL | NULL | YES | BTREE | mes | 1 | idPlus | 2 | rep | A | 15008 | NULL | NULL | YES | BTREE | mes | 1 | idPlus | 3 | ind | A | 15008 | NULL | NULL | YES | BTREE +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------ 7 rows in set (0.00 sec)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 mysql> select * from Mes where dtA > '2020-02-01' limit 5; +----------+------+------+-------------------------+----------+--------+----------------------+------------+ | idx | rep | ind | dtA | val | infoI1 | infoS1 | dyA | +----------+------+------+-------------------------+----------+--------+----------------------+------------+ | 62405160 | 681 | 1 | 2020-02-01 00:00:00.744 | 0.146489 | 0 | STM: Mesure opacité | 1580511600 | | 62405161 | 604 | 1 | 2020-02-01 00:00:08.195 | 1.56353 | 0 | LM: Mesure de vent | 1580511600 | | 62405162 | 609 | 1 | 2020-02-01 00:00:17.395 | 1.44338 | 0 | LM: Mesure de vent | 1580511600 | | 62405163 | 606 | 1 | 2020-02-01 00:00:19.296 | 1.64104 | 0 | LM: Mesure de vent | 1580511600 | | 62405164 | 602 | 1 | 2020-02-01 00:00:19.846 | 1.43067 | 0 | LM: Mesure de vent | 1580511600 | +----------+------+------+-------------------------+----------+--------+----------------------+------------+LE PROBLEME
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 mysql> select count(idx) from Mes; +------------+ | count(idx) | +------------+ | 13159102 | +------------+
-----------
==> Requête super rapide... (tout est relatif...)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 mysql> explain select dtA, val FROM Mes USE INDEX(idPlus) WHERE dyA >= unix_timestamp('2020-02-01') AND dyA <= unix_timestamp('2020-02-15') AND rep=0601 AND ind=1; +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+----------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+----------------------------------+ | 1 | SIMPLE | Mes | NULL | range | idPlus | idPlus| 12 | NULL | 2159980 | 0.30 | Using index condition; Using MRR | +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+----------------------------------+
==> Requête super lente...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 mysql> explain select dtA, val FROM Mes USE INDEX(idPlus) WHERE dyA >= unix_timestamp('2020-02-01') AND dyA <= unix_timestamp('2020-02-16') AND rep=0601 AND ind=1; +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+ | 1 | SIMPLE | Mes | NULL | ALL | idPlus | NULL | NULL | NULL | 13097815 | 0.05 | Using where | +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+
Merci !
Partager