执行计划工具-Postgres SQL execution plan visualizer

在工做中,若是遇到某个SQL执行时间比较长,不少时候会考虑到SQL的执行计划怎样?经过分析SQL的执行计划去分析SQL瓶颈在哪里。sql


那么运用默认的Postgresql方式是能够去分析执行计划的。以下例:app

explain analyze select * from public.sort_test where id = 10001;

其结果是:ide

Screen Shot 2020-09-28 at 13.27.50.png


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


  1. 获得SQL 执行计划的Json 输出格式文本,能够经过以下解决:oop

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"按钮。spa

  Screen Shot 2020-09-28 at 13.30.25.png

    5.以后,上例中的可视化执行计划以下图:code

Screen Shot 2020-09-28 at 13.31.09.png


    你们也能够扫描并关注以下公众号“TimTest”,会有更多性能测试相关内容分享。

qrcode_for_gh_39009e949117_258-1.jpg

相关文章
相关标签/搜索