? node_access_optimize.patch
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.896
diff -u -p -r1.896 node.module
--- modules/node/node.module	24 Oct 2007 14:38:38 -0000	1.896
+++ modules/node/node.module	25 Oct 2007 23:55:33 -0000
@@ -1807,9 +1807,7 @@ function node_access($op, $node, $accoun
   if ($op != 'create' && $node->nid && $node->status) {
     $grants = array();
     foreach (node_access_grants($op, $account) as $realm => $gids) {
-      foreach ($gids as $gid) {
-        $grants[] = "(gid = $gid AND realm = '$realm')";
-      }
+      $grants[] = "((realm = '$realm') AND (gid = ".implode(' OR gid = ', $gids)."))";
     }
 
     $grants_sql = '';
