]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 999331: searching attachment data is very slow due to an unbounded
authorByron Jones <glob@mozilla.com>
Mon, 5 May 2014 07:15:37 +0000 (15:15 +0800)
committerByron Jones <glob@mozilla.com>
Mon, 5 May 2014 07:15:37 +0000 (15:15 +0800)
select
r=LpSolit, a=glob

Bugzilla/Search.pm

index f900b347404f7f3828d9e2ff2b826a87b72f35be..7df9d04c1e2dd6525299184e7212b21dbf50a796 100644 (file)
@@ -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";