标签:code test rom nod where type pad amp can
在工作中,如果遇到某个SQL执行时间比较长,很多时候会考虑到SQL的执行计划怎样?通过分析SQL的执行计划去分析SQL瓶颈在哪里。
那么运用默认的Postgresql方式是可以去分析执行计划的。如下例:
explain analyze select * from public.sort_test where id = 10001;
其结果是:
而我这里会给大家分享一个免费的,很好的可视化工具去分析,特别是针对比较复杂的SQL执行计划,会更适用。步骤如下:
得到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. 之后,上例中的可视化执行计划如下图:
分享Postgres SQL execution plan visualizer
标签:code test rom nod where type pad amp can
原文地址:https://www.cnblogs.com/summerstone/p/13721613.html