File Coverage

blib/lib/Pg/Explain/Hinter/Hint.pm
Criterion Covered Total %
statement 48 48 100.0
branch 10 14 71.4
condition n/a
subroutine 14 14 100.0
pod 4 4 100.0
total 76 80 95.0


line stmt bran cond sub pod time code
1             package Pg::Explain::Hinter::Hint;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 5     5   59 use v5.18;
  5         20  
5 5     5   25 use strict;
  5         12  
  5         98  
6 5     5   26 use warnings;
  5         10  
  5         146  
7 5     5   26 use warnings qw( FATAL utf8 );
  5         10  
  5         200  
8 5     5   35 use utf8;
  5         31  
  5         34  
9 5     5   204 use open qw( :std :utf8 );
  5         14  
  5         38  
10 5     5   669 use Unicode::Normalize qw( NFC );
  5         13  
  5         282  
11 5     5   35 use Unicode::Collate;
  5         8  
  5         141  
12 5     5   23 use Encode qw( decode );
  5         12  
  5         345  
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 5     5   992 use Carp;
  5         13  
  5         2204  
21              
22             =head1 NAME
23              
24             Pg::Explain::Hinter::Hint - Single hint for Pg::Explain plan
25              
26             =head1 VERSION
27              
28             Version 2.3
29              
30             =cut
31              
32             our $VERSION = '2.3';
33              
34             =head1 SYNOPSIS
35              
36             These should be returned by Pg::Explain::Hinter, using:
37              
38             my $hinter = Pg::Explain::Hinter->new( $plan );
39             if ( $hinter->any_hints ) {
40             for my $hint ( @{ $hinter->hints } ) {
41             ...
42             printf "Hint for node #%d (%s) : %s\n", $hint->node->id, $hint->node_type, $hint->type;
43             if ( $hint->details ) {
44             print Dumper($hint->details);
45             }
46             }
47             }
48              
49             Read "HINT TYPES" part for more description of what hint types there can be, and what is the meaning of details for them.
50              
51             =head1 FUNCTIONS
52              
53             =head2 new
54              
55             Object constructor.
56              
57             =cut
58              
59             sub new {
60 42     42 1 74 my $class = shift;
61 42         163 my %args = @_;
62 42 50       103 croak( 'There is no node arg!' ) unless $args{ 'node' };
63 42 50       113 croak( 'Given node is not Pg::Explain::Node object!' ) unless 'Pg::Explain::Node' eq ref $args{ 'node' };
64 42 50       85 croak( 'There is no type arg!' ) unless $args{ 'type' };
65 42         84 my $self = bless {}, $class;
66 42         114 $self->type( $args{ 'type' } );
67 42         98 $self->node( $args{ 'node' } );
68 42 50       126 $self->details( $args{ 'details' } ) if $args{ 'details' };
69 42         132 return $self;
70             }
71              
72             =head2 type
73              
74             Accessor for type inside hint.
75              
76             =cut
77              
78             sub type {
79 84     84 1 137 my $self = shift;
80 84 100       233 $self->{ 'type' } = $_[ 0 ] if 0 < scalar @_;
81 84         236 return $self->{ 'type' };
82             }
83              
84             =head2 node
85              
86             Accessor for node inside hint.
87              
88             =cut
89              
90             sub node {
91 84     84 1 14755 my $self = shift;
92 84 100       193 $self->{ 'node' } = $_[ 0 ] if 0 < scalar @_;
93 84         188 return $self->{ 'node' };
94             }
95              
96             =head2 details
97              
98             Accessor for details inside hint.
99              
100             =cut
101              
102             sub details {
103 208     208 1 371 my $self = shift;
104 208 100       527 $self->{ 'details' } = $_[ 0 ] if 0 < scalar @_;
105 208         751 return $self->{ 'details' };
106             }
107              
108             =head1 HINT TYPES
109              
110             There are various types of hints, and each have their own meaning of ->details:
111              
112             =head2 DISK_SORT
113              
114             Node that the hint is for is using sorting that is spilling to disk. It's possible that increasing work_mem would help.
115              
116             Details:
117              
118             =over
119              
120             =item * Used disk space in kB
121              
122             =back
123              
124             =head2 INDEXABLE_SEQSCAN_SIMPLE
125              
126             Node that the hint is for is using sequential scan, but it should be possible to add simple index (on one column) that will make it faster.
127              
128             Details:
129              
130             =over
131              
132             =item * Column name that the index should be made on
133              
134             =back
135              
136             =head2 INDEXABLE_SEQSCAN_MULTI_EQUAL_AND
137              
138             Node that the hint is for us using sequential scan, and it should be possible to add index(es) to make it go faster.
139              
140             This happens only for scans that have multiple equality checks joined with AND operator, like:
141              
142             =over
143              
144             =item * a = 1 and b = 2
145              
146             =item * x = 'abc' and z = 12
147              
148             =back
149              
150             Details are arrayref where each element is hashref with two keys:
151              
152             =over
153              
154             =item * column : column name that was checked
155              
156             =item * value : the value that the check was using
157              
158             =back
159              
160             =head1 AUTHOR
161              
162             hubert depesz lubaczewski, C<< >>
163              
164             =head1 BUGS
165              
166             Please report any bugs or feature requests to C.
167              
168             =head1 SUPPORT
169              
170             You can find documentation for this module with the perldoc command.
171              
172             perldoc Pg::Explain::Node
173              
174             =head1 COPYRIGHT & LICENSE
175              
176             Copyright 2008-2021 hubert depesz lubaczewski, all rights reserved.
177              
178             This program is free software; you can redistribute it and/or modify it
179             under the same terms as Perl itself.
180              
181             =cut
182              
183             1; # End of Pg::Explain::Hinter