line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pg::Explain::FromYAML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
4
|
74
|
|
|
74
|
|
1143
|
use v5.18; |
|
74
|
|
|
|
|
311
|
|
5
|
74
|
|
|
74
|
|
652
|
use strict; |
|
74
|
|
|
|
|
157
|
|
|
74
|
|
|
|
|
1608
|
|
6
|
74
|
|
|
74
|
|
559
|
use warnings; |
|
74
|
|
|
|
|
154
|
|
|
74
|
|
|
|
|
2182
|
|
7
|
74
|
|
|
74
|
|
600
|
use warnings qw( FATAL utf8 ); |
|
74
|
|
|
|
|
165
|
|
|
74
|
|
|
|
|
2329
|
|
8
|
74
|
|
|
74
|
|
891
|
use utf8; |
|
74
|
|
|
|
|
175
|
|
|
74
|
|
|
|
|
399
|
|
9
|
74
|
|
|
74
|
|
2132
|
use open qw( :std :utf8 ); |
|
74
|
|
|
|
|
173
|
|
|
74
|
|
|
|
|
408
|
|
10
|
74
|
|
|
74
|
|
10125
|
use Unicode::Normalize qw( NFC ); |
|
74
|
|
|
|
|
225
|
|
|
74
|
|
|
|
|
4148
|
|
11
|
74
|
|
|
74
|
|
757
|
use Unicode::Collate; |
|
74
|
|
|
|
|
207
|
|
|
74
|
|
|
|
|
2495
|
|
12
|
74
|
|
|
74
|
|
646
|
use Encode qw( decode ); |
|
74
|
|
|
|
|
188
|
|
|
74
|
|
|
|
|
4774
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
if ( grep /\P{ASCII}/ => @ARGV ) { |
15
|
|
|
|
|
|
|
@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
19
|
|
|
|
|
|
|
|
20
|
74
|
|
|
74
|
|
16409
|
use base qw( Pg::Explain::From ); |
|
74
|
|
|
|
|
176
|
|
|
74
|
|
|
|
|
35433
|
|
21
|
74
|
|
|
74
|
|
32807
|
use YAML::XS; |
|
74
|
|
|
|
|
216842
|
|
|
74
|
|
|
|
|
4400
|
|
22
|
74
|
|
|
74
|
|
765
|
use Carp; |
|
74
|
|
|
|
|
175
|
|
|
74
|
|
|
|
|
3787
|
|
23
|
74
|
|
|
74
|
|
668
|
use Pg::Explain::JIT; |
|
74
|
|
|
|
|
194
|
|
|
74
|
|
|
|
|
1573
|
|
24
|
74
|
|
|
74
|
|
612
|
use Pg::Explain::Buffers; |
|
74
|
|
|
|
|
182
|
|
|
74
|
|
|
|
|
56726
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Pg::Explain::FromYAML - Parser for explains in YAML format |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 VERSION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Version 2.3 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '2.3'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
It's internal class to wrap some work. It should be used by Pg::Explain, and not directly. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 FUNCTIONS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 parse_source |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Function which parses actual plan, and constructs Pg::Explain::Node objects |
47
|
|
|
|
|
|
|
which represent it. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Returns Top node of query plan. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub parse_source { |
54
|
71
|
|
|
71
|
1
|
445
|
my $self = shift; |
55
|
71
|
|
|
|
|
183
|
my $source = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# If this is plan from auto-explain |
58
|
71
|
100
|
|
|
|
896
|
if ( $source =~ s{ \A (\s*) Query \s+ Text : \s+ " ( [^\n]* ) " \s* \n }{}xms ) { |
59
|
5
|
|
|
|
|
199
|
my ( $prefix, $query ) = ( $1, $2 ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Change prefix to two spaces in all lines |
62
|
5
|
|
|
|
|
112
|
$source =~ s{^$prefix}{ }gm; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Add - to first line (should be Plan:) |
65
|
5
|
|
|
|
|
29
|
$source =~ s{ \A \s \s }{- }xms; |
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
|
|
299
|
$query =~ s/\\n/\n/g; |
68
|
5
|
|
|
|
|
19
|
$query =~ s/\\r/\r/g; |
69
|
5
|
|
|
|
|
16
|
$query =~ s/\\t/\t/g; |
70
|
5
|
|
|
|
|
200
|
$query =~ s/\\(.)/$1/g; |
71
|
5
|
|
|
|
|
27
|
$self->explain->query( $query ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
71
|
50
|
|
|
|
1378
|
unless ( $source =~ s{\A .*? ^ (\s*) ( - \s+ Plan: \s*\n )}{$1$2}xms ) { |
76
|
1
|
|
|
|
|
207
|
carp( 'Source does not match first s///' ); |
77
|
1
|
|
|
|
|
7
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
71
|
|
|
|
|
2016
|
$source =~ s{ ^ ( \s* | [^\s-] [^\n] * ) \n .* \z }{}xms; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Make sure boolean variables will be properly marked if/for exporting to JSON |
83
|
71
|
|
|
|
|
457
|
$YAML::XS::Boolean = "JSON::PP"; |
84
|
71
|
|
|
19
|
|
2491
|
my $struct = Load( $source )->[ 0 ]; |
|
18
|
|
|
13
|
|
15505
|
|
|
18
|
|
|
6
|
|
263695
|
|
|
18
|
|
|
5
|
|
4387
|
|
|
12
|
|
|
4
|
|
107
|
|
|
12
|
|
|
3
|
|
35
|
|
|
12
|
|
|
3
|
|
2274
|
|
|
5
|
|
|
2
|
|
36
|
|
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
858
|
|
|
4
|
|
|
|
|
35
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
677
|
|
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
477
|
|
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
356
|
|
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
342
|
|
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
407
|
|
85
|
|
|
|
|
|
|
|
86
|
71
|
|
|
|
|
1000
|
my $top_node = $self->make_node_from( $struct->{ 'Plan' } ); |
87
|
|
|
|
|
|
|
|
88
|
71
|
100
|
|
|
|
612
|
if ( $struct->{ 'Planning' } ) { |
|
|
100
|
|
|
|
|
|
89
|
5
|
|
|
|
|
29
|
$self->explain->planning_time( $struct->{ 'Planning' }->{ 'Planning Time' } ); |
90
|
5
|
|
|
|
|
33
|
my $buffers = Pg::Explain::Buffers->new( $struct->{ 'Planning' } ); |
91
|
5
|
100
|
|
|
|
202
|
$self->explain->planning_buffers( $buffers ) if $buffers; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
elsif ( $struct->{ 'Planning Time' } ) { |
94
|
50
|
|
|
|
|
171
|
$self->explain->planning_time( $struct->{ 'Planning Time' } ); |
95
|
|
|
|
|
|
|
} |
96
|
71
|
100
|
|
|
|
349
|
$self->explain->execution_time( $struct->{ 'Execution Time' } ) if $struct->{ 'Execution Time' }; |
97
|
71
|
100
|
|
|
|
499
|
$self->explain->total_runtime( $struct->{ 'Total Runtime' } ) if $struct->{ 'Total Runtime' }; |
98
|
70
|
100
|
|
|
|
203
|
if ( $struct->{ 'Triggers' } ) { |
99
|
1
|
|
|
|
|
2
|
for my $t ( @{ $struct->{ 'Triggers' } } ) { |
|
1
|
|
|
|
|
4
|
|
100
|
2
|
|
|
|
|
5
|
my $ts = {}; |
101
|
2
|
50
|
|
|
|
8
|
$ts->{ 'calls' } = $t->{ 'Calls' } if defined $t->{ 'Calls' }; |
102
|
2
|
50
|
|
|
|
7
|
$ts->{ 'time' } = $t->{ 'Time' } if defined $t->{ 'Time' }; |
103
|
2
|
50
|
|
|
|
6
|
$ts->{ 'relation' } = $t->{ 'Relation' } if defined $t->{ 'Relation' }; |
104
|
2
|
50
|
|
|
|
7
|
$ts->{ 'name' } = $t->{ 'Trigger Name' } if defined $t->{ 'Trigger Name' }; |
105
|
2
|
|
|
|
|
5
|
$self->explain->add_trigger_time( $ts ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
70
|
100
|
|
|
|
211
|
$self->explain->jit( Pg::Explain::JIT->new( 'struct' => $struct->{ 'JIT' } ) ) if $struct->{ 'JIT' }; |
109
|
|
|
|
|
|
|
|
110
|
70
|
100
|
66
|
|
|
243
|
$self->explain->settings( $struct->{ 'Settings' } ) if ( $struct->{ 'Settings' } ) && ( 0 < scalar keys %{ $struct->{ 'Settings' } } ); |
|
2
|
|
|
|
|
13
|
|
111
|
|
|
|
|
|
|
|
112
|
70
|
|
|
|
|
775
|
return $top_node; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
hubert depesz lubaczewski, C<< >> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 BUGS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please report any bugs or feature requests to C. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SUPPORT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
perldoc Pg::Explain |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright 2008-2021 hubert depesz lubaczewski, all rights reserved. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
134
|
|
|
|
|
|
|
under the same terms as Perl itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; # End of Pg::Explain::FromYAML |