From eddd05213730c2d41260c589c97730ec84b67a70 Mon Sep 17 00:00:00 2001 From: Hubert depesz Lubaczewski Date: Sun, 6 Feb 2022 17:00:12 +0100 Subject: [PATCH] change output of find_interesting_plans --- scripts/find_interesting_plans | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/scripts/find_interesting_plans b/scripts/find_interesting_plans index 14f32b5..d0f22fd 100755 --- a/scripts/find_interesting_plans +++ b/scripts/find_interesting_plans @@ -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 {