diff --git a/modules/node/node.module b/modules/node/node.module
index c052f4b..04c205a 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -3312,6 +3312,10 @@ function node_access_acquire_grants($node, $delete = TRUE) {
  *   and assumes the caller has already performed a mass delete of some form.
  */
 function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE) {
+  static $saved_grants;
+  if (!isset($saved_grants)) {
+    $saved_grants = array();
+  }
   if ($delete) {
     $query = db_delete('node_access')->condition('nid', $node->nid);
     if ($realm) {
@@ -3323,6 +3327,7 @@ function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE)
   // Only perform work when node_access modules are active.
   if (!empty($grants) && count(module_implements('node_grants'))) {
     $query = db_insert('node_access')->fields(array('nid', 'realm', 'gid', 'grant_view', 'grant_update', 'grant_delete'));
+    $has_fields = FALSE;
     foreach ($grants as $grant) {
       if ($realm && $realm != $grant['realm']) {
         continue;
@@ -3330,10 +3335,18 @@ function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE)
       // Only write grants; denies are implicit.
       if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
         $grant['nid'] = $node->nid;
-        $query->values($grant);
+
+        $grant_string = $node->nid . '-' . $grant['gid'] . '-' . $realm;
+        if (!in_array($grant_string, $saved_grants)) {
+          $query->values($grant);
+          $saved_grants[] = $grant_string;
+          $has_fields = TRUE;
+        }
       }
     }
-    $query->execute();
+    if ($has_fields) {
+      $query->execute();
+    }
   }
 }
 
