[PostgreSQL] - explain SQL分析介紹

一、圖形化在線分析工具

https://explain.dalibo.com/

二、執(zhí)行分析語(yǔ)句

EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)
select * from ...

生成分析JSON之后,填入圖形化分析頁(yè)面,進(jìn)行分析。

三、分析樣例

1、走索引 - Index Scan Node

表示先走二級(jí)索引,再走一級(jí)索引找到數(shù)據(jù)

finds relevant records based on an Index. Index Scans perform 2 read operations: one to read the index and another to read the actual value from the table.

2、順序掃描 - Seq Scan Node

finds relevant records by sequentially scanning the input record set. When reading from a table, Seq Scans (unlike Index Scans) perform a single read operation (only the table is read).

3、緩存 - shared

  • Hit - 命中
  • Read - 讀磁盤(pán)
  • Dirtied - 臟頁(yè)(臟頁(yè)包含在Hit中)

4、循環(huán)匹配 - Nested Loop

join數(shù)據(jù),將兩個(gè)結(jié)果集進(jìn)行拼接

merges two record sets by looping through every record in the first set and trying to find a match in the second set. All matching records are returned.

遍歷模式


索引模式


5、聚合 - Aggregate

group by 操作

groups records together based on a GROUP BY or aggregate function (like sum()).

6、排序 - Sort

order by 操作

sorts a record set based on the specified sort key.

7、數(shù)量限制 - limit

returns a specified number of rows from a record set.

8、with as 臨時(shí)表 - Common table expressions - CTE

performs a sequential scan of Common Table Expression (CTE) query results. Note that results of a CTE are materialized (calculated and temporarily stored).
對(duì)公共表表達(dá)式(CTE)查詢(xún)結(jié)果執(zhí)行順序掃描。注意,CTE的結(jié)果是具體化的(計(jì)算并臨時(shí)存儲(chǔ))。

9、其他操作

  • WindowAgg
  • Subquery Scan

10、其他join模式圖解

  • Hash Join


  • Merge Join


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容