Index: includes/query.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/query.inc,v retrieving revision 1.15 diff -u -F^f -r1.15 query.inc --- includes/query.inc 22 Apr 2008 05:34:03 -0000 1.15 +++ includes/query.inc 8 May 2008 21:59:53 -0000 @@ -375,6 +375,37 @@ } if ($this->ensure_path($table, $relationship, $join)) { + + // Attempt to eliminate redundant joins. If this table's + // relationship and join exactly matches an existing table's + // relationship and join, we do not have to join to it again; + // just return the existing table's alias. See + // http://groups.drupal.org/node/11288 for details. + // + // TODO: Scanning through $this->table_queue results in an + // O(N^2) algorithm. N is small but we can probably do better. + + // If we do not have join info, get it the same way queue_table + // will get it. + // + // TODO: I do not yet grok adjust_join(). + if (! isset($join)) { + $join = $this->get_join_data($table, $this->relationships[$relationship]['base']); + } + + // If we have join info, scan through the table queue to see if + // a matching join and relationship exists. If so, use it. + if (isset($join)) { + foreach ($this->table_queue as $quetab) { + // In PHP 4 and 5, the == operation returns TRUE for two objects + // if they are instances of the same class and have the same + // attributes and values. + if ($quetab['relationship'] == $relationship && $quetab['join'] == $join) { + return $quetab['table']; + } + } + } + return $this->queue_table($table, $relationship, $join); } }