From: Byron Jones Date: Mon, 5 May 2014 07:15:37 +0000 (+0800) Subject: Bug 999331: searching attachment data is very slow due to an unbounded X-Git-Tag: bugzilla-4.4.5~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbc08e72fa2cb0bd711ea3c82d9e3530ae88184b;p=thirdparty%2Fbugzilla.git Bug 999331: searching attachment data is very slow due to an unbounded select r=LpSolit, a=glob --- diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index f900b34740..7df9d04c1e 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -1968,6 +1968,13 @@ sub _quote_unless_numeric { sub build_subselect { my ($outer, $inner, $table, $cond, $negate) = @_; + if ($table =~ /\battach_data\b/) { + # It takes a long time to scan the whole attach_data table + # unconditionally, so we return the subselect and let the DB optimizer + # restrict the search based on other search criteria. + my $not = $negate ? "NOT" : ""; + return "$outer $not IN (SELECT DISTINCT $inner FROM $table WHERE $cond)"; + } # Execute subselects immediately to avoid dependent subqueries, which are # large performance hits on MySql my $q = "SELECT DISTINCT $inner FROM $table WHERE $cond";