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 ...
随机推荐
- Huawei配置两台交换机堆叠示例
配置两台交换机堆叠示例(先配置后连线方式,推荐) 一.基本概念 在堆叠中,有以下一些基本概念,如图1所示.图1 堆叠基本概念示意图 1. 角色堆叠中的单台交换机称为成员交换机,按照功能不同可以分为以下 ...
- 虚拟摄像头vivi的测试(二)
(前一部分的基础操作来源于作者:LingXiaokai 的 Ubuntu 9.10 下如何使用笔记本摄像头以及虚拟摄像头vivi的测试) 自己仅对实际操作中需要注意的点进行阐述 一.先在Ubuntu ...
- RocketMQ 就是耗内存
http://blog.csdn.net/loongshawn/article/details/51086876 https://rocketmq.incubator.apache.org/docs/ ...
- <LeetCode OJ> 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- Torch 的安装与基本用法
本文安装仅限 ubuntu 系统.官方文档见:Getting started with Torch. 0. 简介 Torch 使用轻量级脚本语言 Lua 及其 C/CUDA 扩展模块实现,底层数值计算 ...
- CSU 1046 追杀
Description 在一个8行9列的国际象棋棋盘上,有一名骑士在追杀对方的国王.该骑士每秒跨越一个2*3的区域,如下图所示. 而对方的国王慌忙落逃,他先沿着右下斜线方向一直跑,遇到边界以后会沿着光 ...
- Mysql学习总结(16)——Mysql之数据库设计规范
一.三大范式 1.第一范式:消除一个字段包含多个数据库值,消除一个记录包含重复的组(单独的一列包含多个项目),即可满足1NF. 2.第二范式:消除部分依赖性即可转化为2NF.部分依赖性表示一个记录中包 ...
- oracle取随机结果测试
http://www.2cto.com/database/201307/227524.html
- hdu2768Cat vs. Dog (反建法,最大独立集)
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- Funui-Theme 资源的替换
实现资源的替换,需要分为以下几个步骤 1.找到需要更改的模块 mediatek/packages/apps/FileManager 2.到主题模块下根据包名找到相应资源(以Grass为例) cd ve ...