]> granicus.if.org Git - postgresql/commitdiff
transformForUpdate() mustn't assume rowMarks list is initially empty.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Dec 2000 01:12:08 +0000 (01:12 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Dec 2000 01:12:08 +0000 (01:12 +0000)
It could be recursing into a sub-query where there was already a FOR
UPDATE clause.

src/backend/parser/analyze.c

index 2c33dba0ec5dbba8db82721b5d4fa718a5a5bbea..4be93ff5822d859560a4ebc1b56b5bfa6d59bd93 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $Id: analyze.c,v 1.171 2000/12/06 23:55:19 tgl Exp $
+ *     $Id: analyze.c,v 1.172 2000/12/07 01:12:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2503,6 +2503,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
        return qry;
 }
 
+/* exported so planner can check again after rewriting, query pullup, etc */
 void
 CheckSelectForUpdate(Query *qry)
 {
@@ -2519,7 +2520,7 @@ CheckSelectForUpdate(Query *qry)
 static void
 transformForUpdate(Query *qry, List *forUpdate)
 {
-       List       *rowMarks = NIL;
+       List       *rowMarks = qry->rowMarks;
        List       *l;
        List       *rt;
        Index           i;
@@ -2542,7 +2543,8 @@ transformForUpdate(Query *qry, List *forUpdate)
                        }
                        else
                        {
-                               rowMarks = lappendi(rowMarks, i);
+                               if (!intMember(i, rowMarks)) /* avoid duplicates */
+                                       rowMarks = lappendi(rowMarks, i);
                                rte->checkForWrite = true;
                        }
                }