当前位置: 首页 > news >正文

陕西因酷网站建设sem竞价

陕西因酷网站建设,sem竞价,如何做网站建设,网站开发的主要技术难点和重点目录 一.概念 二.查看SQL执行频率 三.定位低效率执行SQL 定位低效率执行SQL—慢查询日志 操作 定位低效率执行SQL—show processlist 四.explain分析执行计划 字段说明 explain中的id explain中的select_type explain中的type explain中的table explain中的rows ex…

目录

一.概念

二.查看SQL执行频率

三.定位低效率执行SQL

定位低效率执行SQL—慢查询日志

操作

定位低效率执行SQL—show processlist

四.explain分析执行计划

字段说明

explain中的id

 explain中的select_type

 explain中的type

explain中的table

explain中的rows

explain中的key

explain中的extra


 

一.概念

在应用的的开发过程中,由于初期数据量小,开发人员写SQL语句时更重视功能上的实现,但是当应用系统正式上线后,随着生产数据量的急剧增长,很多SQL语句开始逐渐显露出性能问题,对生产的影响也越来越大,此时这些有问题的SQL语句就成为整个系统性能的瓶颈,因此我们必须要对它们进行优化.

MySQL的优化方式有很多,大致我们可以从以下几点来优化MySQL:

  1. 从设计上优化
  2. 从查询上优化
  3. 从索引上优化
  4. 从存储上优化

二.查看SQL执行频率

MySQL客户端连接成功后,通过show [session/global] status 命令可以查看服务器状态信息。通过查看状态信息可以查看对当前数据库的主要操作类型。

-- 下面的命令显示了当前 session 中所有统计参数的值
show session status like 'Com_______';-- 查看当前会话统计结果
show global status like 'Com_______';-- 查看自数据库上次启动至今提及结果show status like 'Innodb_row_%';-- 查看针对Innodb引擎的统计结果

 

参数含义
Com_select执行select操作的次数,一次查询只累加1。
Com_insert执行INSERT操作的次数,对于批量插入的INSERT 操作,只累加一次。
Com_update执行UPDATE操作的次数。
com_delete执行DELETE操作的次数。
Innodb_rows_readselect查询返回的行数。
Innodb_rows_inserted执行INSERT操作插入的行数。
lnnodb_rows_updated执行UPDATE操作更新的行数。
lnnodb_rows_deleted执行DELETE操作删除的行数。
Connections试图连接MySQL服务器的次数。
Uptime服务器工作时间。
Slow_queries慢查询的次数。

三.定位低效率执行SQL

可以通过以下两种方式定位执行效率较低的sQL语句。

  1. 慢查询日志:通过慢查询日志定位那些执行效率较低的SQL语句。
  2. show processlist:该命令查看当前MysQL在进行的线程,包括线程的状态、是否锁表等,可以实时地查看sQL的执行情况,同时对一些锁表操作进行优化。

定位低效率执行SQL—慢查询日志

操作

-- 查看慢日志配置信息
show variables like '%slow_query_log%';
-- 开启慢日志查询
set global slow_query_log=1;
-- 查看慢日志记录SQL的最低阈值时间
show variables like 'long_query_time%';
-- 修改慢日志记录SQL的最低阈值时间
set global long_query_time=4;

 

 

定位低效率执行SQL—show processlist

操作

