[Bps-public-commit] r20070 - DBIx-SearchBuilder/trunk

ruz at bestpractical.com ruz at bestpractical.com
Tue Jun 30 18:43:21 EDT 2009


Author: ruz
Date: Tue Jun 30 18:43:20 2009
New Revision: 20070

Modified:
   DBIx-SearchBuilder/trunk/SearchBuilder.pm

Log:
* let's move group_by vs. distinct to upper level

Modified: DBIx-SearchBuilder/trunk/SearchBuilder.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder.pm	(original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder.pm	Tue Jun 30 18:43:20 2009
@@ -430,11 +430,19 @@
       if ( $self->_isLimited > 0 );
 
     # DISTINCT query only required for multi-table selects
-    if ($self->_isJoined) {
+    # when we have group by clause then the result set is distinct as
+    # it must contain only columns we group by or results of aggregate
+    # functions which give one result per group, so we can skip DISTINCTing
+    if ( my $clause = $self->_GroupClause ) {
+        $QueryString = "SELECT main.* FROM $QueryString";
+        $QueryString .= $clause;
+        $QueryString .= $self->_OrderClause;
+    }
+    elsif ($self->_isJoined) {
         $self->_DistinctQuery(\$QueryString);
-    } else {
+    }
+    else {
         $QueryString = "SELECT main.* FROM $QueryString";
-        $QueryString .= $self->_GroupClause;
         $QueryString .= $self->_OrderClause;
     }
 



More information about the Bps-public-commit mailing list