mysql> CREATE INDEX idx_username ON users(username); Query OK, 1 row affected (0.15 sec) Records: 1 Duplicates: 0 Warnings: 0 |
mysql> SHOW INDEX FROM users; | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | | users | 1 | idx_username | 1 | username | A | NULL | NULL | NULL | YES | BTREE | | 1 row in set (0.00 sec) |
mysql> EXPLAIN SELECT city.name, city.district FROM city, country WHERE city.countrycode = country.code AND country.code = 'IND'; | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | 1 | SIMPLE | country | const | PRIMARY | PRIMARY | 3 | const | 1 | Using index | | 1 | SIMPLE | city | ALL | NULL | NULL | NULL | NULL | 4079 | Using where | |
mysql> CREATE INDEX idx_ccode ON city(countrycode); Query OK, 4079 rows affected (0.15 sec) Records: 4079 Duplicates: 0 Warnings: 0 |
以下是引用片段: mysql> EXPLAIN SELECT city.name, city.district FROM city, country WHERE city.countrycode = country.code AND country.code = 'IND'; | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | 1 | SIMPLE | country | const | PRIMARY | PRIMARY | 3 | const | 1 | Using index | | 1 | SIMPLE | city | ref | idx_ccode | idx_ccode | 3 | const | 333 | Using where | 2 rows in set (0.01 sec) |
欢迎光临 DIY编程器网 (http://diybcq.com/) | Powered by Discuz! X3.2 |