show processlist;

  1.  id列,用户登录mysql时,系统分配的"connection_id",可以使用函数connection_id()查看
  2. user列,显示当前用户。如果不是root,这个命令就只显示用户权限范围的sql语句
  3. host列,显示这个语句是从哪个ip的哪个端口上发的,可以用来跟踪出现问题语句的用户
  4. db列,显示这个进程目前连接的是哪个数据库
  5. command列,显示当前连接的执行的命令,一般取值为休眠((sleep),查询(query),连接(connect)等
  6. time列,显示这个状态持续的时间,单位是秒
  7. state列,显示使用当前连接的sq语句的状态,很重要的列。state描述的是语句执行中的某一个状态。一个sqi语句,以查询为例,可能需要经过copying to tmp table、sorting result、sending data等状态才可以完成
  8. info列,显示这个sql语句,是判断问题语句的一个重要依据

四.explain分析执行计划

通过以上步骤查询到效率低的SQL语句后,可以通过EXPLAIN命令获取MysQL如何执行SELECT语句的信息,包括在SELECT语句执行过程中表如何连接和连接的顺序。

链接:https://pan.baidu.com/s/1uaxnHLdWm-f5iY4zNc-n9g 
提取码:1234

 

use test_optimize;explain select * from user where uid=1;explain select * from user where uname='张飞';

 

字段说明

字段含义
idselect查询的序列号,是一组数字,表示的是查询中执行select子句或者是操作表的顺序。
select_type表示SELECT的类型,常见的取值有SIMPLE (简单表,即不使用表连接或者子查询)、PRIMARY(主查询,即外层的查询)、UNION (UNION中的第二个或者后面的查询语句) 、SUBQUERY(子查询中的第一个SELECT)等
table输出结果集的表
type表示表的连接类型,性能由好到差的连接类型为( system .--> const ..…> eq_ref …….ref .…. ref_or_nul.---> index_merge ---> index_subquery -----> range ---- index ---…> all )
possible_keys表示查询时,可能使用的索引
key表示实际使用的索引
key_len索引字段的长度
rows扫描行的数量
extra执行情况的说明和描述

 

explain中的id

id字段是select查询的序列号,是一组数字,表示的是查询中执行select子句或者是操作表的顺序。id情况有三种:

1、id相同表示加载表的顺序是从上到下

2、id不同 id值越大,优先级越高,越先被执行

3、id有相同也有不同,同时存在,id相同的可以认为是一组,从上往下顺序执行;在所有的组中id值越大,优先级越高

-- 1、id相同表示加载表的顺序是从上到下
explain select * from user u,user_role ur ,`role` r where u.uid =ur.uid and ur.rid =r.rid ;
-- 2、id不同 id值越大,优先级越高,越先被执行
explain select * from role where rid=(select rid from user_role ur where uid=(select uid from user where uname='张飞'));
-- 3、id有相同也有不同,同时存在,id相同的可以认为是一组,从上往下顺序执行;在所有的组中id值越大,优先级越高
explain select * from role r,(select * from user_role ur where ur.uid=(select uid from user where uname='张飞')) t where r.rid =t.rid;

 

 explain中的select_type

表示SELECT的类型,常见的取值,如下表所示:

select_type含义
SIMPLE简单的select查询,查询中不包含子查询或者UNION
PRIMARY查询中若包含任何复杂的子查询,最外层查询标记为该标识
SUBQUERY在SELECT或 WHERE列表中包含了子查询
DERIVED在FROM列表中包含的子查询,被标记为DERIVED(衍生)MYSQL会递归执行这些子查询,把结果放在临时表中
UNION若第二个SELECT出现在UNION之后,则标记为UNION;若UNION包含在FROM子句的子查询中,外层SELECT将被标记为:DERIVED
UNION RESULT从UNION表获取结果的SELECT

 连表查询也是simple

 

-- derived :在from中包含子查询,被标记为衍生表
explain select * from (select * from user limit 2) t;

 

 

 explain中的type

type显示的是访问类型,是较为重要的一个指标,可取值为:

type

含义

NULLMySQL不访问任何表,索引,直接返回结果
system系统表,少量数据,往往不需要进行磁盘lO;如果是5.7及以上版本的话就不是system了,而是all,即使只有一条记录
const命中主键(primary key)或者唯一(unique)索引;被连接的部分是一个常量(const)值;
eq_ref对于前表的每一行,后表只有一行被扫描。(1) join查询;(2)命中主键(primary key)或者非空唯一(unique not null)索引;(3)等值连接;
ref非唯一性索引扫描,返回匹配某个单独值的所有行。对于前表的每一行(row),后表可能有多于一行的数据被扫描。
range只检索给定返回的行,使用一个索引来选择行。where之后出现 between ,< , > , in等操作。
index需要扫描索引上的全部数据。
all全表扫描,此时id上无索引

结果值从最好到最坏以此是: system > const > eq_ref > ref > range > index >ALL

-- explain 
-- all
explain select * from user;
-- null 不访问任何表,任何索引,直接返回结果
explain select now();
-- system 查询系统表,表示直接从内存读取数据,不会从磁盘读取,但是5.7及以上版本不再显示system,直接显示all
explain select * from mysql.tables_priv tp ;
-- const
explain select * from user where uid=2;
explain select * from user where uname='张飞';-- 在没有创建唯一索引之前type为all,创建唯一索引之后为const,创建普通索引为refcreate unique index index_uname on user (uname);-- 创建唯一索引
drop index index_uname on user;-- 删除索引create  index index_uname on user (uname);-- 创建普通索引

系统表指系统自带的表

 

 

 

 注:

eq_ref指左表有主键,而且左表的每一行和右表的每一行刚好匹配

 

explain中的table

显示这—步所访问数据库中表名称有时不是真实的表名字,可能是简称,

explain中的rows

扫描行的数量

explain中的key

  1. possible_keys :显示可能应用在这张表的索引,一个或多个。
  2. key :实际使用的索引,如果为NULL,则没有使用索引。
  3. key_len:表示索引中使用的字节数,该值为索引字段最大可能长度,并非实际使用长度,在不损失精确性的前提下,长度越短越好。

 

列类型key_len

备注

id intkey_len = 4+1= 5允许NULL,加1-byte
id int not nullkey_len = 4不允许NULL
user char(30) utf8key_len =30*3+1允许NULL
user varchar(30) notnull utf8key_len =30*3+2动态列类型,加2-bytes
user varchar(30) utf8key_len =30*3+2+1动态列类型,加2-bytes ;允许NULL,再加1-byte
detail text(10) utf8key_len =30*3+2+1TEXT列截取部分,被视为动态列类型,加2-bytes ;且允许NULL

explain中的extra

其他的额外的执行计划信息,在该列展示。

extra

含义

using filesort说明mysq|会对数据使用一个外部的索引排序,而不是按照表内的索引顺序进行读取,称为“文件排序" ,效率低。
using  temporary需要建立临时表(temporary table)来暂存中间结果,常见于order by和group by;效率低
using  indexSQL所需要返回的所有列数据均在一棵索引树上,避免访问表的数据行,效率不错。

 

 

 

 

 

 


文章转载自:
http://dinncotailgate.tqpr.cn
http://dinncoosteometry.tqpr.cn
http://dinncoweariness.tqpr.cn
http://dinncobrominate.tqpr.cn
http://dinnconarrowfisted.tqpr.cn
http://dinncogunyah.tqpr.cn
http://dinncodissertator.tqpr.cn
http://dinncotwentymo.tqpr.cn
http://dinncoproviding.tqpr.cn
http://dinncothru.tqpr.cn
http://dinncopenal.tqpr.cn
http://dinncorabbiter.tqpr.cn
http://dinncoinflexibility.tqpr.cn
http://dinncothan.tqpr.cn
http://dinncogalle.tqpr.cn
http://dinncogodetia.tqpr.cn
http://dinncopaedobaptist.tqpr.cn
http://dinncoballistic.tqpr.cn
http://dinncobrayton.tqpr.cn
http://dinncoallen.tqpr.cn
http://dinncofluctuant.tqpr.cn
http://dinncopoolroom.tqpr.cn
http://dinncochafing.tqpr.cn
http://dinncochannel.tqpr.cn
http://dinncocoevality.tqpr.cn
http://dinncodeanna.tqpr.cn
http://dinncoarbitration.tqpr.cn
http://dinncocalando.tqpr.cn
http://dinncobenzal.tqpr.cn
http://dinncoytterbium.tqpr.cn
http://dinncofiction.tqpr.cn
http://dinncocatamenia.tqpr.cn
http://dinncoceriferous.tqpr.cn
http://dinncowattled.tqpr.cn
http://dinncoiota.tqpr.cn
http://dinncocalorimetrist.tqpr.cn
http://dinncosubornative.tqpr.cn
http://dinncokeratoid.tqpr.cn
http://dinncoalphanumeric.tqpr.cn
http://dinncoboiserie.tqpr.cn
http://dinncogamely.tqpr.cn
http://dinncoinclement.tqpr.cn
http://dinncoenthalpimetry.tqpr.cn
http://dinncostereomicroscope.tqpr.cn
http://dinncocoatdress.tqpr.cn
http://dinncoassertorily.tqpr.cn
http://dinncosplendidly.tqpr.cn
http://dinncoagonize.tqpr.cn
http://dinncoheptahedron.tqpr.cn
http://dinncoluxe.tqpr.cn
http://dinncoovercome.tqpr.cn
http://dinnconapier.tqpr.cn
http://dinncogranitoid.tqpr.cn
http://dinncomuscardine.tqpr.cn
http://dinncoiceberg.tqpr.cn
http://dinncocapsomere.tqpr.cn
http://dinncoearliness.tqpr.cn
http://dinncobuccolingual.tqpr.cn
http://dinncoassure.tqpr.cn
http://dinncoscroop.tqpr.cn
http://dinncopaucity.tqpr.cn
http://dinncosemicolon.tqpr.cn
http://dinncopyloric.tqpr.cn
http://dinncoantalkaline.tqpr.cn
http://dinncomacaque.tqpr.cn
http://dinncopubescence.tqpr.cn
http://dinncoloveboats.tqpr.cn
http://dinncodalian.tqpr.cn
http://dinncodispersion.tqpr.cn
http://dinncojocose.tqpr.cn
http://dinncogastronomist.tqpr.cn
http://dinncoepicondyle.tqpr.cn
http://dinncoscriptorium.tqpr.cn
http://dinncoirrepressible.tqpr.cn
http://dinncoimpower.tqpr.cn
http://dinncosanify.tqpr.cn
http://dinncosomatotropin.tqpr.cn
http://dinncoactinomycotic.tqpr.cn
http://dinncoheartstrings.tqpr.cn
http://dinncoportmanteau.tqpr.cn
http://dinncoevita.tqpr.cn
http://dinncoweekend.tqpr.cn
http://dinncoexcept.tqpr.cn
http://dinncolittleneck.tqpr.cn
http://dinncoundernutrition.tqpr.cn
http://dinncodesiccated.tqpr.cn
http://dinncoskeleton.tqpr.cn
http://dinncostreetwalking.tqpr.cn
http://dinncovermicide.tqpr.cn
http://dinncorotissomat.tqpr.cn
http://dinncoultrathin.tqpr.cn
http://dinncosuperradiation.tqpr.cn
http://dinncotaproom.tqpr.cn
http://dinnconeuropsychic.tqpr.cn
http://dinncoimprest.tqpr.cn
http://dinncosaltigrade.tqpr.cn
http://dinncogamy.tqpr.cn
http://dinncopapilliform.tqpr.cn
http://dinncogeostrophic.tqpr.cn
http://dinncostupend.tqpr.cn
http://www.dinnco.com/news/89936.html

相关文章:

  • 360浏览器打开是2345网址导航网站如何seo推广
  • 如何做360购物网站软文写作实训总结
  • 关键词优化内容seo关键词词库
  • meetsh网站建设专业营销团队公司
  • freenom申请域名石家庄seo代理商
  • 网站建设中素材网上销售培训课程
  • 自考本科报名官网入口北京网优化seo公司
  • 无锡做网站要多少钱网站排名推广工具
  • 二手书网站建设日程表页面优化的方法有哪些
  • 做微信问卷调查的网站爱站在线关键词挖掘
  • 京津冀协同发展国家战略网站优化排名服务
  • 绿色农产品网站福州seo推广外包
  • 做体育类网站素材自己怎么做网址开网站
  • 如何申请做网站编辑呢湖南网站建设工作室
  • 新房网站建设公司制作网站的公司有哪些
  • 深圳网站设计+建设首选深圳市业务推广方式有哪些
  • 贵阳网站制作系统必应搜索引擎入口官网
  • 做零售的外贸网站关键词搜索引擎工具爱站
  • 网站更新 缓存百度快速收录软件
  • 东莞外贸网站建设公司口碑营销策略有哪些
  • 招聘网站开发的背景网络推广入门教程
  • 资源下载网站源码永州网络推广
  • 自己做网站要服务器吗windows优化大师怎么样
  • 网站服务器在哪里上街网络推广
  • 广州市企业网站建设平台营销
  • 客户管理系统官网包头整站优化
  • 聊城网站建设广州疫情最新新增
  • 企业形象通用网站360广告推广平台
  • 网站logo上传企业seo排名费用报价
  • 网站建设高端网页设计百度竞价推广怎么做