> > This is missing the necessary adjustments in backend/nodes/ (copy and
> > equal funcs).  Also the NOWAIT keyword must be added to the list of
> > nonreserved keywords near the bottom of gram.y.
> 
> Thanks for the review. I'll work on this.

Here is the revised patch.
--
Tatsuo Ishii
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/lock.sgml,v
retrieving revision 1.40
diff -c -r1.40 lock.sgml
*** doc/src/sgml/ref/lock.sgml  14 Dec 2003 00:05:29 -0000      1.40
--- doc/src/sgml/ref/lock.sgml  10 Mar 2004 01:35:18 -0000
***************
*** 20,26 ****
  
   <refsynopsisdiv>
  <synopsis>
! LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ IN 
<replaceable class="PARAMETER">lockmode</replaceable> MODE ]
  
  where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
  
--- 20,26 ----
  
   <refsynopsisdiv>
  <synopsis>
! LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ IN 
<replaceable class="PARAMETER">lockmode</replaceable> MODE ] [ NOWAIT ]
  
  where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
  
***************
*** 34,41 ****
  
    <para>
     <command>LOCK TABLE</command> obtains a table-level lock, waiting if
!    necessary for any conflicting locks to be released.  Once obtained,
!    the lock is held for the remainder of the current transaction.
     (There is no <command>UNLOCK TABLE</command> command; locks are always
     released at transaction end.)
    </para>
--- 34,43 ----
  
    <para>
     <command>LOCK TABLE</command> obtains a table-level lock, waiting if
!    necessary for any conflicting locks to be released.
!    If <literal>NOWAIT</literal> is given, <command>LOCK TABLE</command>
!    does not wait for acquiring lock, and throws an error instead.
!    Once obtained, the lock is held for the remainder of the current transaction.
     (There is no <command>UNLOCK TABLE</command> command; locks are always
     released at transaction end.)
    </para>
Index: src/backend/access/heap/heapam.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/access/heap/heapam.c,v
retrieving revision 1.162
diff -c -r1.162 heapam.c
*** src/backend/access/heap/heapam.c    16 Jan 2004 20:51:30 -0000      1.162
--- src/backend/access/heap/heapam.c    10 Mar 2004 01:35:21 -0000
***************
*** 464,469 ****
--- 464,496 ----
        return r;
  }
  
+ Relation
+ conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool nowait)
+ {
+       Relation        r;
+ 
+       Assert(lockmode >= NoLock && lockmode < MAX_LOCKMODES);
+ 
+       /* The relcache does all the real work... */
+       r = RelationIdGetRelation(relationId);
+ 
+       if (!RelationIsValid(r))
+               elog(ERROR, "could not open relation with OID %u", relationId);
+ 
+       if (lockmode != NoLock)
+       {
+               if (nowait)
+               {
+                       if (!ConditionalLockRelation(r, lockmode))
+                               elog(ERROR, "could not aquire relation lock");
+               }
+               else
+                       LockRelation(r, lockmode);
+       }
+ 
+       return r;
+ }
+ 
  /* ----------------
   *            relation_openrv - open any relation specified by a RangeVar
   *
Index: src/backend/commands/lockcmds.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/lockcmds.c,v
retrieving revision 1.8
diff -c -r1.8 lockcmds.c
*** src/backend/commands/lockcmds.c     29 Nov 2003 19:51:47 -0000      1.8
--- src/backend/commands/lockcmds.c     10 Mar 2004 01:35:21 -0000
***************
*** 59,65 ****
                        aclcheck_error(aclresult, ACL_KIND_CLASS,
                                                   get_rel_name(reloid));
  
!               rel = relation_open(reloid, lockstmt->mode);
  
                /* Currently, we only allow plain tables to be locked */
                if (rel->rd_rel->relkind != RELKIND_RELATION)
--- 59,65 ----
                        aclcheck_error(aclresult, ACL_KIND_CLASS,
                                                   get_rel_name(reloid));
  
!               rel = conditional_relation_open(reloid, lockstmt->mode, 
lockstmt->nowait);
  
                /* Currently, we only allow plain tables to be locked */
                if (rel->rd_rel->relkind != RELKIND_RELATION)
Index: src/backend/nodes/copyfuncs.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/nodes/copyfuncs.c,v
retrieving revision 1.277
diff -c -r1.277 copyfuncs.c
*** src/backend/nodes/copyfuncs.c       14 Jan 2004 23:01:54 -0000      1.277
--- src/backend/nodes/copyfuncs.c       10 Mar 2004 01:35:25 -0000
***************
*** 2316,2321 ****
--- 2316,2322 ----
  
        COPY_NODE_FIELD(relations);
        COPY_SCALAR_FIELD(mode);
+       COPY_SCALAR_FIELD(nowait);
  
        return newnode;
  }
