mysql哪些语句使用了索引呢
2016-06-13 18:34
543 查看
------为表中的字段增加默认值语法--
alter table account modify income int(10) not null default '0';
------mysql哪些语句使用了索引呢?
mysql> explain select * from account where income between 6000000 and 7000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>6000000 and income<7000000;
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | account | range | income | income | 4 | NULL | 1 | Using index condition |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>=6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income<6000000;
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | account | range | income | income | 4 | NULL | 2 | Using index condition |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income<=6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
可以看出,使用<号使用了索引,
< and > 也使用了索引
=号用了索引
alter table account modify income int(10) not null default '0';
------mysql哪些语句使用了索引呢?
mysql> explain select * from account where income between 6000000 and 7000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>6000000 and income<7000000;
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | account | range | income | income | 4 | NULL | 1 | Using index condition |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income>=6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income<6000000;
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
| 1 | SIMPLE | account | range | income | income | 4 | NULL | 2 | Using index condition |
+----+-------------+---------+-------+---------------+--------+---------+------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain select * from account where income<=6000000;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | account | ALL | income | NULL | NULL | NULL | 6 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
可以看出,使用<号使用了索引,
< and > 也使用了索引
=号用了索引
相关文章推荐
- 查看MySQL配置文件路径及相关配置
- Mysql5.6.23免安装配置
- saiku迁移到本地数据库mysql
- MySQL数据库表设计优化
- MySQL 5.7.10 绿色版的精简安装与C语言编程
- Node.js的Koa框架上手及MySQL操作指南
- Mysql主从不同步问题处理案例 推荐
- mysql查询优化--临时表和文件排序(Using temporary; Using filesort问题解决)
- MySQL多列索引
- mysql 中文乱码的解决方法
- mysql安装详情
- MySQL数据库中备份相关的两种工具--mysqlbinlog和mysqldump使用详解
- Can't connect to local MySQL server through socket 问题解决
- mysql 崩溃
- SQLServer、MySQL存储过程的参数以及存储过程中变量区别,@
- MySQL 触发器简单实例
- MySQL数据库备份和恢复
- MYSQLl查询今天、昨天、7天、近30天、本月、上一月 数据
- MySQL relay log 详细参数解释
- MySQL数据库设置主从同步