1
0
mirror of https://gitlab.com/depesz/explain.depesz.com.git synced 2024-11-28 08:58:52 +02:00

change output of find_interesting_plans

This commit is contained in:
Hubert depesz Lubaczewski 2022-02-06 17:00:12 +01:00
parent 5fd2f83e2e
commit eddd052137

View File

@ -60,6 +60,8 @@ for my $partno ( 0 .. $#{ $partitions } ) {
$pm->start and next PARTITION;
printf "Starting partition #%d\n", 1 + $partno;
open my $out, '>', "${output}/${part}.txt";
my $dbh = get_dbh();
my $seen = 0;
@ -83,18 +85,21 @@ for my $partno ( 0 .. $#{ $partitions } ) {
next;
}
next unless $explain->top_node;
next unless is_plan_interesting( $explain );
$interesting++;
my $output_path = sprintf '%s/%s.plan', $output, $row->{ 'id' };
open my $fh, '>', $output_path;
print $fh $row->{ 'plan' };
close $fh;
my $is_interesting = 0;
for my $line ( @{ output_lines( $row->{'id'}, $explain ) } ) {
print $out join("\t", @{$line}) . "\n";
$is_interesting = 1;
}
$interesting++ if $is_interesting;
}
}
$dbh->rollback();
$dbh->disconnect();
close $out;
printf "Partition %d done. %d plans scanned, %d errored out, %d interesting saved.\n", 1 + $partno, $seen, $errors, $interesting;
$pm->finish;
}
@ -104,18 +109,29 @@ printf "All done, output in %s\n", $output;
exit;
sub is_plan_interesting {
my $plan = shift;
sub output_lines {
my ( $id, $plan ) = @_;
my $ret = [];
for my $node ( $plan->top_node, $plan->top_node->all_recursive_subnodes ) {
next unless $node->estimated_row_width;
next unless $node->total_rows;
next unless $node->total_rows > 200;
next unless $node->total_rows_removed;
next unless $node->total_rows_removed > 9 * $node->total_rows;
next unless $node->extra_info;
next unless any { /^Filter:/ } @{ $node->extra_info };
return 1;
# At least 3 pages worth of data is returned
next unless $node->total_rows * $node->estimated_row_width > 3 * 8192;
# At least 90% of rows were removed
next unless $node->total_rows_removed > 9 * $node->total_rows;
my @filter_lines = grep { /^Filter:/ } @{ $node->extra_info };
# There are filter expressions
next if 0 == scalar @filter_lines;
push @{ $ret }, map { [ $id, $node->id, $node->type, $node->estimated_row_width, $node->total_rows, $node->total_rows_removed, $_ ] } @filter_lines;
}
return;
return $ret;
}
sub get_dbh {