[Rt-commit] [svn] r1966 - in rt/branches/3.2-RELEASE: . lib/RT

jesse at pallas.eruditorum.org jesse at pallas.eruditorum.org
Tue Dec 7 17:48:34 EST 2004


Author: jesse
Date: Tue Dec  7 17:48:33 2004
New Revision: 1966

Modified:
   rt/branches/3.2-RELEASE/   (props changed)
   rt/branches/3.2-RELEASE/lib/RT/Tickets_Overlay.pm
Log:
 r9522 at tinbook:  jesse | 2004-12-07T22:47:20.573617Z
 RT-Ticket: 6286
 RT-Status: resolved
 RT-Update: correspond
 
 Searching on Ticket data  and Transaction content caused horribly pessimal searches.
 
 OLD
 
 mysql> explain SELECT DISTINCT main.* FROM Tickets main , Transactions Transactions_1, Attachments Attachments_2  WHERE ((main.EffectiveId = main.id)) AND ((main.Status != 'deleted')) AND ((main.Type = 'ticket')) AND ((main.Subject LIKE '%subject/content SQL test%')OR ( (Attachments_2.Content LIKE '%subject/content SQL test%')AND(Attachments_2.TransactionId = Transactions_1.id)AND(main.id = Transactions_1.Ticket) ) );
 +----------------+-------+-----------------------+---------------+---------+------+------+------------------------------------+
 | table          | type  | possible_keys         | key           | key_len | ref  | rows | Extra                              |
 +----------------+-------+-----------------------+---------------+---------+------+------+------------------------------------+
 | main           | ALL   | PRIMARY               | NULL          |    NULL | NULL |   30 | Using where; Using temporary       |
 | Attachments_2  | ALL   | Attachments2          | NULL          |    NULL | NULL |   22 | Using where; Distinct              |
 | Transactions_1 | index | PRIMARY,Transactions1 | Transactions1 |       4 | NULL |   73 | Using where; Using index; Distinct |
 +----------------+-------+-----------------------+---------------+---------+------+------+------------------------------------+
 3 rows in set (0.00 sec)
 
 NEW
 
 mysql> explain SELECT DISTINCT main.* FROM ((Tickets main  LEFT JOIN Transactions Transactions_1  ON ( main.id = Transactions_1.Ticket))  LEFT JOIN Attachments Attachments_2  ON ( Transactions_1.id = Attachments_2.TransactionId))   WHERE ((main.EffectiveId = main.id)) AND ((main.Status != 'deleted')) AND ((main.Type = 'ticket')) AND ((main.Subject LIKE '%subject/content SQL test%')OR ( (Attachments_2.Content LIKE '%subject/content SQL test%') ) );
 +----------------+------+---------------+---------------+---------+-------------------+------+------------------------------+
 | table          | type | possible_keys | key           | key_len | ref               | rows | Extra                        |
 +----------------+------+---------------+---------------+---------+-------------------+------+------------------------------+
 | main           | ALL  | NULL          | NULL          |    NULL | NULL              |   30 | Using where; Using temporary |
 | Transactions_1 | ref  | Transactions1 | Transactions1 |       4 | main.id           |    1 | Using index; Distinct        |
 | Attachments_2  | ref  | Attachments2  | Attachments2  |       4 | Transactions_1.id |    1 | Using where; Distinct        |
 +----------------+------+---------------+---------------+---------+-------------------+------+------------------------------+
 3 rows in set (0.03 sec)
 
 
 


Modified: rt/branches/3.2-RELEASE/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/3.2-RELEASE/lib/RT/Tickets_Overlay.pm	(original)
+++ rt/branches/3.2-RELEASE/lib/RT/Tickets_Overlay.pm	Tue Dec  7 17:48:33 2004
@@ -478,22 +478,9 @@
   my ($sb,$field,$op,$value, at rest) = @_;
 
   # See the comments for TransLimit, they apply here too
-
-  $sb->{_sql_transalias} = $sb->NewAlias ('Transactions')
-    unless defined $sb->{_sql_transalias};
-  $sb->{_sql_trattachalias} = $sb->NewAlias ('Attachments')
-    unless defined $sb->{_sql_trattachalias};
+  $sb->_SetupTransactionJoins();
 
   $sb->_OpenParen;
-
-  # Join Transactions To Attachments
-  $sb->_SQLJoin( ALIAS1 => $sb->{_sql_trattachalias}, FIELD1 => 'TransactionId',
-	     ALIAS2 => $sb->{_sql_transalias}, FIELD2 => 'id');
-
-  # Join Transactions to Tickets
-  $sb->_SQLJoin( ALIAS1 => 'main', FIELD1 => $sb->{'primary_key'}, # UGH!
-	     ALIAS2 => $sb->{_sql_transalias}, FIELD2 => 'Ticket');
-
   my $d = new RT::Date( $sb->CurrentUser );
   $d->Set( Format => 'ISO', Value => $value);
    $value = $d->ISO;
@@ -554,10 +541,7 @@
 
   my ($sb,$field,$op,$value, at rest) = @_;
 
-  $sb->{_sql_transalias} = $sb->NewAlias ('Transactions')
-    unless defined $sb->{_sql_transalias};
-  $sb->{_sql_trattachalias} = $sb->NewAlias ('Attachments')
-    unless defined $sb->{_sql_trattachalias};
+    $sb->_SetupTransactionJoins();
 
   $sb->_OpenParen;
 
@@ -570,13 +554,6 @@
 		 @rest
 		);
 
-  # Join Transactions To Attachments
-  $sb->_SQLJoin( ALIAS1 => $sb->{_sql_trattachalias}, FIELD1 => 'TransactionId',
-	     ALIAS2 => $sb->{_sql_transalias}, FIELD2 => 'id');
-
-  # Join Transactions to Tickets
-  $sb->_SQLJoin( ALIAS1 => 'main', FIELD1 => $sb->{'primary_key'}, # UGH!
-	     ALIAS2 => $sb->{_sql_transalias}, FIELD2 => 'Ticket');
 
   $sb->_CloseParen;
 
@@ -882,6 +859,28 @@
 
 }
 
+sub _SetupTransactionJoins {
+    my $self = shift;
+    # Join Transactions to Tickets
+    $self->{_sql_transalias} ||= $self->Join(
+        TYPE => 'LEFT',
+        ALIAS1 => 'main',
+        FIELD1 => $self->{'primary_key'},    # UGH!
+        TABLE2 => 'Transactions',
+        FIELD2 => 'Ticket'
+    );
+
+    # Join Transactions To Attachments
+    $self->{_sql_trattachalias} ||= $self->Join(
+        TYPE => 'LEFT',
+        TABLE2 => 'Attachments',
+        FIELD2 => 'TransactionId',
+        ALIAS1 => $self->{_sql_transalias},
+        FIELD1 => 'id'
+    );
+
+}
+
 
 # End Helper Functions
 


More information about the Rt-commit mailing list