You've already forked explain.depesz.com
mirror of
https://gitlab.com/depesz/explain.depesz.com.git
synced 2025-07-05 00:58:52 +02:00
Added stats
In view of query, added 3rd tab (HTML, TEXT) - STATS. This shows list of all different node types with their repetition count, summarized time, and percent of total query time, plus similar per table stats.
This commit is contained in:
@ -111,9 +111,34 @@ sub show {
|
||||
return $self->redirect_to( 'new-explain' );
|
||||
}
|
||||
|
||||
# Get stats from plan
|
||||
my $stats = { 'tables' => {} };
|
||||
my @elements = ( $explain->top_node );
|
||||
while ( my $e = shift @elements ) {
|
||||
push @elements, values ${ $e->ctes } if $e->{ 'ctes' };
|
||||
push @elements, @{ $e->sub_nodes } if $e->sub_nodes;
|
||||
push @elements, @{ $e->initplans } if $e->initplans;
|
||||
push @elements, @{ $e->subplans } if $e->subplans;
|
||||
|
||||
$stats->{'nodes'}->{ $e->type }->{'count'}++;
|
||||
$stats->{'nodes'}->{ $e->type }->{'time'}+=$e->total_exclusive_time if $e->total_exclusive_time;
|
||||
|
||||
next unless $e->scan_on;
|
||||
next unless $e->scan_on->{ 'table_name' };
|
||||
$stats->{ 'tables' }->{ $e->scan_on->{ 'table_name' } } ||= {};
|
||||
my $S = $stats->{ 'tables' }->{ $e->scan_on->{ 'table_name' } };
|
||||
$S->{ $e->{ 'type' } }->{ 'count' }++;
|
||||
$S->{ ':total' }->{ 'count' }++;
|
||||
if ( defined( my $t = $e->total_exclusive_time ) ) {
|
||||
$S->{ $e->type }->{ 'time' } += $t;
|
||||
$S->{ ':total' }->{ 'time' } += $t;
|
||||
}
|
||||
}
|
||||
|
||||
# put explain and title to stash
|
||||
$self->stash->{ explain } = $explain;
|
||||
$self->stash->{ title } = $title;
|
||||
$self->stash->{ title } = $title;
|
||||
$self->stash->{ stats } = $stats;
|
||||
|
||||
# render will be called automatically
|
||||
return;
|
||||
|
Reference in New Issue
Block a user