mysql>select*from big_data where id ='899999';+--------+------------+------+--------------------+| id | name | age | email |+--------+------------+------+--------------------+|899999| test899998 |5| test899998@163.com|+--------+------------+------+--------------------+1rowinset(0.01 sec)
mysql>select*from big_data where name ='999999';
Empty set(0.22 sec)
mysql>select*from big_data where email ='test999999@163.com';+---------+------------+------+--------------------+| id | name | age | email |+---------+------------+------+--------------------+|1000000| test999999 |9| test999999@163.com|+---------+------------+------+--------------------+1rowinset(0.25 sec)
以上可以看出,主键id查询明显速度更快
查询指定字段和查询全量对比
# name创建索引前
mysql>select name from big_data where name ='test999999';+------------+| name |+------------+| test999999 |+------------+1rowinset(0.19 sec)
mysql>select*from big_data where name ='test999999';+---------+------------+------+--------------------+| id | name | age | email |+---------+------------+------+--------------------+|1000000| test999999 |9| test999999@163.com|+---------+------------+------+--------------------+1rowinset(0.24 sec)
mysql>select email from big_data where email ='test999999@163.com';+--------------------+| email |+--------------------+| test999999@163.com|+--------------------+1rowinset(0.19 sec)
mysql>select*from big_data where email ='test999999@163.com';+---------+------------+------+--------------------+| id | name | age | email |+---------+------------+------+--------------------+|1000000| test999999 |9| test999999@163.com|+---------+------------+------+--------------------+1rowinset(0.25 sec)
以上可以看出,指定字段查询比全量数据查询速度略快
创建索引前后查询对比
# 创建索引前
mysql>select name from big_data where name ='test999999';+------------+| name |+------------+| test999999 |+------------+1rowinset(0.19 sec)
mysql>select*from big_data where name ='test999999';+---------+------------+------+--------------------+| id | name | age | email |+---------+------------+------+--------------------+|1000000| test999999 |9| test999999@163.com|+---------+------------+------+--------------------+1rowinset(0.24 sec)
# 创建索引createindex index_name on big_data(name);# name创建索引后
mysql>select name from big_data where name ='test999999';+------------+| name |+------------+| test999999 |+------------+1rowinset(0.00 sec)
mysql>select*from big_data where name ='test999999';+---------+------------+------+--------------------+| id | name | age | email |+---------+------------+------+--------------------+|1000000| test999999 |9| test999999@163.com|+---------+------------+------+--------------------+1rowinset(0.00 sec)
以上可以看出,指定索引查询比无索引查询速度明显要快。
mysql使用精准数据类型查询对比
mysql>select*from big_data where age =44;19841rowsinset(0.22 sec)
mysql>select*from big_data where age ='44';19841rowsinset(0.22 sec)# 通过age ='44abc'搜索,实际搜索age = 44select*from big_data where age ='44abc';19841rowsinset(0.22 sec)# 通过age ='44abc'搜索,实际搜索age = 0select*from big_data where age ='abc44';10160rowsinset,1 warning (0.22 sec)