Index: src/backend/nodes/equalfuncs.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/nodes/equalfuncs.c,v
retrieving revision 1.215
diff -c -r1.215 equalfuncs.c
*** src/backend/nodes/equalfuncs.c      14 Jan 2004 23:01:55 -0000      1.215
--- src/backend/nodes/equalfuncs.c      10 Mar 2004 01:35:28 -0000
***************
*** 1252,1257 ****
--- 1252,1258 ----
  {
        COMPARE_NODE_FIELD(relations);
        COMPARE_SCALAR_FIELD(mode);
+       COMPARE_SCALAR_FIELD(nowait);
  
        return true;
  }
Index: src/backend/parser/gram.y
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/gram.y,v
retrieving revision 2.447
diff -c -r2.447 gram.y
*** src/backend/parser/gram.y   9 Mar 2004 05:05:41 -0000       2.447
--- src/backend/parser/gram.y   10 Mar 2004 01:35:42 -0000
***************
*** 169,174 ****
--- 169,175 ----
  %type <ival>  opt_lock lock_type cast_context
  %type <boolean>       opt_force opt_or_replace transaction_access_mode
                                opt_grant_grant_option opt_revoke_grant_option
+                               opt_nowait
  
  %type <boolean>       like_including_defaults
  
***************
*** 375,381 ****
        MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
  
        NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
!       NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NULL_P
        NULLIF NUMERIC
  
        OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
--- 376,382 ----
        MATCH MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
  
        NAMES NATIONAL NATURAL NCHAR NEW NEXT NO NOCREATEDB
!       NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P
        NULLIF NUMERIC
  
        OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
***************
*** 4347,4358 ****
                                }
                ;
  
! LockStmt:     LOCK_P opt_table qualified_name_list opt_lock
                                {
                                        LockStmt *n = makeNode(LockStmt);
  
                                        n->relations = $3;
                                        n->mode = $4;
                                        $$ = (Node *)n;
                                }
                ;
--- 4348,4360 ----
                                }
                ;
  
! LockStmt:     LOCK_P opt_table qualified_name_list opt_lock opt_nowait
                                {
                                        LockStmt *n = makeNode(LockStmt);
  
                                        n->relations = $3;
                                        n->mode = $4;
+                                       n->nowait = $5;
                                        $$ = (Node *)n;
                                }
                ;
***************
*** 4371,4376 ****
--- 4373,4382 ----
                        | ACCESS EXCLUSIVE                              { $$ = 
AccessExclusiveLock; }
                ;
  
+ opt_nowait:   NOWAIT                  { $$ = TRUE; }
+                       | /*EMPTY*/                                             { $$ = 
FALSE; }
+               ;
+ 
  
  /*****************************************************************************
   *
***************
*** 7683,7688 ****
--- 7689,7695 ----
                        | LOCALTIMESTAMP
                        | NEW
                        | NOT
+                       | NOWAIT
                        | NULL_P
                        | OFF
                        | OFFSET
Index: src/backend/parser/keywords.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/parser/keywords.c,v
retrieving revision 1.146
diff -c -r1.146 keywords.c
*** src/backend/parser/keywords.c       9 Mar 2004 05:05:41 -0000       1.146
--- src/backend/parser/keywords.c       10 Mar 2004 01:35:42 -0000
***************
*** 213,218 ****
--- 213,219 ----
        {"nothing", NOTHING},
        {"notify", NOTIFY},
        {"notnull", NOTNULL},
+       {"nowait", NOWAIT},
        {"null", NULL_P},
        {"nullif", NULLIF},
        {"numeric", NUMERIC},
Index: src/include/access/heapam.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/access/heapam.h,v
retrieving revision 1.86
diff -c -r1.86 heapam.h
*** src/include/access/heapam.h 29 Nov 2003 22:40:55 -0000      1.86
--- src/include/access/heapam.h 10 Mar 2004 01:35:46 -0000
***************
*** 129,134 ****
--- 129,135 ----
  /* heapam.c */
  
  extern Relation relation_open(Oid relationId, LOCKMODE lockmode);
+ extern Relation conditional_relation_open(Oid relationId, LOCKMODE lockmode, bool 
nowait);
  extern Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode);
  extern Relation relation_openr(const char *sysRelationName, LOCKMODE lockmode);
  extern void relation_close(Relation relation, LOCKMODE lockmode);
Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/nodes/parsenodes.h,v
retrieving revision 1.253
diff -c -r1.253 parsenodes.h
*** src/include/nodes/parsenodes.h      14 Jan 2004 23:01:55 -0000      1.253
--- src/include/nodes/parsenodes.h      10 Mar 2004 01:35:49 -0000
***************
*** 1619,1624 ****
--- 1619,1625 ----
        NodeTag         type;
        List       *relations;          /* relations to lock */
        int                     mode;                   /* lock mode */
+       bool            nowait;         /* no wait mode */
  } LockStmt;
  
  /* ----------------------
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to