diff options
author | mkanat%bugzilla.org <> | 2008-08-01 07:37:15 +0200 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2008-08-01 07:37:15 +0200 |
commit | 73a4dd56109c4799fd1d4ac7ed56ff72a47279bb (patch) | |
tree | 1b029a07667f48b1eb80507b815905ef9bb217f3 /Bugzilla | |
parent | d165b7785df760352ce17d3677691c5be0b3b6c4 (diff) | |
download | bugzilla-73a4dd56109c4799fd1d4ac7ed56ff72a47279bb.tar.gz bugzilla-73a4dd56109c4799fd1d4ac7ed56ff72a47279bb.tar.xz |
Bug 440188: buglist.cgi should display EXPLAIN output when &debug=1
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/DB.pm | 2 | ||||
-rw-r--r-- | Bugzilla/DB/Mysql.pm | 26 | ||||
-rw-r--r-- | Bugzilla/DB/Oracle.pm | 9 | ||||
-rw-r--r-- | Bugzilla/DB/Pg.pm | 6 |
4 files changed, 42 insertions, 1 deletions
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index b23c865c1..399f3c643 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -273,7 +273,7 @@ EOT # List of abstract methods we are checking the derived class implements our @_abstract_methods = qw(REQUIRED_VERSION PROGRAM_NAME DBD_VERSION new sql_regexp sql_not_regexp sql_limit sql_to_days - sql_date_format sql_interval); + sql_date_format sql_interval bz_explain); # This overridden import method will check implementation of inherited classes # for missing implementation of abstract methods diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm index 8a64d3646..fdb475078 100644 --- a/Bugzilla/DB/Mysql.pm +++ b/Bugzilla/DB/Mysql.pm @@ -48,6 +48,8 @@ use Bugzilla::Util; use Bugzilla::Error; use Bugzilla::DB::Schema::Mysql; +use List::Util qw(max); + # This module extends the DB interface via inheritance use base qw(Bugzilla::DB); @@ -204,6 +206,30 @@ sub sql_group_by { return "GROUP BY $needed_columns"; } +sub bz_explain { + my ($self, $sql) = @_; + my $sth = $self->prepare("EXPLAIN $sql"); + $sth->execute(); + my $columns = $sth->{'NAME'}; + my $lengths = $sth->{'mysql_max_length'}; + my $format_string = '|'; + my $i = 0; + foreach my $column (@$columns) { + # Sometimes the column name is longer than the contents. + my $length = max($lengths->[$i], length($column)); + $format_string .= ' %-' . $length . 's |'; + $i++; + } + + my $first_row = sprintf($format_string, @$columns); + my @explain_rows = ($first_row, '-' x length($first_row)); + while (my $row = $sth->fetchrow_arrayref) { + my @fixed = map { defined $_ ? $_ : 'NULL' } @$row; + push(@explain_rows, sprintf($format_string, @fixed)); + } + + return join("\n", @explain_rows); +} sub _bz_get_initial_schema { my ($self) = @_; diff --git a/Bugzilla/DB/Oracle.pm b/Bugzilla/DB/Oracle.pm index 56d9d3fbf..341818a5c 100644 --- a/Bugzilla/DB/Oracle.pm +++ b/Bugzilla/DB/Oracle.pm @@ -104,6 +104,15 @@ sub bz_check_regexp { { value => $pattern, dberror => $self->errstr }); } +sub bz_explain { + my ($self, $sql) = @_; + my $sth = $self->prepare("EXPLAIN PLAN FOR $sql"); + $sth->execute(); + my $explain = $self->selectcol_arrayref( + "SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY)"); + return join("\n", @$explain); +} + sub sql_regexp { my ($self, $expr, $pattern, $nocheck) = @_; diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index a6a2e3281..d06decaa3 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -171,6 +171,12 @@ sub bz_sequence_exists { return $exists || 0; } +sub bz_explain { + my ($self, $sql) = @_; + my $explain = $self->selectcol_arrayref("EXPLAIN ANALYZE $sql"); + return join("\n", @$explain); +} + ##################################################################### # Custom Database Setup ##################################################################### |