line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pg::SQL::PrettyPrinter::Node::ExplainStmt; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
4
|
2
|
|
|
2
|
|
1592
|
use v5.26; |
|
2
|
|
|
|
|
13
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
41
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
70
|
|
7
|
2
|
|
|
2
|
|
10
|
use warnings qw( FATAL utf8 ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
8
|
2
|
|
|
2
|
|
11
|
use utf8; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
8
|
|
9
|
2
|
|
|
2
|
|
49
|
use open qw( :std :utf8 ); |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
18
|
|
10
|
2
|
|
|
2
|
|
318
|
use Unicode::Normalize qw( NFC ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
134
|
|
11
|
2
|
|
|
2
|
|
38
|
use Unicode::Collate; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
82
|
|
12
|
2
|
|
|
2
|
|
21
|
use Encode qw( decode ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
134
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
if ( grep /\P{ASCII}/ => @ARGV ) { |
15
|
|
|
|
|
|
|
@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# If there is __DATA__,then uncomment next line: |
19
|
|
|
|
|
|
|
# binmode( DATA, ':encoding(UTF-8)' ); |
20
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Useful common code |
23
|
2
|
|
|
2
|
|
496
|
use autodie; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
24
|
2
|
|
|
2
|
|
10985
|
use Carp qw( carp croak confess cluck ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
158
|
|
25
|
2
|
|
|
2
|
|
13
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
26
|
2
|
|
|
2
|
|
787
|
use Data::Dumper qw( Dumper ); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
447
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# give a full stack dump on any untrapped exceptions |
29
|
|
|
|
|
|
|
local $SIG{ __DIE__ } = sub { |
30
|
|
|
|
|
|
|
confess "Uncaught exception: @_" unless $^S; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# now promote run-time warnings into stackdumped exceptions |
34
|
|
|
|
|
|
|
# *unless* we're in an try block, in which |
35
|
|
|
|
|
|
|
# case just generate a clucking stackdump instead |
36
|
|
|
|
|
|
|
local $SIG{ __WARN__ } = sub { |
37
|
|
|
|
|
|
|
if ( $^S ) { cluck "Trapped warning: @_" } |
38
|
|
|
|
|
|
|
else { confess "Deadly warning: @_" } |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Useful common code |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
2
|
|
16
|
use parent qw( Pg::SQL::PrettyPrinter::Node ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
5
|
|
|
5
|
1
|
166
|
my $class = shift; |
47
|
5
|
|
|
|
|
23
|
my $self = $class->SUPER::new( @_ ); |
48
|
5
|
|
|
|
|
9
|
bless $self, $class; |
49
|
|
|
|
|
|
|
|
50
|
5
|
|
|
|
|
20
|
$self->objectify( qw( query options ) ); |
51
|
|
|
|
|
|
|
|
52
|
5
|
100
|
|
|
|
12
|
if ( exists $self->{ 'options' } ) { |
53
|
4
|
|
|
|
|
8
|
$self->{ '_options' } = [ map { $_->as_text } @{ $self->{ 'options' } } ]; |
|
13
|
|
|
|
|
29
|
|
|
4
|
|
|
|
|
13
|
|
54
|
|
|
|
|
|
|
} |
55
|
5
|
|
|
|
|
13
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub as_text { |
59
|
5
|
|
|
5
|
1
|
22
|
my $self = shift; |
60
|
5
|
100
|
|
|
|
16
|
return 'EXPLAIN ' . $self->{ 'query' }->as_text unless exists $self->{ 'options' }; |
61
|
4
|
|
|
|
|
9
|
my @elements = (); |
62
|
4
|
|
|
|
|
8
|
push @elements, 'EXPLAIN'; |
63
|
4
|
100
|
|
|
|
9
|
if ( $self->has_complex_opts ) { |
64
|
1
|
|
|
|
|
4
|
push @elements, '('; |
65
|
1
|
|
|
|
|
3
|
push @elements, join( ', ', @{ $self->{ '_options' } } ); |
|
1
|
|
|
|
|
14
|
|
66
|
1
|
|
|
|
|
3
|
push @elements, ')'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
3
|
|
|
|
|
6
|
push @elements, map { uc $_ } @{ $self->{ '_options' } }; |
|
4
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
6
|
|
70
|
|
|
|
|
|
|
} |
71
|
4
|
|
|
|
|
14
|
push @elements, $self->{ 'query' }->as_text; |
72
|
4
|
|
|
|
|
18
|
return join( ' ', @elements ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub has_complex_opts { |
76
|
8
|
|
|
8
|
1
|
14
|
my $self = shift; |
77
|
8
|
50
|
|
|
|
20
|
return unless exists $self->{ '_options' }; |
78
|
8
|
|
|
|
|
14
|
for my $key ( @{ $self->{ '_options' } } ) { |
|
8
|
|
|
|
|
20
|
|
79
|
14
|
100
|
|
|
|
60
|
return 1 unless $key =~ m{\A(?:analyze|verbose)\z}; |
80
|
|
|
|
|
|
|
} |
81
|
6
|
|
|
|
|
17
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub pretty_print { |
85
|
5
|
|
|
5
|
1
|
3883
|
my $self = shift; |
86
|
5
|
|
|
|
|
11
|
my @lines = (); |
87
|
5
|
|
|
|
|
13
|
push @lines, 'EXPLAIN'; |
88
|
5
|
100
|
|
|
|
17
|
if ( exists $self->{ 'options' } ) { |
89
|
4
|
100
|
|
|
|
11
|
if ( $self->has_complex_opts ) { |
90
|
1
|
|
|
|
|
3
|
$lines[ -1 ] .= ' ('; |
91
|
1
|
|
|
|
|
5
|
push @lines, map { $self->increase_indent( $_ ) . ',' } @{ $self->{ '_options' } }; |
|
9
|
|
|
|
|
24
|
|
|
1
|
|
|
|
|
4
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Remove unnecessary trailing , in last element |
94
|
1
|
|
|
|
|
6
|
$lines[ -1 ] =~ s/,\z//; |
95
|
1
|
|
|
|
|
3
|
push @lines, ')'; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
3
|
|
|
|
|
7
|
$lines[ -1 ] .= ' ' . join( ' ', map { uc $_ } @{ $self->{ '_options' } } ); |
|
4
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
8
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
5
|
|
|
|
|
21
|
push @lines, $self->{ 'query' }->pretty_print; |
102
|
5
|
|
|
|
|
25
|
return join( "\n", @lines ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# vim: set ft=perl: |