-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexplain_dalibo.sql
More file actions
65 lines (59 loc) · 2.34 KB
/
Copy pathexplain_dalibo.sql
File metadata and controls
65 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
\set VERBOSITY terse
\pset footer off
set search_path to planstats,public;
\if :{?query_id}
\if :{?pg_stat_statements}
select explainplan.planid , pg_stat_statements.queryid from pg_stat_statements , lateral planstats.run_plan_explain(query) as explainplan where pg_stat_statements.queryid =:query_id
\gset
\else
select queryid::text as queryid from planstats.plan_table where planid = (select max(planid) from planstats.plan_table where queryid = :query_id)
\gset
select max(planid) as planid from planstats.plan_table where queryid = :query_id
\gset
\endif
\else
select queryid::text as queryid from planstats.plan_table where planid = (select max(planid) from plan_table)
\gset
select max(planid) as planid from planstats.plan_table
\gset
\endif
select 'dalibo' || '_' || abs((:'queryid')::bigint) || '.html' as htmlfile
\gset
\o :htmlfile
\pset footer off
\pset tuples_only on
\qecho <!DOCTYPE html>
\qecho <html lang="en">
\qecho <head>
\qecho <meta charset="UTF-8">
\qecho <meta name="viewport" content="width=device-width, initial-scale=1.0">
\qecho <title>PostgreSQL Query Plan Viewer - Dalibo</title>
\qecho <script src="https://unpkg.com/vue@3.5.29/dist/vue.global.prod.js"></script>
\qecho <script src="https://unpkg.com/pev2@1.20.2/dist/pev2.umd.js"></script>
\qecho <link href="https://unpkg.com/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
\qecho <link rel="stylesheet" href="https://unpkg.com/pev2@1.20.2/dist/pev2.css"/>
\qecho <style>html,body{height:100%;margin:0;overflow:hidden}#app{height:100%;display:flex;flex-direction:column}#app .pev2{flex:1;min-height:0}</style>
\qecho </head>
\qecho <body>
\qecho <div id="app" class="container-fluid p-0" style="height:100%">
\qecho <pev2 :plan-source="plan" :plan-query="query" style="height:100%" />
\qecho </div>
\qecho
\qecho <script>
\qecho const { createApp } = Vue;
\qecho const app = createApp({
\qecho data() {
\qecho return {
\pset format unaligned
select concat_ws('','query:','`',sql,'`,') from plan_table where planid = :planid;
select concat_ws('','plan:','`',plainplan,'`') from plan_table where planid = :planid;
\qecho }
\qecho },
\qecho });
\qecho app.component("pev2", pev2.Plan);
\qecho app.mount("#app");
\qecho </script>
\echo
\echo Dalibo Plan is generated for Query(:queryid)
\qecho </body>
\qecho </html>