1
0
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:
Hubert depesz Lubaczewski
2020-11-05 15:38:16 +01:00
parent db338f6a88
commit 6833367855
7 changed files with 50 additions and 2 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "ext/pgFormatter"]
path = ext/pgFormatter
url = https://github.com/darold/pgFormatter.git

1
ext/pgFormatter Submodule

Submodule ext/pgFormatter added at 5690b24648

View File

@@ -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 } ] );

View File

@@ -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 );

View File

@@ -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}

View File

@@ -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 ) {

View File

@@ -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">