--- node.module.unmodified      2006-08-02 21:09:45.000000000 -0400
+++ node.module 2006-08-02 21:40:07.000000000 -0400
@@ -2347,26 +2347,6 @@
 }

 /**
- * Generate an SQL join clause for use in fetching a node listing.
- *
- * @param $node_alias
- *   If the node table has been given an SQL alias other than the default
- *   "n", that must be passed here.
- * @param $node_access_alias
- *   If the node_access table has been given an SQL alias other than the default
- *   "na", that must be passed here.
- * @return
- *   An SQL join clause.
- */
-function _node_access_join_sql($node_alias = 'n', $node_access_alias = 'na') {
-  if (user_access('administer nodes')) {
-    return '';
-  }
-
-  return 'INNER JOIN {node_access} '. $node_access_alias .' ON '. $node_access_alias .'.nid = '. $node_alias .'.nid';
-}
-
-/**
  * Generate an SQL where clause for use in fetching a node listing.
  *
  * @param $op
@@ -2377,7 +2357,7 @@
  * @return
  *   An SQL where clause.
  */
-function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid = NULL) {
+function _node_access_where_sql($node_alias = 'n', $op = 'view', $node_access_alias = 'na', $uid = NULL) {
   if (user_access('administer nodes')) {
     return;
   }
@@ -2394,7 +2374,7 @@
     $grants_sql = 'AND ('. implode(' OR ', $grants) .')';
   }

-  $sql = "$node_access_alias.grant_$op >= 1 $grants_sql";
+  $sql = "EXISTS (SELECT 1 FROM {node_access} $node_access_alias WHERE $node_access_alias.nid = $node_alias.nid AND ($node_access_alias.grant_$op >= 1 $grants_sql))";
   return $sql;
 }

@@ -2458,9 +2438,7 @@
  */
 function node_db_rewrite_sql($query, $primary_table, $primary_field) {
   if ($primary_field == 'nid' && !node_access_view_all_nodes()) {
-    $return['join'] = _node_access_join_sql($primary_table);
-    $return['where'] = _node_access_where_sql();
-    $return['distinct'] = 1;
+    $return['where'] = _node_access_where_sql($primary_table);
     return $return;
   }
 }
