MySQL Federated Index Test 2

Source: Internet
Author: User

To the next article:

Http://www.cnblogs.com/xiaoit/p/4430300.html

1: First delete the previous established index and re-establish one.

Mysql> DROP INDEX idx1 on Tab_index; Query OK, rows affected (0.01 sec) records:55  duplicates:0  warnings:0

  

Mysql> ALTER TABLE tab_index,    ADD index idx2 (age,dte); Query OK, rows affected (0.01 sec) records:55  duplicates:0  warnings:0

  

The test results according to the previous article should be:

(age) Walk the index with the shortest index length
(age,id) walk index with shortest index length

(age,dte) Go index, and the index length is the longest
(id,age,dte) Go index, and the index length is the longest
(id,dte,age) Go index, and the index length is the longest
(dte,id,age) Go index, and the index length is the longest
(dte,age,id) Go index, and the index length is the longest
(age,dte,id) Go index, and the index length is the longest
(age,id,dte) Go index, and the index length is the longest

Re-test look under:

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE age=31;+----+-------------+-----------+- -----+---------------+------+---------+-------+------+-------------+| ID | Select_type | Table     | type | possible_keys | key  | key_len | ref   | rows | Extra       |+----+-------------+-----------+------+---------------+------+---------+-------+------+------------- +|  1 | Simple      | tab_index | ref  | IDX2          | idx2 | 5       | const |    1 | Using where |+----+-------------+-----------+------+---------------+------+---------+-------+------+------------ -+1 row in Set (0.01 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE age=31 and id=3;+----+-------------+------ -----+------+---------------+------+---------+-------+------+-------------+| ID | Select_type | Table     | type | possible_keys | key  | key_len | ref   | rows | Extra       |+----+-------------+-----------+------+---------------+------+---------+-------+------+------------- +|  1 | Simple      | tab_index | ref  | IDX2          | idx2 | 5       | const |    1 | Using where |+----+-------------+-----------+------+---------------+------+---------+-------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE age=31 and DTE between ' 2011-05-13 00:00:00 ' and ' 2013-05-13 00:00:00 ', +----+-------------+-----------+-------+---------------+------+---------+------+------ +-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE id=3 and DTE between ' 2011-05-13 00:00:00 ' an D ' 2013-05-13 00:00:00 ' and age=31;+----+-------------+-----------+-------+---------------+------+---------+------ +------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE id=3 and age=31 and DTE between ' 2011-05-13 0 0:00:00 ' and ' 2013-05-13 00:00:00 ' +----+-------------+-----------+-------+---------------+------+---------+----- -+------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    Tab_index,    WHERE DTE between ' 2011-05-13 00:00:00 ' and ' 2013-0 5-13 00:00:00 ' and id=3 and  age=31;+----+-------------+-----------+-------+---------------+------+---------+-- ----+------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    Tab_index,    WHERE DTE between ' 2011-05-13 00:00:00 ' and ' 2013-0 5-13 00:00:00 ' and age=31 and id=3;+----+-------------+-----------+-------+---------------+------+---------+------+ ------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE id=3 and DTE between ' 2011-05-13 00:00:00 ' an D ' 2013-05-13 00:00:00 ' and age=31;+----+-------------+-----------+-------+---------------+------+---------+------ +------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE id=3 and DTE between ' 2011-05-13 00:00:00 ' an D ' 2013-05-13 00:00:00 ' and age=31;+----+-------------+-----------+-------+---------------+------+---------+------ +------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE age=31 and id=3 and DTE between ' 2011-05-13 0 0:00:00 ' and ' 2013-05-13 00:00:00 '  +----+-------------+-----------+-------+---------------+------+---------+ ------+------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

Mysql> EXPLAIN SELECT id,dte,age, from    tab_index,    WHERE age=31 and DTE between ' 2011-05-13 00:00:00 ' and ' 2013-05-13 00:00:00 ' and id=3, +----+-------------+-----------+-------+---------------+------+---------+------ +------+-------------+| ID | Select_type | Table     | type  | possible_keys | key  | key_len | ref  | rows | Extra       |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------- +|  1 | Simple      | tab_index | range | idx2          | idx2 |      NULL |    1 | Using where |+----+-------------+-----------+-------+---------------+------+---------+------+------+------------ -+1 row in Set (0.00 sec)

  

The conclusion is correct!

Because questioning today's interviewer's conclusion, go home and do a test, the decisive interviewer is not careful enough. Tomorrow if you call to confirm the number of the call to think again ...

MySQL Federated Index Test 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.