
Paste_Image.png
考官考點
查找分析查詢速度慢的原因
優(yōu)化查詢過程中的數(shù)據(jù)訪問
游湖長難的查詢語句
游湖特定類型的查詢語句
分析SQL查詢慢的方法
記錄慢查詢?nèi)罩?br>
分析查詢?nèi)罩荆灰苯哟蜷_慢查詢?nèi)罩具M行分析,這樣比較浪費時間和經(jīng)理,可以使用pt-query-digest工具進行分析

Paste_Image.png

Paste_Image.png

Paste_Image.png
是作為我們的一個計數(shù)器

Paste_Image.png
觀察不正常的進程
explain,非常重要,他可以幫我們肥西單條語句。
查詢的行數(shù)等等


Paste_Image.png

Paste_Image.png
優(yōu)化查詢過程中的數(shù)據(jù)訪問
訪問太多數(shù)據(jù)導(dǎo)致查詢性能下降
確定應(yīng)用程序是否在檢索大量超過需要的數(shù)據(jù),可能是太多行或列
避免使用如下SQL語句
查詢不需要的記錄,使用limit解決

Paste_Image.png
重復(fù)查詢相同的數(shù)據(jù),可以緩存數(shù)據(jù),下次直接讀取緩存。

Paste_Image.png
比如,我只需要5行數(shù)據(jù),但是卻掃描了200行數(shù)據(jù),,剩下的數(shù)據(jù)就白掃了。
加索引,就能解決這個問題

Paste_Image.png
如果我是第三范式,我經(jīng)常查 連表查詢,我可以把一個表,冗余到另一個表里面。。。
可以用空間來換取我們的時間


Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
所以,不要使用 count(列名)

Paste_Image.png

Paste_Image.png
沒有索引,一定要建立索引。

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png

Paste_Image.png
先定位,,那些SQL語句,會比較慢,根據(jù)前面的四種方案,
查詢?nèi)罩?br>
show profile
show processlist
show status
explain
先從索引的監(jiān)督考慮,索引沒問題的話,
再從數(shù)據(jù)訪問的角度來分析,

Paste_Image.png