LoginSignup
6
4

PostgreSQLの実行計画の読み方:SQLチューニング#5

Posted at

実行計画とは

PostgreSQLなどのDBMSがSQL文を実行する手順書。

実行計画の取得方法

例えば以下のように実行計画を取得したいSQLの前にEXPLAINをつける。

EXPLAIN ANALYZE SELECT * FROM address

pgAdmin4では以下のように出力される

pgAdminで実行計画.png

実行計画1行ずつの意味

3行出力されて1行目はこちら

Seq Scan on address  (cost=0.00..15169.77 rows=124677 width=832) (actual time=0.285..173.450 rows=124677 loops=1)

・Seq Scan
プラン演算子という、データの探し方のようなことを取り扱う演算子の1つ。テーブルフルスキャンを指していることを示す。

・cost
処理完了までにかかるコスト

・rows
返却される検索結果の行数

・width
返却される1行当たりの長さ

2行目はこれ

Planning Time: 4.876 ms

・Planning Time
実行計画生成、最適化に要した時間

3行目はこちら

Execution Time: 177.293 ms

・Execution Time
実行時間

Planning TimeとExecution Timeは
ANALYZEオプション使用時に表示される

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4