
{"id":1363,"date":"2013-01-08T11:22:24","date_gmt":"2013-01-08T10:22:24","guid":{"rendered":"http:\/\/dasini.net\/blog\/?p=1363"},"modified":"2013-01-30T10:57:30","modified_gmt":"2013-01-30T09:57:30","slug":"full-table-scan-vs-full-index-scan-part1-2","status":"publish","type":"post","link":"https:\/\/dasini.net\/blog\/2013\/01\/08\/full-table-scan-vs-full-index-scan-part1-2\/","title":{"rendered":"Full table scan vs Full index scan part1-2"},"content":{"rendered":"<h1 dir=\"ltr\" id=\"internal-source-marker_0.35128079011913194\"><span style=\"font-size: 24px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">1\/ Le myst\u00e8re de la variable Last_query_cost<\/span><\/h1>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">MySQL utilise un optimiseur \u00e0 base de co\u00fbts. Le plan d\u2019ex\u00e9cution de la requ\u00eate choisit est celui dont le co\u00fbt est le plus faible. Ce dernier peut \u00eatre visualis\u00e9 gr\u00e2ce \u00e0 la variable <\/span><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-status-variables.html#statvar_Last_query_cost\"><span style=\"font-size: 15px; font-family: Arial; color: #1155cc; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Last_query_cost<\/span><\/a><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Son unit\u00e9 est le co\u00fbt (encore lui) des acc\u00e8s al\u00e9atoires en lecture de pages de 4ko.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">\u00c9trangement cette variable est assez peu\/mal document\u00e9e. Voici ce qu\u2019on retrouve dans la doc officielle de MySQL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Je cite: <\/span><br \/>\n<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-status-variables.html#statvar_Last_query_cost\"><span style=\"font-size: 15px; font-family: Arial; color: #1155cc; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Last_query_cost<\/span><\/a><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline;\">The total cost of the last compiled query as computed by the query optimizer. This is useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet. The default value is 0.<\/span><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-status-variables.html#statvar_Last_query_cost\"><span style=\"font-size: 15px; font-family: Arial; color: #1155cc; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Last_query_cost<\/span><\/a><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> has session scope.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline;\">The<\/span><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/server-status-variables.html#statvar_Last_query_cost\"><span style=\"font-size: 15px; font-family: Arial; color: #1155cc; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Last_query_cost<\/span><\/a><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> value can be computed accurately only for simple \u201cflat\u201d queries, not complex queries such as those with subqueries or<\/span><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/union.html\"><span style=\"font-size: 15px; font-family: Arial; color: #1155cc; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">UNION<\/span><\/a><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: italic; font-variant: normal; text-decoration: none; vertical-align: baseline;\">. For the latter, the value is set to 0.<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">La valeur de Last_query_cost est parfois d\u00e9concertante, m\u00eame avec MySQL 5.6. Voyez par vous m\u00eame&#8230;<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Quelques informations avant d\u2019entrer dans le vif du sujet.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Server version:<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">5.6.9<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">-rc MySQL Community Server (GPL)<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Configuration de l\u2019instance<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Innodb buffer pool size = <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">32 Go<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">max_heap_table_size = tmp_table_size = <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">512 Mo<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Table<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">: <\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">CREATE TABLE `bills` (<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0`d` datetime NOT NULL,<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0`price` smallint(5) unsigned NOT NULL,<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0PRIMARY KEY (`id`),<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0KEY `d` (`d`)<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">) ENGINE=<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">InnoDB<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">SHOW TABLE STATUS<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">*************************** 1. row ***************************<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Name: bills<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Engine: InnoDB<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Version: 10<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0 Row_format: Compact<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Rows: 176268<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> Avg_row_length: 56<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">\u00a0\u00a0\u00a0 Data_length: 9961472<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Max_data_length: 0<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0Index_length: 4210688<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 Data_free: 2097152<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8230;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 Collation: utf8_swedish_ci<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">=&gt; Donn\u00e9es + Index: \u00a0environs 16 Mo<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">L\u2019id\u00e9e est d\u2019ex\u00e9cuter la requ\u00eate ci-dessous, avec diff\u00e9rents \u201chint\u201d est de voir les plans d\u2019ex\u00e9cution (QEP) g\u00e9n\u00e9r\u00e9s par MySQL ainsi que leurs co\u00fbts respectifs.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">SELECT d,avg(price) FROM bills GROUP BY d<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">2 QEP possibles:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; Faire un full table scan, cr\u00e9er une table temporaire pour regrouper et ordonner (particularit\u00e9 du GROUP BY de MySQL) les donn\u00e9es en fonction de la date (d) pour calculer la moyenne des prix (avg(price)).<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; Faire un full index scan sur d, ce qui \u00e9vite le tri et la cr\u00e9ation de la table temporaire. Cependant le \u201cprice\u201d n\u2019\u00e9tant pas dans l\u2019index, l\u2019info doit \u00eatre r\u00e9cup\u00e9r\u00e9 dans la couche \u201cdata\u201d <\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Query 1\/ EXPLAIN \u00a0SELECT d,avg(price) FROM bills GROUP BY d\\G<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">*************************** 1. row ***************************<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: 1<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0select_type: SIMPLE<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table: bills<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: index<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">possible_keys: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 key: d<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 key_len: 5<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ref: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows: 176268<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Extra: NULL<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Le choix de l\u2019optimiseur est assez intuitif, il se sert du fait que l\u2019index d est tri\u00e9 (type: index = full index scan) pour optimiser le GROUP BY (regroupement + tri), c\u2019est \u00e0 dire ne pas cr\u00e9er de table temporaire.<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Le co\u00fbt de cette op\u00e9ration est:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">SHOW STATUS LIKE &lsquo;Last_query_cost;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Variable_name \u00a0\u00a0| Value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Last_query_cost | <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">212129.599000<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Question de psychopathe, que se passe t\u2019il si je force l\u2019optimiseur \u00e0 utiliser l\u2019index qu\u2019il dit qu\u2019il va utiliser ? (c\u2019est vicieux je sais :D)<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Query 2\/ EXPLAIN \u00a0SELECT d,avg(price) FROM bills <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">USE INDEX(d)<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> GROUP BY d\\G *************************** 1. row ***************************<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: 1<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0select_type: SIMPLE<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table: bills<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: index<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">possible_keys: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 key: d<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 key_len: 5<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ref: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows: 176268<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Extra: NULL<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Alors pour \u00eatre pr\u00e9cis, l\u00e0 je ne le force pas vraiment, je l\u2019incite (fortement) \u00e0 l\u2019utiliser. Mais sans surprise, il l\u2019utilise (ouf !), en d\u2019autre terme le QEP est le m\u00eame que pr\u00e9c\u00e9demment.<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Et qu\u2019en est il du co\u00fbt ?<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">SHOW STATUS LIKE &lsquo;Last_query_cost;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Variable_name \u00a0\u00a0| Value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Last_query_cost | <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">212129.599000<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Pareil que pr\u00e9c\u00e9demment, circuler il n\u2019y a rien \u00e0 voir !<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Ok est si l\u00e0 je le force vraiment, avec FORCE INDEX (principale diff\u00e9rence entre USE INDEX et FORCE INDEX est qu\u2019avec le second l\u2019optimiseur choisira (si c\u2019est possible bien s\u00fbr) d\u2019utiliser l\u2019index en lieu est place d\u2019un full table scan)<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Query 3\/ \u00a0EXPLAIN \u00a0SELECT d,avg(price) FROM bills <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">FORCE INDEX(d)<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> GROUP BY d\\G<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">*************************** 1. row ***************************<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: 1<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0select_type: SIMPLE<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table: bills<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: index<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">possible_keys: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 key: d<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 key_len: 5<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ref: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows: 176268<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Extra: NULL<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">L\u00e0 encore, (sans surprise) le QEP est le m\u00eame que pr\u00e9c\u00e9demment. Et le co\u00fbt ?<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">SHOW STATUS LIKE &lsquo;Last_query_cost;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Variable_name \u00a0\u00a0| Value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Last_query_cost | <\/span><span style=\"font-size: 15px; font-family: Arial; color: #ff0000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">387790.599000<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">\u2026 WTF \u2026<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Bon l\u00e0 pour \u00eatre franc, je n\u2019ai pas d\u2019explications rationnelles. Serait ce une feature ? (rationnelle on \u00e0 dit !!!) ok ok bah un bug alors.<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Inutile de pr\u00e9ciser que je me suis empress\u00e9 de tester avec d\u2019autres versions de MySQL (psychopate !) et le r\u00e9sultat est sans appel:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Avec MySQL 5.5, MariaDB 5.5 &amp; Percona server 5.5 le co\u00fbt du FORCE INDEX est <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">identique<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> aux 3 autres co\u00fbts.<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">J\u2019opterai donc pour une petite r\u00e9gression de l\u2019optimiseur, bref un BUG<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Soit ! si j\u2019emp\u00eache l\u2019optimiseur d\u2019utiliser l\u2019index:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Query 4\/ EXPLAIN \u00a0SELECT d,avg(price) FROM bills <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">IGNORE INDEX(d)<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> GROUP BY d\\G<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">*************************** 1. row ***************************<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: 1<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0select_type: SIMPLE<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table: bills<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: ALL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">possible_keys: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 key: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0 key_len: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ref: NULL<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows: 176268<\/span><br \/>\n<strong><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Extra: Using temporary; Using filesort<\/span><\/strong><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">C\u2019est plut\u00f4t clair, full table scan (type: ALL), plus cr\u00e9ation d\u2019un table temporaire (Using temporary) pour regrouper les donn\u00e9es et les trier (Using filesort). C\u2019est le prix \u00e0 payer pour ne pas utiliser l\u2019index. \u00c7a \u00e0 l\u2019air vachement co\u00fbteux tout \u00e7a, Voyons ce qu\u2019en pense MySQL<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">SHOW STATUS LIKE &lsquo;Last_query_cost&rsquo;;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Variable_name \u00a0\u00a0| Value \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">| Last_query_cost | <\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: bold; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">212129.599000<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"> |<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\"><br class=\"kix-line-break\" \/>Humm pour l\u2019optimiseur, le co\u00fbt est le m\u00eame, pas forc\u00e9ment intuitif tout \u00e7a Pour rappel (ou pas) \u00a0les param\u00e8tres pris en compte par l\u2019optimiseur sont (entre autre): <\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; Pour les co\u00fbts I\/O: information sur les enregistrements (nombre, taille,), informations sur les index(null, unique, cardinalit\u00e9&#8230;)&#8230;<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; Pour les co\u00fbts CPU: l\u2019\u00e9valuation des conditions, comparaison du rapport index\/enregistrements<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Force est de constater que selon l\u2019optimiseur, le co\u00fbt du FTS + table temp + tri et \u00e9quivalent, pour cette requ\u00eate au FIS.<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline;\">Bilan de cette premi\u00e8re partie<\/span><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">:<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; Il y a manifestement un bug de l\u2019optimiseur en MySQL 5.6.9 lors du calcul du co\u00fbt d\u2019une requ\u00eate avec la clause FORCE INDEX<\/span><br \/>\n<span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">&#8211; \u00a0Dans notre exemple, le co\u00fbt d\u2019un full index scan est le m\u00eame qu\u2019un full table scan + Using temporary + Using filesort<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Mais alors, quel QEP donne t\u2019il le meilleur temps d\u2019ex\u00e9cution ?<\/span><\/p>\n<p><span style=\"font-size: 15px; font-family: Arial; color: #000000; background-color: transparent; font-weight: normal; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline;\">Cette question est trait\u00e9e dans la 2\u00e8me partie de cet article<\/span><\/p>\n<p><em>(<a title=\"2\/ FTS ou FIS\" href=\"https:\/\/dasini.net\/blog\/2013\/01\/30\/full-table-scan-vs-full-index-scan-part2-2\/\">Aller \u00e0 la 2\u00e8me partie..<\/a>)<\/em><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL utilise un optimiseur \u00e0 base de co\u00fbts. Le plan d\u2019ex\u00e9cution de la requ\u00eate choisit est celui dont le co\u00fbt est le plus faible. Ce dernier peut \u00eatre visualis\u00e9 gr\u00e2ce \u00e0 la variable Last_query_cost.<br \/>\nSon unit\u00e9 est le co\u00fbt (encore lui) des acc\u00e8s al\u00e9atoires en lecture de pages de 4ko.<br \/>\n\u00c9trangement cette variable est assez peu\/mal document\u00e9e. Voici ce qu\u2019on retrouve dans la doc officielle de MySQL<br \/>\nJe cite:<br \/>\nLast_query_cost<br \/>\nThe total cost of the last compiled query as computed by the query optimizer. This is useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet. The default value is 0.Last_query_cost has session scope.<br \/>\nTheLast_query_cost value can be computed accurately only for simple \u201cflat\u201d queries, not complex queries such as those with subqueries orUNION. For the latter, the value is set to 0.<\/p>\n<p>La valeur de Last_query_cost est parfois d\u00e9concertante, m\u00eame avec MySQL 5.6. Voyez par vous m\u00eame&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[34],"tags":[186],"class_list":["post-1363","post","type-post","status-publish","format-standard","hentry","category-optimisation","tag-mysql-5-6"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9LfWW-lZ","jetpack-related-posts":[{"id":430,"url":"https:\/\/dasini.net\/blog\/2009\/01\/29\/influencer-loptimiseur-de-mysql\/","url_meta":{"origin":1363,"position":0},"title":"Influencer l&rsquo;optimiseur de MySQL","author":"Olivier DASINI","date":"29 janvier 2009","format":false,"excerpt":"Il est possible d'influencer l'optimiseur pour qu'il choisisse d'utiliser ou de ne pas utiliser un index particulier. Les clauses \u00e0 placer dans votre requ\u00eate SELECT sont les suivantes: USE INDEX : utilise l'index pass\u00e9 en argument (MySQL ne l'utilisera pas si l'index est plus couteux qu'un full table scan) FORCE\u2026","rel":"","context":"Dans &quot;MySQL&quot;","block_context":{"text":"MySQL","link":"https:\/\/dasini.net\/blog\/category\/mysql\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1370,"url":"https:\/\/dasini.net\/blog\/2013\/01\/30\/full-table-scan-vs-full-index-scan-part2-2\/","url_meta":{"origin":1363,"position":1},"title":"Full table scan vs Full index scan part2-2","author":"Olivier DASINI","date":"30 janvier 2013","format":false,"excerpt":"2\/ FTS ou FIS Avant de r\u00e9pondre explicitement \u00e0 la question, un petit zoom sur l\u2019une des nombreuses nouveaut\u00e9s de MySQL 5.6. La commande EXPLAIN s\u2019est enrichie de la clause format=json. Elle permet d\u2019avoir une version un peu plus d\u00e9taill\u00e9e que l\u2019EXPLAIN classique. Query 1\/ EXPLAIN format=json SELECT d,avg(price) FROM\u2026","rel":"","context":"Dans &quot;optimisation&quot;","block_context":{"text":"optimisation","link":"https:\/\/dasini.net\/blog\/category\/optimisation\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":453,"url":"https:\/\/dasini.net\/blog\/2009\/02\/18\/optimisation-de-requetes-comprendre-loptimiseur-de-mysql\/","url_meta":{"origin":1363,"position":2},"title":"Optimisation de requ\u00eates: comprendre l&rsquo;optimiseur de MySQL","author":"Olivier DASINI","date":"18 f\u00e9vrier 2009","format":false,"excerpt":"Le but de cet article est d'optimiser une simple requ\u00eate (SELECT avg(Population) FROM city GROUP BY CountryCode) et surtout de comprendre comment l'optimiseur proc\u00e8de, en \u00e9tudiant les r\u00e9sultats donn\u00e9s par les variables qui permettent de surveiller le serveur MySQL.","rel":"","context":"Dans &quot;MySQL&quot;","block_context":{"text":"MySQL","link":"https:\/\/dasini.net\/blog\/category\/mysql\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1196,"url":"https:\/\/dasini.net\/blog\/2012\/02\/28\/attention-au-query-cache\/","url_meta":{"origin":1363,"position":3},"title":"Attention au query cache","author":"Olivier DASINI","date":"28 f\u00e9vrier 2012","format":false,"excerpt":"Selon le livre \u00abAudit & optimisation, MySQL 5 - \u00e9ditions Eyrolles\u00bb, le cache de requ\u00eates ou query cache est un syst\u00e8me de cache m\u00e9moire interne \u00e0 MySQL, transparent pour l'application, qui ne stocke que les requ\u00eates SELECT et leurs r\u00e9sultats. L'apport de ce cache est particuli\u00e8rement d\u00e9pendant de votre application.\u2026","rel":"","context":"Dans &quot;bench&quot;","block_context":{"text":"bench","link":"https:\/\/dasini.net\/blog\/category\/bench\/"},"img":{"alt_text":"dasini.net - MySQL query cache","src":"https:\/\/i0.wp.com\/dasini.net\/blog\/wp-includes\/images\/query_cache_on_VS_query_cache_off_im_tiny.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1593,"url":"https:\/\/dasini.net\/blog\/2016\/03\/02\/30-mins-avec-mysql-query-rewriter\/","url_meta":{"origin":1363,"position":4},"title":"30 mins avec MySQL Query Rewriter","author":"Olivier DASINI","date":"2 mars 2016","format":false,"excerpt":"Parfois des requ\u00eates probl\u00e9matiques tournent sur le serveur, mais il n'est pas possible de r\u00e9gler le probl\u00e8me \u00e0 la source (Requ\u00eates venant d'un ORM par example) MySQL 5.7 fournit une API pre et post parse query rewrite. Les utilisateurs peuvent \u00e9crire leurs propre plugins ce qui permet d'\u00e9liminer le besoin\u2026","rel":"","context":"Dans &quot;MySQL&quot;","block_context":{"text":"MySQL","link":"https:\/\/dasini.net\/blog\/category\/mysql\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":788,"url":"https:\/\/dasini.net\/blog\/2009\/10\/12\/mysql-query-cache\/","url_meta":{"origin":1363,"position":5},"title":"MySQL Query cache","author":"Olivier DASINI","date":"12 octobre 2009","format":false,"excerpt":"Le cache est toujours \u00e0 jour car en cas de modification d'une table, toutes les requ\u00eates en relations avec cette table sont invalid\u00e9es. Le cache de requ\u00eates est en g\u00e9n\u00e9ral utile lorsque: Les modifications sur les tables ne sont pas tr\u00e8s fr\u00e9quentes Beaucoup de requ\u00eates de lectures identiques Utilisation de\u2026","rel":"","context":"Dans &quot;MySQL&quot;","block_context":{"text":"MySQL","link":"https:\/\/dasini.net\/blog\/category\/mysql\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/comments?post=1363"}],"version-history":[{"count":5,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/1363\/revisions"}],"predecessor-version":[{"id":1367,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/posts\/1363\/revisions\/1367"}],"wp:attachment":[{"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/media?parent=1363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/categories?post=1363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dasini.net\/blog\/wp-json\/wp\/v2\/tags?post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}