现在有个测试表
一个表是user,大概20W数据,另一个表是user_oper,大概3W
user(id,name,sex,birthday),user_oper(id,uid,arm,oper)
现在要查询出user_oper表的记录,但要知道用户名的名字,user_oper表uid是索引我写的是这样的
select a.*,b.name from user_oper a,user b where a.uid = b.id;查询完,速度0.203sselect a.*,b.name from user_oper a left join user b on a.uid = b.id;这2个sql运行速率差不多
还有没有能改进查询速度快mysql查询优化
一个表是user,大概20W数据,另一个表是user_oper,大概3W
user(id,name,sex,birthday),user_oper(id,uid,arm,oper)
现在要查询出user_oper表的记录,但要知道用户名的名字,user_oper表uid是索引我写的是这样的
select a.*,b.name from user_oper a,user b where a.uid = b.id;查询完,速度0.203sselect a.*,b.name from user_oper a left join user b on a.uid = b.id;这2个sql运行速率差不多
还有没有能改进查询速度快mysql查询优化
解决方案 »
- 关于mysql order索引问题
- MYSQL 5.5 完全一样的代码改成存储过程却运行结果不正确,请高手帮忙
- mysql去除一张表中的重复数据问题,求高手!
- mobile 平台上远程连接mysql的问题
- MySQL 主表对应多表查询优化
- 请问想查询mysql数据库的服务名字,应如何操作?若想查询某个数据库服务内的所有表名,又该如何操作?
- 求助,Berkeley DB 生成的数据文件要用什么工具来查看?????
- 导入数据库大小有限制么
- ++++++++请问一个sql查询语句?
- 请教关于MySQL字符串
- 求一条SQL执行语句,试了半天,还是不行!
- INSERT INTO 'order' (id,pid,cid,state) VALUES (NULL, '6','crew1','work in progre
2、你的两个查询逻辑是不一样的,数据也应该不一样的,其实没有可比性,第一个查询可以改写为:
select a.*,b.name from user_oper a inner join user b on a.uid = b.id;
from user_oper a
INNER JOIN [user] b --id字段应该是主键
ON a.[uid] = b.id
where a.NAME = 'xxx' --#1.name字段建立索引--如果没有WHERE中的条件,两个语句的差别在于:第一个是INNER JOIN,第二个是LEFT JOIN
--如果[user]表中的id数据在user_oper表中不存在,那么第一个效率会高,同时,他们查询出来的结果集是不一样的