1
0
mirror of https://gitlab.com/depesz/explain.depesz.com.git synced 2025-11-29 23:08:18 +02:00
Files
explain.depesz.com/templates/controller/show.html.ep
Hubert depesz Lubaczewski d2d4e03557 Add colorized sources for explains
If explain was originally in json/yaml/xml format, add syntax-highlight
to the source of it.

Also - in such cases, add text view - explain regenerated to text
format.
2019-11-13 00:14:18 +01:00

659 lines
30 KiB
Plaintext
Executable File

% layout 'default';
% my $node_type_docs = {
% 'Append' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#append',
% 'Bitmap Heap Scan' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#bitmap-heap-scan',
% 'Bitmap Index Scan' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#bitmap-index-scan',
% 'CTE Scan' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#cte-scan',
% 'Function Scan' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#function-scan',
% 'GroupAggregate' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#group-aggregate',
% 'HashAggregate' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#hash-aggregate',
% 'Hash' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#hash',
% 'Hash Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#hash-join',
% 'HashSetOp' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#hash-set-op',
% 'Index Only Scan' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#index-only-scan',
% 'Index Scan Backward' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#index-scan-backward',
% 'Index Scan' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#index-scan',
% 'InitPlan' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#init-plan',
% 'Limit' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#limit',
% 'Materialize' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#materialize',
% 'Merge Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#merge-join',
% 'Nested Loop' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#nested-loop',
% 'Result' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#result',
% 'Seq Scan' => 'http://www.depesz.com/2013/04/27/explaining-the-unexplainable-part-2/#seq-scan',
% 'Sort' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#sort',
% 'SubPlan' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#sub-plan',
% 'Unique' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#unique',
% 'Values Scan' => 'http://www.depesz.com/2013/05/19/explaining-the-unexplainable-part-4/#values-scan',
% 'Hash Full Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Hash Left Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Hash Right Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Merge Full Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Merge Left Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Merge Right Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Nested Loop Right Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Nested Loop Full Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% 'Nested Loop Left Join' => 'http://www.depesz.com/2013/05/09/explaining-the-unexplainable-part-3/#join-modifiers',
% };
% my $id = stash( 'id' );
% my $title = stash( 'title' );
% my $full_title = $title ? "$id : $title" : $id;
% title $full_title;
%# c = e|i|x|m (colorize = exclusive|inclusive|rows-x|mixed)
%# ve - visibility of "exclusive" column
%# vi - visibility of "inclusive" column
%# ...
% my @cookie = grep { $_->name eq 'explain' } @{ $self->req->cookies };
% my $cookie = scalar @cookie ? Mojo::ByteStream->new( $cookie[0]->value )->url_unescape : '';
% my @cfg = split /\|/, $cookie || '';
% my $cfg = {};
%
% for ( @cfg ) {
% next unless $_ =~ /\A(c|vu|ve|vi|vx|vr|vl)\=([exim01]{1})\z/;
% $cfg->{ $1 } = $2;
% }
%
% $cfg->{ c } = 'm' unless $cfg->{ c } && $cfg->{ c } =~ /\A(e|i|x|m)\z/;
%
% for ( qw( vu ve vi vx vr vl ) ) {
% next if exists $cfg->{ $_ } && $cfg->{ $_ } =~ /\A(0|1)\z/;
% $cfg->{ $_ } = 1;
% }
% my $global_node_id = 0;
% my $prev_row_level = 0;
% my $prev_row_class = 'odd';
% my $block = undef;
%
% $block = begin
%
% my ( $node, $level, $parent ) = @_;
% my $full_execution_time = $explain->runtime || 0;
%
% $level ||= 0;
% $parent = '' unless defined $parent;
%
% my $exclusive_point = 1;
% my $inclusive_point = 1;
%
% if ( $explain->top_node->total_inclusive_time && defined( $node->total_exclusive_time ) && defined( $node->total_inclusive_time ) && $node->total_exclusive_time ne '' && $node->total_inclusive_time ne '' ) {
%
% $exclusive_point = $node->total_exclusive_time / $full_execution_time;
%
% if ( $exclusive_point > 0.9 ) { $exclusive_point = 4; }
% elsif ( $exclusive_point > 0.5 ) { $exclusive_point = 3; }
% elsif ( $exclusive_point > 0.1 ) { $exclusive_point = 2; }
% else { $exclusive_point = 1; }
%
% $inclusive_point = $node->total_inclusive_time / $full_execution_time;
%
% if ( $inclusive_point > 0.9 ) { $inclusive_point = 4; }
% elsif ( $inclusive_point > 0.5 ) { $inclusive_point = 3; }
% elsif ( $inclusive_point > 0.1 ) { $inclusive_point = 2; }
% else { $inclusive_point = 1; }
% }
%
% my $rows_x = 0;
% my $rows_x_mark = '';
% my $rows_x_point = 1;
%
% if ( $node->estimated_rows && $node->actual_rows ) {
%
% if ( $node->actual_rows > $node->estimated_rows ) {
% $rows_x = $node->actual_rows / $node->estimated_rows;
% $rows_x_mark = 'down';
% } else {
% $rows_x = $node->estimated_rows / $node->actual_rows;
% $rows_x_mark = 'up';
% }
%
% if ( $rows_x > 1000 ) { $rows_x_point = 4; }
% elsif ( $rows_x > 100 ) { $rows_x_point = 3; }
% elsif ( $rows_x > 10 ) { $rows_x_point = 2; }
% else { $rows_x_point = 1; }
% }
%# tr class="(n|ip|sp) (even|odd) c-(mix|1|2|3|4)"
%# means:
%# n(ode)/i(nit)p(lan)/s(ub)p(lan)
%# c(olor)-mix(ed)|1|2|3|4
%#
%# td class="(u|e|i|x|r|l|n) (c-(1|2|3|4))?"
%# means:
%# n(u)mber|e(xclusive time)/i(nclusive time)/(rows-)x/r(ows)/l(oops)/n(ode)
%# c(olor)-1|2|3|4
%#
%# important!
%# content of td.r(ows)/td.l(oops) must be wrapped in "span" element (because Opera...)
% my $margin = ( $level + 1 ) * 22;
% my $row_color = $cfg->{ c };
% if ( $row_color eq 'e' ) { $row_color = $exclusive_point; }
% elsif ( $row_color eq 'i' ) { $row_color = $inclusive_point; }
% elsif ( $row_color eq 'x' ) { $row_color = $rows_x_point; }
% my $row_class = $prev_row_class;
%
% if ( $level != $prev_row_level ) {
%
% $row_class = $prev_row_class eq 'even' ? 'odd' : 'even';
%
% $prev_row_level = $level;
% $prev_row_class = $row_class;
% }
%
% $row_class .= ' c-' . $row_color;
% my $node_id = $global_node_id++;
<tr id="l<%= $global_node_id =%>" class="n <%= $row_class %>" data-node_id="<%= $node_id =%>" data-node_parent="<%= $parent =%>" data-level="<%= $level =%>" data-e="<%= $exclusive_point =%>" data-i="<%= $inclusive_point =%>" data-x="<%= $rows_x_point =%>">
<td class="u <%= $cfg->{ vu } ? '' : ' tight' %>"><a href="#l<%= $global_node_id =%>"><%= $global_node_id =%>.</a></td>
<td class="e c-<%= $exclusive_point =%><%= $cfg->{ ve } ? '' : ' tight' %>">
<span><%= commify_numbers( sprintf '%.3f', defined $node->total_exclusive_time ? $node->total_exclusive_time : 0 ) =%></span>
</td>
<td class="i c-<%= $inclusive_point =%><%= $cfg->{ vi } ? '' : ' tight' %>">
<span><%= commify_numbers( sprintf '%.3f', defined $node->total_inclusive_time ? $node->total_inclusive_time : 0 ) =%></span>
</td>
<td class="x c-<%= $rows_x_point =%><%= $cfg->{ vx } ? '' : ' tight' %>">
<span>
<%== $rows_x_mark eq 'up' ? '&uarr;' : '&darr;' %>
<%= commify_numbers( sprintf '%.1f', $rows_x ) %>
</span>
</td>
<td class="r<%= $cfg->{ vr } ? '' : ' tight' %>"><span><%= commify_numbers( $node->actual_rows ) =%></span></td>
<td class="l<%= $cfg->{ vl } ? '' : ' tight' %>"><span><%= commify_numbers( $node->actual_loops ) =%></span></td>
<td class="n">
<div class="n" style="margin-left:<%= $margin =%>px">
<div class="ico">&rarr;</div>
<p>
<span class="node">
% if ( $node_type_docs->{ $node->type }) {
<a href="<%= $node_type_docs->{ $node->type } %>"><%= $node->type %></a>
% } else {
<%= $node->type %>
% }
% if ( $node->type =~ m{^(Parallel )?Bitmap Heap Scan$} ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( 'Bitmap Index Scan' eq $node->type ) {
on <%= $node->scan_on->{ index_name } %>
% }
% elsif ( $node->type =~ m{^(Parallel )?Index (Only )?Scan( Backward)?$} ) {
using <%= $node->scan_on->{ index_name } %> on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( $node->type =~ m{^(Parallel )?Seq Scan$} ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( ( 'Insert' eq $node->type ) && ( $node->scan_on ) ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( ( 'Update' eq $node->type ) && ( $node->scan_on ) ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( ( 'Delete' eq $node->type ) && ( $node->scan_on ) ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% elsif ( 'Foreign Scan' eq $node->type ) {
% if ( defined $node->scan_on ) {
on <%= $node->scan_on->{ table_name } %> <%= $node->scan_on->{ table_alias } || '' %>
% }
% }
% elsif ( 'CTE Scan' eq $node->type ) {
on <%= $node->scan_on->{ cte_name } %> <%= $node->scan_on->{ cte_alias } || '' %>
% }
% elsif ( 'WorkTable Scan' eq $node->type ) {
on <%= $node->scan_on->{ worktable_name } %> <%= $node->scan_on->{ worktable_alias } || '' %>
% }
% elsif ( 'Function Scan' eq $node->type ) {
on <%= $node->scan_on->{ function_name } %> <%= $node->scan_on->{ function_alias } || '' %>
% }
% elsif ( 'Subquery Scan' eq $node->type ) {
on <%= $node->scan_on->{ subquery_name } %>
% }
</span>
<span class="est">
(cost=<%= commify_numbers( $node->estimated_startup_cost ) =%>..<%= commify_numbers( $node->estimated_total_cost ) %>
rows=<%= commify_numbers( $node->estimated_rows ) %>
width=<%= commify_numbers( $node->estimated_row_width ) =%>)
</span>
<span class="act">
% if ( $node->never_executed ) {
(never executed)
% } else {
(actual
% if ( defined $node->actual_time_first ) {
time=<%= commify_numbers( $node->actual_time_first ) =%>..<%= commify_numbers( $node->actual_time_last ) %>
% }
rows=<%= commify_numbers( $node->actual_rows ) %>
loops=<%= commify_numbers( $node->actual_loops ) =%>)
% }
</span>
</p>
% if ( $node->extra_info ) {
<ul class="ex-nfo">
% for my $line ( @{ $node->extra_info } ) {
<li><%= $line =%></li>
% }
</ul>
% }
</div>
</td>
</tr>
% if ( $node->can( 'ctes' ) ) {
% if ( $node->ctes ) {
% for my $cte ( @{ $node->cte_order } ) {
% my $cte_node_id = $global_node_id++;
<tr id="l<%= $global_node_id =%>" class="cte" data-node_id="<%= $cte_node_id =%>" data-node_parent="<%= $node_id =%>" data-level="<%= $level =%>">
<td class="u<%= $cfg->{ vu } ? '' : ' tight' %>"><span><a href="#l<%= $global_node_id =%>"><%= $global_node_id =%>.</a></span></td>
<td class="e<%= $cfg->{ ve } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="i<%= $cfg->{ vi } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="x<%= $cfg->{ vx } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="r<%= $cfg->{ vr } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="l<%= $cfg->{ vl } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="n">
<div class="n" style="margin-left:<%= $margin =%>px">
<p><span>CTE <%= $cte %></span></p>
</div>
</td>
</tr>
%== $block->( $node->cte( $cte ), $level + 1, $cte_node_id );
% }
% }
% }
% if ( $node->initplans ) {
% my $ip_node_id = $global_node_id++;
<tr id="l<%= $global_node_id =%>" class="ip" data-node_id="<%= $ip_node_id =%>" data-node_parent="<%= $node_id =%>" data-level="<%= $level =%>">
<td class="u<%= $cfg->{ vu } ? '' : ' tight' %>"><span><a href="#l<%= $global_node_id =%>"><%= $global_node_id =%>.</a></span></td>
<td class="e<%= $cfg->{ ve } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="i<%= $cfg->{ vi } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="x<%= $cfg->{ vx } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="r<%= $cfg->{ vr } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="l<%= $cfg->{ vl } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="n">
<div class="n" style="margin-left:<%= $margin =%>px">
<p><span>Initplan (for <%= $node->type %>)</span></p>
</div>
</td>
</tr>
% for ( @{ $node->initplans } ) {
%== $block->( $_, $level + 1, $ip_node_id );
% }
% }
% if ( $node->sub_nodes ) {
% for ( @{ $node->sub_nodes } ) {
%== $block->( $_, $level + 1, $node_id );
% }
% }
% if ( $node->subplans ) {
% my $sp_node_id = $global_node_id++;
<tr id="l<%= $global_node_id =%>" class="sp" data-node_id="<%= $sp_node_id =%>" data-node_parent="<%= $node_id =%>" data-level="<%= $level =%>">
<td class="u<%= $cfg->{ vu } ? '' : ' tight' %>"><span><a href="#l<%= $global_node_id =%>"><%= $global_node_id =%>.</a></span></td>
<td class="e<%= $cfg->{ ve } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="i<%= $cfg->{ vi } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="x<%= $cfg->{ vx } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="r<%= $cfg->{ vr } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="l<%= $cfg->{ vl } ? '' : ' tight' %>"><span>&nbsp;</span></td>
<td class="n">
<div class="n" style="margin-left:<%= $margin =%>px">
<p><span>SubPlan (for <%= $node->type %>)</span></p>
</div>
</td>
</tr>
% for ( @{ $node->subplans } ) {
%== $block->( $_, $level + 1, $sp_node_id );
% }
% }
% end;
<h1>Result: <%= $full_title %></h1>
% if ( flash( 'delete_key' ) ) {
<div class="message messageNice">
<p class="message">To delete this plan, you can use <a href="<%= url_for( 'delete', id => $id, key => flash( 'delete_key' ) )=%>">this link</a>.</p>
<p class="hint">This link will not be shown any more, so you might want to bookmark it, just in case.</p>
</div>
% }
<div class="explain-form">
<form id="explain-form" class="hidden" method="get" action="<%= url_for 'current' %>" autocomplete="off">
<h3>Color mode:</h3>
<ul>
<li>
<input type="radio" name="c" id="ce" value="e"<%= $cfg->{ c } eq 'e' ? ' checked="checked"' : '' %> />
<label for="ce">exclusive</label>
</li>
<li>
<input type="radio" name="c" id="ci" value="i"<%= $cfg->{ c } eq 'i' ? ' checked="checked"' : '' %> />
<label for="ci">inclusive</label>
</li>
<li>
<input type="radio" name="c" id="cx" value="x"<%= $cfg->{ c } eq 'x' ? ' checked="checked"' : '' %> />
<label for="cx">rows x</label>
</li>
<li>
<input type="radio" name="c" id="cm" value="m"<%= $cfg->{ c } eq 'm' ? ' checked="checked"' : '' %> />
<label for="cm">mixed</label>
</li>
</ul>
<h3>Visible columns:</h3>
<ul>
<li>
<input type="checkbox" name="vu" id="vu" value="1"<%= $cfg->{ vu } ? ' checked="checked"' : '' %> />
<label for="vu">#</label>
</li>
<li>
<input type="checkbox" name="ve" id="ve" value="1"<%= $cfg->{ ve } ? ' checked="checked"' : '' %> />
<label for="ve">exclusive</label>
</li>
<li>
<input type="checkbox" name="vi" id="vi" value="1"<%= $cfg->{ vi } ? ' checked="checked"' : '' %> />
<label for="vi">inclusive</label>
</li>
<li>
<input type="checkbox" name="vx" id="vx" value="1"<%= $cfg->{ vx } ? ' checked="checked"' : '' %> />
<label for="vx">rows x</label>
</li>
<li>
<input type="checkbox" name="vr" id="vr" value="1"<%= $cfg->{ vr } ? ' checked="checked"' : '' %> />
<label for="vr">rows</label>
</li>
<li>
<input type="checkbox" name="vl" id="vl" value="1"<%= $cfg->{ vl } ? ' checked="checked"' : '' %> />
<label for="vl">loops</label>
</li>
</ul>
<div class="fe fe-buttons">
<button type="submit" name="save-settings" id="save-settings"><span>Save settings</span></button>
</div>
</form>
<a href="#" onclick="$.fn.explain( 'toggleCfgForm', this ); return false;" onkeypress="return this.onclick( );"><span>Settings</span></a>
</div>
% if ( stash('optimization_path') ) {
<h3>Optimization path:</h3>
<ul>
% for my $opt ( @{ stash('optimization_path') }) {
<li><a href="<%= url_for( 'show', id => $opt->{'id'} ) =%>">#<%= $opt->{'id'} %> : <%= $opt->{'title'} %></a></li>
% }
</ul>
</h3>
% }
% if ( stash('suboptimizations') ) {
<h3>Optimization(s) for this plan:</h3>
<ul>
% for my $opt ( @{ stash('suboptimizations') }) {
<li><a href="<%= url_for( 'show', id => $opt->{'id'} ) =%>">#<%= $opt->{'id'} %> : <%= $opt->{'title'} %></a></li>
% }
</ul>
% }
<div class="result">
<div class="plea">
<form id="new-optimization" method="post" action="<%= url_for 'new-optimization' %>">
<input type="hidden" name="original" value="<%= $id %>"/>
<button type="submit" name="add-optimization" id="add-optimization"><span>Add optimization</span></button>
</form>
</div>
<div class="tabs">
<ul class="clearfix">
<li class="html">
<a href="#html"
title="view HTML"
class="current"
onclick="$( this ).explain( 'toggleView', 'html', this ); return false;"
onkeypress="return this.onclick( );">HTML</a>
</li>
<li class="source">
<a href="#source"
title="view source explain"
onclick="$( this ).explain( 'toggleView', 'source', this ); return false;"
onkeypress="return this.onclick( );">SOURCE</a>
</li>
% if ( $explain->source_format ne 'TEXT' ) {
<li class="text">
<a href="#text"
title="view as text explain"
onclick="$( this ).explain( 'toggleView', 'text', this ); return false;"
onkeypress="return this.onclick( );">TEXT</a>
</li>
% }
<li class="stats">
<a href="#stats"
title="view plan stats"
onclick="$( this ).explain( 'toggleView', 'stats', this ); return false;"
onkeypress="return this.onclick( );">STATS</a>
</li>
</ul>
</div>
<div class="result-html">
<table id="explain">
<thead>
<tr>
<th class="u<%= $cfg->{ vu } ? '' : ' tight' %>">
<span>#</span>
</th>
<th class="e<%= $cfg->{ ve } ? '' : ' tight' %>">
<a href="#colorize-exclusive"
title="colorize rows based on &quot;exclusive&quot;"
onclick="$.fn.explain( 'colorize', 'e', this ); return false"
onkeypress="return this.onclick( );">exclusive</a>
</th>
<th class="i<%= $cfg->{ vi } ? '' : ' tight' %>">
<a href="#colorize-inclusive"
title="colorize rows based on &quot;inclusive&quot;"
onclick="$.fn.explain( 'colorize', 'i', this ); return false"
onkeypress="return this.onclick( );">inclusive</a>
</th>
<th class="x<%= $cfg->{ vx } ? '' : ' tight' %>">
<a href="#colorize-rows-x"
title="colorize rows based on &quot;rows x&quot;"
onclick="$.fn.explain( 'colorize', 'x', this ); return false"
onkeypress="return this.onclick( );">rows x</a>
</th>
<th class="r<%= $cfg->{ vr } ? '' : ' tight' %>">
<span>rows</span>
</th>
<th class="l<%= $cfg->{ vl } ? '' : ' tight' %>">
<span>loops</span>
</th>
<th class="n">
<span>node</span>
</th>
</tr>
</thead>
<tbody>
%== $block->( $explain->top_node );
</tbody>
</table>
% if ( (defined $explain->planning_time) || (defined $explain->execution_time) || (defined $explain->total_runtime) ) {
% my $trclass="single";
% $trclass="both" if (defined $explain->planning_time) && (defined $explain->execution_time);
<table id="total-times">
% if (defined $explain->planning_time) {
<tr class="<%= $trclass %> planning">
<th>Planning time</th>
<td class="separator">:</td>
<td class="value"><%= commify_numbers( $explain->planning_time ) %> ms</td>
</tr>
% }
% if (defined $explain->execution_time) {
<tr class="<%= $trclass %> execution">
<th>Execution time</th>
<td class="separator">:</td>
<td><span class="value"><%= commify_numbers( $explain->execution_time ) %></span> <span class="unit">ms</span></td>
</tr>
% }
% if (defined $explain->total_runtime) {
<tr class="<%= $trclass %> execution">
<th>Total runtime</th>
<td class="separator">:</td>
<td><span class="value"><%= commify_numbers( $explain->total_runtime ) %></span> <span class="unit">ms</span></td>
</tr>
% }
</table>
% }
% if ( defined $explain->trigger_times ) {
% my $full_execution_time = $explain->runtime || 0;
<table id="trigger-times">
<thead>
<tr><th colspan="4" class="top">Trigger times:</th></tr>
<tr><th>Trigger Name:</th><th>Total time:</th><th>Calls:</th><th>Average time:</th></tr>
</thead>
<tbody>
% for my $trg ( @{ $explain->trigger_times } ) {
% my $row_color = 1;
% if ( $full_execution_time ) {
% my $trigger_point = $trg->{'time'} / $full_execution_time;
% if ( $trigger_point > 0.9 ) { $row_color = 4; }
% elsif ( $trigger_point > 0.5 ) { $row_color = 3; }
% elsif ( $trigger_point > 0.1 ) { $row_color = 2; }
% }
<tr class="c-<%= $row_color %>">
<th class="name"><%= $trg->{'name'} %></th>
<td class="time"><span class="value"><%= commify_numbers( sprintf '%.03f', $trg->{'time'} ) %></span> <span class="unit">ms</span></td>
<td class="count"><span class="value"><%= $trg->{'calls'} %></span></td>
<td class="time"><span class="value"><%= commify_numbers( sprintf '%.03f', $trg->{'time'} / $trg->{'calls'} ) %></span> <span class="unit">ms</span></td>
</tr>
% }
</tbody>
</table>
% }
</div>
<div class="result-source hidden">
<pre id="source"><code class="<%= lc( $explain->source_format ) =%>"><%= $explain->source =%></code></pre>
</div>
% if ( $explain->source_format ne 'TEXT' ) {
<div class="result-text hidden">
<pre id="text"><%= $explain->as_text =%></pre>
</div>
% }
<div class="result-stats hidden">
<h1>Per node type stats</h1>
<table class="stats">
<thead>
<tr><th>node type</th><th>count</th><th>sum of times</th><th>% of query</th></tr>
</thead>
<tbody>
% for my $node_type ( sort keys %{ $stats->{'nodes'} } ) {
<tr class="table-detail">
<td class="node-type"><%= $node_type %></td>
<td class="count"><%= $stats->{'nodes'}->{$node_type}->{'count'} %></td>
<td class="time"><%= commify_numbers( sprintf '%.03f ms', $stats->{'nodes'}->{$node_type}->{'time'} || 0 ) %></td>
<td class="percent">
<% my $total = $explain->top_node->total_inclusive_time || 0; %>
<% my $current = $stats->{'nodes'}->{$node_type}->{'time'} || 0; %>
<% my $percent = $total == 0 ? 0 : 100 * $current / $total; %>
<%= sprintf '%.1f %%', $percent %>
</td>
</tr>
% }
</tbody>
</table>
<h1>Per table stats</h1>
<table class="stats">
<thead>
<tr><th>Table name</th><th>Scan count</th><th>Total time</th><th>% of query</th></tr>
<tr><th>scan type</th><th>count</th><th>sum of times</th><th>% of table</th></tr>
</thead>
<tbody>
% for my $table_name ( sort keys %{ $stats->{'tables'} } ) {
<tr class="table-summary">
<td class="table-name"><%= $table_name %></td>
<td class="count"><%= $stats->{'tables'}->{$table_name}->{':total'}->{'count'} %></td>
<td class="time"><%= commify_numbers( sprintf '%.03f ms', $stats->{'tables'}->{$table_name}->{':total'}->{'time'} || 0 ) %></td>
<td class="percent">
<% my $total = $explain->top_node->total_inclusive_time || 0; %>
<% my $current = $stats->{'tables'}->{$table_name}->{':total'}->{'time'} || 0; %>
<% my $percent = $total == 0 ? 0 : 100 * $current / $total; %>
<%= sprintf '%.1f %%', $percent %>
</td>
</tr>
% for my $scan_type ( sort grep { ! /^:/ } keys %{ $stats->{'tables'}->{$table_name} } ) {
<tr class="table-detail">
<td class="scan-type"><%= $scan_type %></td>
<td class="count"><%= $stats->{'tables'}->{$table_name}->{$scan_type}->{'count'} %></td>
<td class="time"><%= commify_numbers( sprintf '%.03f ms', $stats->{'tables'}->{$table_name}->{$scan_type}->{'time'} || 0 ) %></td>
<td class="percent">
<% my $total = $stats->{'tables'}->{$table_name}->{':total'}->{'time'} || 0; %>
<% my $current = $stats->{'tables'}->{$table_name}->{$scan_type}->{'time'} || 0; %>
<% my $percent = $total == 0 ? 0 : 100 * $current / $total; %>
<%= sprintf '%.1f %%', $percent %>
</td>
</tr>
% }
% }
</tbody>
</table>
</div>
</div>
<% content_for 'head' => begin %>
<link rel="stylesheet" href="<%= url_for '/' %>css/highlight-styles/tomorrow-night.css">
<script src="<%= url_for '/' %>js/highlight.pack.js"></script>
<script>
$( document ).ready( function( ) {
/* startup */
$.fn.explain( 'init', $( '#explain-form' ), $( '#explain' ) );
hljs.initHighlightingOnLoad();
} );
</script>
<% end %>