You've already forked explain.depesz.com
mirror of
https://gitlab.com/depesz/explain.depesz.com.git
synced 2025-09-16 09:26:37 +02:00
Beautify queries, and hide bogus "actual" info
1. Added beautification of queries using pgFormatter library https://github.com/darold/pgFormatter 2. In case of plans that are "explain query" and not "explain analyze" - don't show bogus "actual ..." info.
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "ext/pgFormatter"]
|
||||
path = ext/pgFormatter
|
||||
url = https://github.com/darold/pgFormatter.git
|
1
ext/pgFormatter
Submodule
1
ext/pgFormatter
Submodule
Submodule ext/pgFormatter added at 5690b24648
@@ -8,6 +8,9 @@ sub startup {
|
||||
$self->sessions->cookie_name( 'explain' );
|
||||
$self->sessions->default_expiration( 60 * 60 * 24 * 365 );
|
||||
|
||||
# Add path to pgFormatter library, from git submodule
|
||||
push @INC, $self->home->rel_file( 'ext/pgFormatter/lib' )->to_string();
|
||||
|
||||
# register Explain plugins namespace
|
||||
$self->plugins->namespaces( [ "Explain::Plugin", @{ $self->plugins->namespaces } ] );
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
## Please see file perltidy.ERR
|
||||
package Explain::Controller;
|
||||
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
@@ -5,6 +6,7 @@ use Mojo::Base 'Mojolicious::Controller';
|
||||
use English -no_match_vars;
|
||||
|
||||
use Pg::Explain;
|
||||
use pgFormatter::Beautify;
|
||||
use Encode;
|
||||
use Email::Valid;
|
||||
use Config;
|
||||
@@ -340,8 +342,15 @@ sub show {
|
||||
# put explain and title to stash
|
||||
$self->stash->{ explain } = $explain;
|
||||
$self->stash->{ title } = $data->{ 'title' };
|
||||
$self->stash->{ query } = $data->{ 'query' };
|
||||
$self->stash->{ stats } = $stats;
|
||||
if ( $data->{ 'query' } ) {
|
||||
my $beautifier = pgFormatter::Beautify->new();
|
||||
$beautifier->query( $data->{ 'query' } );
|
||||
$beautifier->beautify();
|
||||
|
||||
$self->stash->{ bquery } = $beautifier->content();
|
||||
$self->stash->{ query } = $data->{ 'query' };
|
||||
}
|
||||
$self->stash->{ stats } = $stats;
|
||||
|
||||
# Fetch path of optimizations
|
||||
$self->stash->{ optimization_path } = $self->database->get_optimization_path( $id );
|
||||
|
@@ -110,6 +110,8 @@ section p a:hover {background:#234;color:#fff;border:1px solid #123}
|
||||
.result-source pre {margin:0;padding:1em}
|
||||
.result-query {background:#222 url('../img/code-bg.gif');color:#fff}
|
||||
.result-query pre {margin:0;padding:1em}
|
||||
.result-bquery {background:#222 url('../img/code-bg.gif');color:#fff}
|
||||
.result-bquery pre {margin:0;padding:1em}
|
||||
.result-text {background:#222 url('../img/code-bg.gif');color:#fff}
|
||||
.result-text pre {margin:0;padding:1em}
|
||||
|
||||
|
@@ -195,12 +195,22 @@
|
||||
|
||||
var result = $( link.parents( 'div.result' ).get( 0 ) );
|
||||
|
||||
if ( 'bquery' == view.toLowerCase( ) ) {
|
||||
result.find( 'div.result-html' ).hide( );
|
||||
result.find( 'div.result-stats' ).hide( );
|
||||
result.find( 'div.result-source' ).hide( );
|
||||
result.find( 'div.result-query' ).hide( );
|
||||
result.find( 'div.result-text' ).hide( );
|
||||
result.find( 'div.result-bquery' ).show( );
|
||||
return;
|
||||
}
|
||||
if ( 'query' == view.toLowerCase( ) ) {
|
||||
result.find( 'div.result-html' ).hide( );
|
||||
result.find( 'div.result-stats' ).hide( );
|
||||
result.find( 'div.result-source' ).hide( );
|
||||
result.find( 'div.result-query' ).show( );
|
||||
result.find( 'div.result-text' ).hide( );
|
||||
result.find( 'div.result-bquery' ).hide( );
|
||||
return;
|
||||
}
|
||||
if ( 'text' == view.toLowerCase( ) ) {
|
||||
@@ -209,6 +219,7 @@
|
||||
result.find( 'div.result-source' ).hide( );
|
||||
result.find( 'div.result-query' ).hide( );
|
||||
result.find( 'div.result-text' ).show( );
|
||||
result.find( 'div.result-bquery' ).hide( );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -218,6 +229,7 @@
|
||||
result.find( 'div.result-source' ).hide( );
|
||||
result.find( 'div.result-query' ).hide( );
|
||||
result.find( 'div.result-text' ).hide( );
|
||||
result.find( 'div.result-bquery' ).hide( );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -227,6 +239,7 @@
|
||||
result.find( 'div.result-source' ).show( );
|
||||
result.find( 'div.result-query' ).hide( );
|
||||
result.find( 'div.result-text' ).hide( );
|
||||
result.find( 'div.result-bquery' ).hide( );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -235,6 +248,7 @@
|
||||
result.find( 'div.result-stats' ).show( );
|
||||
result.find( 'div.result-query' ).hide( );
|
||||
result.find( 'div.result-text' ).hide( );
|
||||
result.find( 'div.result-bquery' ).hide( );
|
||||
},
|
||||
|
||||
toggleCfgForm : function( link ) {
|
||||
|
@@ -244,6 +244,7 @@
|
||||
width=<%= commify_number( $node->estimated_row_width ) =%>)
|
||||
</span>
|
||||
|
||||
% if ( $node->is_analyzed ) {
|
||||
<span class="act">
|
||||
% if ( $node->never_executed ) {
|
||||
(never executed)
|
||||
@@ -256,6 +257,7 @@
|
||||
loops=<%= commify_number( $node->actual_loops ) =%>)
|
||||
% }
|
||||
</span>
|
||||
% }
|
||||
</p>
|
||||
|
||||
% if ( $node->extra_info ) {
|
||||
@@ -483,6 +485,14 @@
|
||||
onclick="$( this ).explain( 'toggleView', 'query', this ); return false;"
|
||||
onkeypress="return this.onclick( );">QUERY</a>
|
||||
</li>
|
||||
% }
|
||||
% if ( stash('bquery') ) {
|
||||
<li class="bquery">
|
||||
<a href="#bquery"
|
||||
title="view reformatted query"
|
||||
onclick="$( this ).explain( 'toggleView', 'bquery', this ); return false;"
|
||||
onkeypress="return this.onclick( );">REFORMATTED QUERY</a>
|
||||
</li>
|
||||
% }
|
||||
<li class="stats">
|
||||
<a href="#stats"
|
||||
@@ -606,6 +616,12 @@
|
||||
</div>
|
||||
% }
|
||||
|
||||
% if ( stash('bquery') ) {
|
||||
<div class="result-bquery hidden">
|
||||
<pre id="bquery"><code class="sql"><%= stash('bquery') %></code></pre>
|
||||
</div>
|
||||
% }
|
||||
|
||||
<div class="result-stats hidden">
|
||||
<h1>Per node type stats</h1>
|
||||
<table class="stats">
|
||||
|
Reference in New Issue
Block a user