当前位置:Gxlcms > 数据库问题 > 分享Postgres SQL execution plan visualizer

分享Postgres SQL execution plan visualizer

时间:2021-07-01 10:21:17 帮助过:30人阅读

* from public.sort_test where id = 10001;

其结果是:

技术图片

 

 

而我这里会给大家分享一个免费的,很好的可视化工具去分析,特别是针对比较复杂的SQL执行计划,会更适用。步骤如下:

  1. 得到SQL 执行计划的Json 输出格式文本,可以通过如下解决:

EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) 
select * from public.sort_test where id = 10001;

得到的Json格式的执行计划如下:

[
  {
    "Plan": {
      "Node Type": "Index Scan",
      "Parallel Aware": false,
      "Scan Direction": "Forward",
      "Index Name": "sort_test_pkey",
      "Relation Name": "sort_test",
      "Schema": "public",
      "Alias": "sort_test",
      "Startup Cost": 0.43,
      "Total Cost": 8.45,
      "Plan Rows": 1,
      "Plan Width": 14,
      "Actual Startup Time": 0.015,
      "Actual Total Time": 0.016,
      "Actual Rows": 1,
      "Actual Loops": 1,
      "Output": [
        "id",
        "salary"
      ],
      "Index Cond": "(sort_test.id = 10001)",
      "Rows Removed by Index Recheck": 0,
      "Shared Hit Blocks": 4,
      "Shared Read Blocks": 0,
      "Shared Dirtied Blocks": 0,
      "Shared Written Blocks": 0,
      "Local Hit Blocks": 0,
      "Local Read Blocks": 0,
      "Local Dirtied Blocks": 0,
      "Local Written Blocks": 0,
      "Temp Read Blocks": 0,
      "Temp Written Blocks": 0
    },
    "Planning Time": 0.127,
    "Triggers": [],
    "Execution Time": 0.037
  }]

       2.打开可视化工具网站:http://www.tatiyants.com/pev/

       3.在页面上点击按钮“NEW PLAN"

       4.在界面上按顺序填入如下图所示的元素,然后点击“SUBMIT"按钮。

技术图片

 

 6. 之后,上例中的可视化执行计划如下图:

技术图片

 

 

转自公众号【TimTest】,

人气教程排行