[Rt-commit] rt branch, 4.4/chart-sql-subquery, created. rt-4.4.4-255-gf2dc4ffd95

? sunnavy sunnavy at bestpractical.com
Thu Mar 4 16:44:08 EST 2021


The branch, 4.4/chart-sql-subquery has been created
        at  f2dc4ffd95b9400296200ba672df292e9e39253d (commit)

- Log -----------------------------------------------------------------
commit f2dc4ffd95b9400296200ba672df292e9e39253d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Mar 4 07:58:10 2021 +0800

    Use subquery when possible in case ticket ids are too many for search chart
    
    This is mainly for performance. E.g. my local test shows that for 100k
    tickets, the chart rendering is 4x faster on MariaDB and 15x faster on
    PostgreSQL. It's 5x faster on Oracle with 10k tickets.

diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 01e9b72d3c..e702349e14 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -492,21 +492,29 @@ sub SetupGroupings {
         # If it isn't, we need to do this in two stages -- first, find
         # the distinct matching tickets (with no group by), then search
         # within the matching tickets grouped by what is wanted.
-        my @match = (0);
         $self->Columns( 'id' );
-        while (my $row = $self->Next) {
-            push @match, $row->id;
+        if ( RT->Config->Get('UseSQLForACLChecks') ) {
+            my $query = $self->BuildSelectQuery;
+            $self->CleanSlate;
+            $self->Limit( FIELD => 'Id', OPERATOR => 'IN', VALUE => "($query)", QUOTEVALUE => 0 );
         }
+        else {
+            # ACL is done in Next call
+            my @match = (0);
+            while ( my $row = $self->Next ) {
+                push @match, $row->id;
+            }
 
-        # Replace the query with one that matches precisely those
-        # tickets, with no joins.  We then mark it as having been ACL'd,
-        # since it was by dint of being in the search results above
-        $self->CleanSlate;
-        while ( @match > 1000 ) {
-            my @batch = splice( @match, 0, 1000 );
-            $self->Limit( FIELD => 'Id', OPERATOR => 'IN', VALUE => \@batch );
+            # Replace the query with one that matches precisely those
+            # tickets, with no joins.  We then mark it as having been ACL'd,
+            # since it was by dint of being in the search results above
+            $self->CleanSlate;
+            while ( @match > 1000 ) {
+                my @batch = splice( @match, 0, 1000 );
+                $self->Limit( FIELD => 'Id', OPERATOR => 'IN', VALUE => \@batch );
+            }
+            $self->Limit( FIELD => 'Id', OPERATOR => 'IN', VALUE => \@match );
         }
-        $self->Limit( FIELD => 'Id', OPERATOR => 'IN', VALUE => \@match );
         $self->{'_sql_current_user_can_see_applied'} = 1
     }
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list