mysql 语句优化心得
排序导致性能较慢
优化策略:1.尽量不使用排序 2.只查有索引的结果然后 内连接查询
select bizchance0_.* from biz_chance bizchance0_, biz_bizcustomer bizbizcust1_
where bizchance0_.uuid=bizbizcust1_.recordinfoid and bizchance0_.ispublic=1 order by bizchance0_.orderkey desc limit 0,10;
时间 33秒 order by 排序性能较慢 原因:select bizchance0_.* 如果只查select bizchance0_.uuid uuid带索引 性能提高
select bizchance0_.uuid as uid from biz_chance bizchance0_, biz_bizcustomer bizbizcust1_
where bizchance0_.uuid=bizbizcust1_.recordinfoid and bizchance0_.ispublic=1 order by bizchance0_.orderkey desc limit 0,10 ;
时间 3秒
select * from biz_chance as uu inner join (select bizchance0_.uuid as uid from biz_chance bizchance0_, biz_bizcustomer bizbizcust1_
where bizchance0_.uuid=bizbizcust1_.recordinfoid and bizchance0_.ispublic=1 order by bizchance0_.orderkey desc limit 0,10 ) as u on u.uid=uu.uuid
inner join biz_bizcustomer as cus on uu.uuid=cus.recordinfoid
综合 语句
2.筛选条件、顺序不对
select * from biz_customer as cus
left join biz_config400 as conf on conf.customerid=cus.uuid
left join biz_billinginfo as bill on bill.configid=conf.uuid and bill.customerid=cus.uuid
用时 15秒
原因:“and bill.customerid=cus.uuid ”
优化结果
select cus.* from biz_customer as cus
left join biz_config400 as conf on conf.customerid=cus.uuid
left join biz_billinginfo as bill on bill.configid=conf.uuid
where bill.customerid=cus.uuid or bill.uuid is null
或者
select cus.* from biz_customer as cus
left join biz_config400 as conf on conf.customerid=cus.uuid
left join biz_billinginfo as bill on bill.configid=conf.uuid
mysql 语句优化心得的更多相关文章
- Mysql语句优化
总结总结自己犯过的错,网上说的与自己的Mysql语句优化的想法. 1.查询数据库的语句的字段,尽量做到用多少写多少. 2.建索引,确保查询速度. 3.orm框架自带的方法会损耗一部分性能,这个性能应该 ...
- php代码优化,mysql语句优化,面试需要用到的
首先说个问题,就是这些所谓的优化其实代码标准化的建议,其实真算不上什么正真意义上的优化,还有一点需要指出的为了一丁点的性能优化,甚至在代码上的在一次请求上性能提升万分之一的所谓就去大面积改变代码习惯, ...
- MySql基础笔记(二)Mysql语句优化---索引
Mysql语句优化--索引 一.开始优化前的准备 一)explain语句 当MySql要执行一个查询语句的时候,它首先会对语句进行语法检查,然后生成一个QEP(Query Execution Plan ...
- mysql语句优化原则
有时候发现数据量大的时候查询起来效率就比较慢了,学习一下mysql语句优化的原则,自己在正常写sql的时候还没注意到这些,先记录下来,慢慢一点一点的学,加油! 这几篇博客写的都可以: https:// ...
- mysql语句优化总结(一)
Sql语句优化和索引 1.Innerjoin和左连接,右连接,子查询 A. inner join内连接也叫等值连接是,left/rightjoin是外连接. SELECT A.id,A.nam ...
- Mysql 语句优化技巧
前言 有人反馈之前几篇文章过于理论缺少实际操作细节,这篇文章就多一些可操作性的内容吧. 注:这篇文章是以 MySQL 为背景,很多内容同时适用于其他关系型数据库,需要有一些索引知识为基础. 优化目标 ...
- mysql语句优化方案(网上流传)
关于mysql处理百万级以上的数据时如何提高其查询速度的方法 最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法. 由于在参与的实际项目中发现当mysql表的数 ...
- Mysql语句优化建议
一.建立索引 1)考虑在 where 及 order by 涉及的列上建立索引 2)对于模糊查询, 建立全文索引 3)对于多主键查询,建立组合索引 二.避免陷阱 然而,一些情况下可能使索引无效: 1) ...
- Mysql 语句优化
通过 show status 命令了解各个 sql 语句的执行频率格式:Mysql> show [session | global] status;注:session 表示当前连接global ...
随机推荐
- sublime text 2 licence
----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...
- 【Linux下权限控制之chmod与chown命令】
chmod 用于配置文件/目录权限 命名格式:chmod [选项] 文件/目录名 . 权限类别: r 读取 可用数字4表示 w 写入 可用数字2表示 x 执行 可用数字1表示 . 归属类别: u 属主 ...
- 安装php-ldap模块
php-ldap模块作用就是实现ldap认证,因此需要安装 1.安装软件包解决依赖 yum install openldapyum install openldap-devel 2.拷贝库文件 cp ...
- 谈谈 Struts2 的拦截器
套话 相信非常多人都用过 Struts2 了,当然,对 Struts2 的原理也都比較了解.之前在一个项目中就已经用到了,当初的理解也不过局限在应用的层面上,对于更深层次的原理.机制,了解的并非非常多 ...
- leetCode 27.Remove Element (删除元素) 解题思路和方法
Remove Element Given an array and a value, remove all instances of that value in place and return th ...
- Android Studio升级到0.8.1后怎样设置字体大小?
升级到0.8.1后.打开设置字体大小页面.你会发现无论是Default还是Darcula,都不同意你改变字体的大小.事实上这个是由于这两个模式是Android Studio自带模式,所以不同意你修改, ...
- Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack.
1.错误描写叙述 八月 14, 2015 4:22:45 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error 严重: Excepti ...
- 关于TabLayout+ViewPager组合实现多页面滑动
转载请注明出处:http://blog.csdn.net/ht_android/article/details/46647711 在android提供的design library中新增了一个控件,叫 ...
- elasticsearch index 之merge
merge是lucene的底层机制,merge过程会将index中的segment进行合并,生成更大的segment,提高搜索效率.segment是lucene索引的一种存储结构,每个segment都 ...
- ShareSDk的使用
效果: 具体操作参考Mob官网shareSdk的文档 调用方法 public class MainActivity extends Activity { @Override protected voi ...