From 117e82408036b85d6c8caa2c6c4919d6285387f5 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Mon, 5 May 2014 15:16:05 +0800 Subject: Bug 999331: searching attachment data is very slow due to an unbounded select --- Bugzilla/Search.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index e060de990..0665fbd96 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -2091,6 +2091,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"; -- cgit v1.2.3-24-g4f1b