Skip to content

Commit

Permalink
Revert commit 5e88446, with very logn queries this was worth than
Browse files Browse the repository at this point in the history
truncating at --maxlength (10Kb by default). Thanks to Bhushan Uparkar
for the report.
  • Loading branch information
Gilles Darold committed Aug 1, 2019
1 parent b014cb3 commit a87fd55
Showing 1 changed file with 1 addition and 72 deletions.
73 changes: 1 addition & 72 deletions pgbadger
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ my $ident = '';
my $top = 0;
my $sample = 3;
my $extension = '';
my $maxlength = 10240;
my $maxlength = 10480;
my $graph = 1;
my $nograph = 0;
my $debug = 0;
Expand Down Expand Up @@ -4313,47 +4313,6 @@ sub anonymize_query
return $orig_query;
}

# Limit size of SQL queries by truncating parameters values
sub limit_param_size
{
my $orig_query = shift;

return if (!$orig_query);

# Variable to hold parameters
my @param_cache = ();

# Remove comments
$orig_query =~ s/\/\*(.*?)\*\///gs;

# Clean query
$orig_query =~ s/\\'//g;
$orig_query =~ s/('')+//g;

# Anonymize each values
my $i = 0;
while ($orig_query =~ s/([^\s]+[\s\(]*)'([^']*)'/$1\%PGB$i\%/s)
{
push(@param_cache, $2);
$i++;
}

# Limit size of paramaters
for ($i = 0; $i <= $#param_cache; $i++)
{
if (length($param_cache[$i]) > $param_size_limit)
{
$param_cache[$i] = substr($param_cache[$i], 0, $param_size_limit) . '[...]';
}
}

# Restore parameters
$orig_query =~ s/\%PGB(\d+)\%/'$param_cache[$1]'/g;

return $orig_query;
}


# Format numbers with comma for betterparam_cache reading
sub comma_numbers
{
Expand Down Expand Up @@ -14547,12 +14506,6 @@ sub store_queries
return 1;
}

# First limit query size at parameter length
if ($maxlength > 0 && (length($cur_info{$t_pid}{query}) > $maxlength))
{
$cur_info{$t_pid}{query} = &limit_param_size($cur_info{$t_pid}{query});
}

# Truncate the query if requested by the user
$cur_info{$t_pid}{query} = substr($cur_info{$t_pid}{query}, 0, $maxlength) . '[...]'
if (($maxlength > 0) && (length($cur_info{$t_pid}{query}) > $maxlength));
Expand All @@ -14562,12 +14515,6 @@ sub store_queries
# We only process stored object with query here
if ($cur_info{$t_pid}{statement})
{
# First limit statement size at parameter length
if ($maxlength > 0 && (length($cur_info{$t_pid}{statement}) > $maxlength))
{
$cur_info{$t_pid}{statement} = &limit_param_size($cur_info{$t_pid}{statement});
}

# Truncate the statement if requested by the user
$cur_info{$t_pid}{statement} = substr($cur_info{$t_pid}{statement}, 0, $maxlength) . '[...]'
if (($maxlength > 0) && (length($cur_info{$t_pid}{statement}) > $maxlength));
Expand Down Expand Up @@ -14881,12 +14828,6 @@ sub store_temporary_and_lock_infos
$cur_temp_info{$t_pid}{query} = &anonymize_query($cur_temp_info{$t_pid}{query});
}

# First limit query size at parameter length
if ($maxlength > 0 && (length($cur_temp_info{$t_pid}{query}) > $maxlength))
{
$cur_temp_info{$t_pid}{query} = &limit_param_size($cur_temp_info{$t_pid}{query});
}

# Truncate the query if requested by the user
$cur_temp_info{$t_pid}{query} = substr($cur_temp_info{$t_pid}{query}, 0, $maxlength) . '[...]'
if (($maxlength > 0) && (length($cur_temp_info{$t_pid}{query}) > $maxlength));
Expand Down Expand Up @@ -14942,12 +14883,6 @@ sub store_temporary_and_lock_infos
$cur_lock_info{$t_pid}{query} = &anonymize_query($cur_lock_info{$t_pid}{query});
}

# First limit query size at parameter length
if ($maxlength > 0 && (length($cur_lock_info{$t_pid}{query}) > $maxlength))
{
$cur_lock_info{$t_pid}{query} = &limit_param_size($cur_lock_info{$t_pid}{query});
}

# Truncate the query if requested by the user
$cur_lock_info{$t_pid}{query} = substr($cur_lock_info{$t_pid}{query}, 0, $maxlength) . '[...]'
if (($maxlength > 0) && (length($cur_lock_info{$t_pid}{query}) > $maxlength));
Expand Down Expand Up @@ -14998,12 +14933,6 @@ sub store_temporary_and_lock_infos
$cur_cancel_info{$t_pid}{query} = &anonymize_query($cur_cancel_info{$t_pid}{query});
}

# First limit query size at parameter length
if ($maxlength > 0 && (length($cur_cancel_info{$t_pid}{query}) > $maxlength))
{
$cur_cancel_info{$t_pid}{query} = &limit_param_size($cur_cancel_info{$t_pid}{query});
}

# Truncate the query if requested by the user
$cur_cancel_info{$t_pid}{query} = substr($cur_cancel_info{$t_pid}{query}, 0, $maxlength) . '[...]'
if (($maxlength > 0) && (length($cur_cancel_info{$t_pid}{query}) > $maxlength));
Expand Down

0 comments on commit a87fd55

Please sign in to comment.