[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: составные индексы
dvs
Добрый день! Подскажите пожалуйста почему при разных user, берутся разные index-ы? Запросы отличаются только разными user.

mysql> EXPLAIN SELECT `id` FROM `busines` WHERE `user` = 53 AND `status` IN ('','finish') AND `date_from` <= 1458214920 AND `date_to` >= 1458214920;
+
----+-------------+---------+-------+--------------------------------------+------+---------+------+ ------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+--------------------------------------+------+---------+------ +------+--------------------------+
| 1 | SIMPLE | busines | range | status,date_from,date_to,user,user_2 | user | 9 | NULL | 2 | Using where; Using index |
+----+-------------+---------+-------+--------------------------------------+------+---------+------ +------+--------------------------+
1 row in set (0.00 sec)

mysql> EXPLAIN SELECT `id` FROM `busines` WHERE `user` = 51 AND `status` IN ('','finish') AND `date_from` <= 1458214920 AND `date_to` >= 1458214920;
+----+-------------+---------+-------+--------------------------------------+--------+---------+---- --+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+--------------------------------------+--------+---------+---- --+------+-------------+
| 1 | SIMPLE | busines | range | status,date_from,date_to,user,user_2 | user_2 | 9 | NULL | 142 | Using where |
+----+-------------+---------+-------+--------------------------------------+--------+---------+---- --+------+-------------+
1 row in set (0.18 sec)

mysql> SHOW INDEX FROM `busines`;
+---------+------------+-----------+--------------+-------------+-----------+-------------+--------- -+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+-----------+--------------+-------------+-----------+-------------+--------- -+--------+------+------------+---------+---------------+
| busines | 0 | PRIMARY | 1 | id | A | 4651 | NULL | NULL | | BTREE | | |
| busines | 1 | status | 1 | status | A | 2 | NULL | NULL | | BTREE | | |
| busines | 1 | date_from | 1 | date_from | A | 2325 | NULL | NULL | | BTREE | | |
| busines | 1 | date_to | 1 | date_to | A | 2325 | NULL | NULL | | BTREE | | |
| busines | 1 | client | 1 | client | A | 2325 | NULL | NULL | | BTREE | | |
| busines | 1 | code | 1 | code | A | 4651 | NULL | NULL | | BTREE | | |
| busines | 1 | user | 1 | user | A | 54 | NULL | NULL | | BTREE | | |
| busines | 1 | user | 2 | status | A | 83 | NULL | NULL | | BTREE | | |
| busines | 1 | user | 3 | date_from | A | 4651 | NULL | NULL | | BTREE | | |
| busines | 1 | user | 4 | date_to | A | 4651 | NULL | NULL | | BTREE | | |
| busines | 1 | user_2 | 1 | user | A | 26 | NULL | NULL | | BTREE | | |
| busines | 1 | user_2 | 2 | status | A | 40 | NULL | NULL | | BTREE | | |
| busines | 1 | user_2 | 3 | date_to | A | 4651 | NULL | NULL | | BTREE | | |
+---------+------------+-----------+--------------+-------------+-----------+-------------+--------- -+--------+------+------------+---------+---------------+
13 rows in set (0.00 sec)

Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.