]> granicus.if.org Git - postgresql/commitdiff
Back out LOCK A,B,C patch at Tom's suggestion.
authorBruce Momjian <bruce@momjian.us>
Sat, 4 Aug 2001 22:01:39 +0000 (22:01 +0000)
committerBruce Momjian <bruce@momjian.us>
Sat, 4 Aug 2001 22:01:39 +0000 (22:01 +0000)
doc/src/sgml/ref/lock.sgml
src/backend/commands/command.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/gram.y
src/include/nodes/parsenodes.h
src/interfaces/ecpg/preproc/preproc.y

index 58e53371c94488d14598d9a1fa210764ff35cf66..20530d75d712da6748c1af05fbf6e0bac51b3fb4 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.25 2001/08/04 19:38:59 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.26 2001/08/04 22:01:38 momjian Exp $
 Postgres documentation
 -->
 
@@ -15,7 +15,7 @@ Postgres documentation
    LOCK
   </refname>
   <refpurpose>
-   Explicitly lock a table / tables inside a transaction
+   Explicitly lock a table inside a transaction
   </refpurpose>
  </refnamediv>
  <refsynopsisdiv>
@@ -23,8 +23,8 @@ Postgres documentation
    <date>2001-07-09</date>
   </refsynopsisdivinfo>
   <synopsis>
-LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [,...]
-LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [,...] IN <replaceable class="PARAMETER">lockmode</replaceable> MODE
+LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable>
+LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> IN <replaceable class="PARAMETER">lockmode</replaceable> MODE
 
 where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
 
@@ -373,7 +373,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
      An example for this rule was given previously when discussing the 
      use of SHARE ROW EXCLUSIVE mode rather than SHARE mode.
     </para>
-
    </listitem>
   </itemizedlist>
 
@@ -384,12 +383,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
    </para>
   </note>
 
-  <para>
-   When locking multiple tables, the command LOCK a, b; is equivalent to LOCK
-   a; LOCK b;. The tables are locked one-by-one in the order specified in the
-   <command>LOCK</command> command.
-  </para>
-
   <refsect2 id="R2-SQL-LOCK-3">
    <refsect2info>
     <date>1999-06-08</date>
@@ -413,7 +406,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
    <para>
     <command>LOCK</command> works only inside transactions.
    </para>
-
   </refsect2>
  </refsect1>
   
index 827608363cb314c5fd38e6565fdd97876f32da25..37814cdcd3841b2d577df6b65d3c7afc71b69933 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.137 2001/08/04 19:38:59 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.138 2001/08/04 22:01:38 momjian Exp $
  *
  * NOTES
  *       The PerformAddAttribute() code, like most of the relation
@@ -1984,7 +1984,8 @@ needs_toast_table(Relation rel)
                MAXALIGN(data_length);
        return (tuple_length > TOAST_TUPLE_THRESHOLD);
 }
-       
+
+
 /*
  *
  * LOCK TABLE
@@ -1993,104 +1994,26 @@ needs_toast_table(Relation rel)
 void
 LockTableCommand(LockStmt *lockstmt)
 {
-       int         relCnt;
-
-       relCnt = length(lockstmt -> rellist);
-
-       /* Handle a single relation lock specially to avoid overhead on likely the
-          most common case */
-
-       if(relCnt == 1)
-       {
-
-               /* Locking a single table */
-
-               Relation        rel;
-               int                     aclresult;
-               char *relname;
-
-               relname = strVal(lfirst(lockstmt->rellist));
-
-               freeList(lockstmt->rellist);
-
-               rel = heap_openr(relname, NoLock);
-
-               if (rel->rd_rel->relkind != RELKIND_RELATION)
-                       elog(ERROR, "LOCK TABLE: %s is not a table", relname);
-
-               if (lockstmt->mode == AccessShareLock)
-                       aclresult = pg_aclcheck(relname, GetUserId(),
-                                                                       ACL_SELECT);
-               else
-                       aclresult = pg_aclcheck(relname, GetUserId(),
-                                                                       ACL_UPDATE | ACL_DELETE);
-
-               if (aclresult != ACLCHECK_OK)
-                       elog(ERROR, "LOCK TABLE: permission denied");
-
-               LockRelation(rel, lockstmt->mode);
-
-               pfree(relname);
-
-               heap_close(rel, NoLock);        /* close rel, keep lock */
-       } 
-       else 
-       {
-               List *p;
-               Relation *RelationArray;
-               Relation *pRel;
-
-               /* Locking multiple tables */
-
-               /* Create an array of relations */
-
-               RelationArray = palloc(relCnt * sizeof(Relation));
-               pRel = RelationArray;
-
-               /* Iterate over the list and populate the relation array */
-
-               foreach(p, lockstmt->rellist)
-               {
-                       char* relname = strVal(lfirst(p));
-                       int                     aclresult;
-
-                       *pRel = heap_openr(relname, NoLock);
-
-                       if ((*pRel)->rd_rel->relkind != RELKIND_RELATION)
-                               elog(ERROR, "LOCK TABLE: %s is not a table", 
-                                        relname);
-
-                       if (lockstmt->mode == AccessShareLock)
-                               aclresult = pg_aclcheck(relname, GetUserId(),
-                                                                               ACL_SELECT);
-                       else
-                               aclresult = pg_aclcheck(relname, GetUserId(),
-                                                                               ACL_UPDATE | ACL_DELETE);
-
-                       if (aclresult != ACLCHECK_OK)
-                               elog(ERROR, "LOCK TABLE: permission denied");
+       Relation        rel;
+       int                     aclresult;
 
-                       pRel++;
-                       pfree(relname);
-               }
+       rel = heap_openr(lockstmt->relname, NoLock);
 
-               /* Now, lock all the relations, closing each after it is locked
-                  (Keeping the locks)
-                */
+       if (rel->rd_rel->relkind != RELKIND_RELATION)
+               elog(ERROR, "LOCK TABLE: %s is not a table", lockstmt->relname);
 
-               for(pRel = RelationArray;
-                       pRel < RelationArray + relCnt;
-                       pRel++)
-                       {
-                               LockRelation(*pRel, lockstmt->mode);
+       if (lockstmt->mode == AccessShareLock)
+               aclresult = pg_aclcheck(lockstmt->relname, GetUserId(), ACL_SELECT);
+       else
+               aclresult = pg_aclcheck(lockstmt->relname, GetUserId(),
+                                                               ACL_UPDATE | ACL_DELETE);
 
-                               heap_close(*pRel, NoLock);
-                       }
+       if (aclresult != ACLCHECK_OK)
+               elog(ERROR, "LOCK TABLE: permission denied");
 
-               /* Free the relation array */
+       LockRelation(rel, lockstmt->mode);
 
-               pfree(RelationArray);
-       }
+       heap_close(rel, NoLock);        /* close rel, keep lock */
 }
 
 
index 65bd5f27e9e1c487a21c4c32ace2820c6b02eb18..0d9aef03edff98efa5be45078eb98041ad80859b 100644 (file)
@@ -15,7 +15,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.149 2001/08/04 19:38:59 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.150 2001/08/04 22:01:38 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2425,8 +2425,8 @@ _copyLockStmt(LockStmt *from)
 {
        LockStmt   *newnode = makeNode(LockStmt);
 
-       Node_Copy(from, newnode, rellist);
-       
+       if (from->relname)
+               newnode->relname = pstrdup(from->relname);
        newnode->mode = from->mode;
 
        return newnode;
index 3a9629cde381ee617c4a838ef456d7702e4622c6..74a88555c5d3f5f5ab635345a81d7b0d32640328 100644 (file)
@@ -20,7 +20,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.97 2001/08/04 19:38:59 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.98 2001/08/04 22:01:38 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1283,7 +1283,7 @@ _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
 static bool
 _equalLockStmt(LockStmt *a, LockStmt *b)
 {
-       if (!equal(a->rellist, b->rellist))
+       if (!equalstr(a->relname, b->relname))
                return false;
        if (a->mode != b->mode)
                return false;
index 130d259aaadf99a6444a8a9ee3ef2e4ffbad9277..cbefde132ff748ba2afd1f16f7fe115ce25e2b14 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.239 2001/08/04 19:38:59 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.240 2001/08/04 22:01:39 momjian Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -3280,11 +3280,11 @@ DeleteStmt:  DELETE FROM relation_expr where_clause
                                }
                ;
 
-LockStmt:      LOCK_P opt_table relation_name_list opt_lock
+LockStmt:      LOCK_P opt_table relation_name opt_lock
                                {
                                        LockStmt *n = makeNode(LockStmt);
 
-                                       n->rellist = $3;
+                                       n->relname = $3;
                                        n->mode = $4;
                                        $$ = (Node *)n;
                                }
index ed379ab02e45a4f7a8b702a71617db095e934152..ad7bcc2e0f3b9872465edfa5a00576ae4ee30d0d 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: parsenodes.h,v 1.137 2001/08/04 19:38:59 momjian Exp $
+ * $Id: parsenodes.h,v 1.138 2001/08/04 22:01:39 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -760,7 +760,7 @@ typedef struct VariableResetStmt
 typedef struct LockStmt
 {
        NodeTag         type;
-       List       *rellist;            /* relations to lock */
+       char       *relname;            /* relation to lock */
        int                     mode;                   /* lock mode */
 } LockStmt;
 
index 09180f85c9c28b38ae68378f4f0e392a08295277..88330ad3c1de5a9d5af76a53b01ed43e8ca6f059 100644 (file)
@@ -2421,7 +2421,7 @@ DeleteStmt:  DELETE FROM relation_expr where_clause
                                }
                ;
 
-LockStmt:  LOCK_P opt_table relation_name_list opt_lock
+LockStmt:  LOCK_P opt_table relation_name opt_lock
                                {
                                        $$ = cat_str(4, make_str("lock"), $2, $3, $4);
                                }