Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1c9633

Browse files
committed
Back out LOCK A,B,C patch at Tom's suggestion.
1 parenteb610fb commitd1c9633

File tree

7 files changed

+32
-117
lines changed

7 files changed

+32
-117
lines changed

‎doc/src/sgml/ref/lock.sgml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.25 2001/08/0419:38:59 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.26 2001/08/0422:01:38 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -15,16 +15,16 @@ Postgres documentation
1515
LOCK
1616
</refname>
1717
<refpurpose>
18-
Explicitly lock a table/ tablesinside a transaction
18+
Explicitly lock a table inside a transaction
1919
</refpurpose>
2020
</refnamediv>
2121
<refsynopsisdiv>
2222
<refsynopsisdivinfo>
2323
<date>2001-07-09</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [,...]
27-
LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable>[,...]IN <replaceable class="PARAMETER">lockmode</replaceable> MODE
26+
LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable>
27+
LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable> IN <replaceable class="PARAMETER">lockmode</replaceable> MODE
2828

2929
where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
3030

@@ -373,7 +373,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
373373
An example for this rule was given previously when discussing the
374374
use of SHARE ROW EXCLUSIVE mode rather than SHARE mode.
375375
</para>
376-
377376
</listitem>
378377
</itemizedlist>
379378

@@ -384,12 +383,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
384383
</para>
385384
</note>
386385

387-
<para>
388-
When locking multiple tables, the command LOCK a, b; is equivalent to LOCK
389-
a; LOCK b;. The tables are locked one-by-one in the order specified in the
390-
<command>LOCK</command> command.
391-
</para>
392-
393386
<refsect2 id="R2-SQL-LOCK-3">
394387
<refsect2info>
395388
<date>1999-06-08</date>
@@ -413,7 +406,6 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
413406
<para>
414407
<command>LOCK</command> works only inside transactions.
415408
</para>
416-
417409
</refsect2>
418410
</refsect1>
419411

‎src/backend/commands/command.c

Lines changed: 17 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.137 2001/08/0419:38:59 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.138 2001/08/0422:01:38 momjian Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -1984,7 +1984,8 @@ needs_toast_table(Relation rel)
19841984
MAXALIGN(data_length);
19851985
return (tuple_length>TOAST_TUPLE_THRESHOLD);
19861986
}
1987-
1987+
1988+
19881989
/*
19891990
*
19901991
* LOCK TABLE
@@ -1993,104 +1994,26 @@ needs_toast_table(Relation rel)
19931994
void
19941995
LockTableCommand(LockStmt*lockstmt)
19951996
{
1996-
intrelCnt;
1997-
1998-
relCnt=length(lockstmt->rellist);
1999-
2000-
/* Handle a single relation lock specially to avoid overhead on likely the
2001-
most common case */
2002-
2003-
if(relCnt==1)
2004-
{
2005-
2006-
/* Locking a single table */
2007-
2008-
Relationrel;
2009-
intaclresult;
2010-
char*relname;
2011-
2012-
relname=strVal(lfirst(lockstmt->rellist));
2013-
2014-
freeList(lockstmt->rellist);
2015-
2016-
rel=heap_openr(relname,NoLock);
2017-
2018-
if (rel->rd_rel->relkind!=RELKIND_RELATION)
2019-
elog(ERROR,"LOCK TABLE: %s is not a table",relname);
2020-
2021-
if (lockstmt->mode==AccessShareLock)
2022-
aclresult=pg_aclcheck(relname,GetUserId(),
2023-
ACL_SELECT);
2024-
else
2025-
aclresult=pg_aclcheck(relname,GetUserId(),
2026-
ACL_UPDATE |ACL_DELETE);
2027-
2028-
if (aclresult!=ACLCHECK_OK)
2029-
elog(ERROR,"LOCK TABLE: permission denied");
2030-
2031-
LockRelation(rel,lockstmt->mode);
2032-
2033-
pfree(relname);
2034-
2035-
heap_close(rel,NoLock);/* close rel, keep lock */
2036-
}
2037-
else
2038-
{
2039-
List*p;
2040-
Relation*RelationArray;
2041-
Relation*pRel;
2042-
2043-
/* Locking multiple tables */
2044-
2045-
/* Create an array of relations */
2046-
2047-
RelationArray=palloc(relCnt*sizeof(Relation));
2048-
pRel=RelationArray;
2049-
2050-
/* Iterate over the list and populate the relation array */
2051-
2052-
foreach(p,lockstmt->rellist)
2053-
{
2054-
char*relname=strVal(lfirst(p));
2055-
intaclresult;
2056-
2057-
*pRel=heap_openr(relname,NoLock);
2058-
2059-
if ((*pRel)->rd_rel->relkind!=RELKIND_RELATION)
2060-
elog(ERROR,"LOCK TABLE: %s is not a table",
2061-
relname);
2062-
2063-
if (lockstmt->mode==AccessShareLock)
2064-
aclresult=pg_aclcheck(relname,GetUserId(),
2065-
ACL_SELECT);
2066-
else
2067-
aclresult=pg_aclcheck(relname,GetUserId(),
2068-
ACL_UPDATE |ACL_DELETE);
2069-
2070-
if (aclresult!=ACLCHECK_OK)
2071-
elog(ERROR,"LOCK TABLE: permission denied");
1997+
Relationrel;
1998+
intaclresult;
20721999

2073-
pRel++;
2074-
pfree(relname);
2075-
}
2000+
rel=heap_openr(lockstmt->relname,NoLock);
20762001

2077-
/* Now, lock all the relations, closing each after it is locked
2078-
(Keeping the locks)
2079-
*/
2002+
if (rel->rd_rel->relkind!=RELKIND_RELATION)
2003+
elog(ERROR,"LOCK TABLE: %s is not a table",lockstmt->relname);
20802004

2081-
for(pRel=RelationArray;
2082-
pRel<RelationArray+relCnt;
2083-
pRel++)
2084-
{
2085-
LockRelation(*pRel,lockstmt->mode);
2005+
if (lockstmt->mode==AccessShareLock)
2006+
aclresult=pg_aclcheck(lockstmt->relname,GetUserId(),ACL_SELECT);
2007+
else
2008+
aclresult=pg_aclcheck(lockstmt->relname,GetUserId(),
2009+
ACL_UPDATE |ACL_DELETE);
20862010

2087-
heap_close(*pRel,NoLock);
2088-
}
2011+
if (aclresult!=ACLCHECK_OK)
2012+
elog(ERROR,"LOCK TABLE: permission denied");
20892013

2090-
/* Free the relation array */
2014+
LockRelation(rel,lockstmt->mode);
20912015

2092-
pfree(RelationArray);
2093-
}
2016+
heap_close(rel,NoLock);/* close rel, keep lock */
20942017
}
20952018

20962019

‎src/backend/nodes/copyfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.149 2001/08/0419:38:59 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.150 2001/08/0422:01:38 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2425,8 +2425,8 @@ _copyLockStmt(LockStmt *from)
24252425
{
24262426
LockStmt*newnode=makeNode(LockStmt);
24272427

2428-
Node_Copy(from,newnode,rellist);
2429-
2428+
if(from->relname)
2429+
newnode->relname=pstrdup(from->relname);
24302430
newnode->mode=from->mode;
24312431

24322432
returnnewnode;

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.97 2001/08/0419:38:59 momjian Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.98 2001/08/0422:01:38 momjian Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -1283,7 +1283,7 @@ _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
12831283
staticbool
12841284
_equalLockStmt(LockStmt*a,LockStmt*b)
12851285
{
1286-
if (!equal(a->rellist,b->rellist))
1286+
if (!equalstr(a->relname,b->relname))
12871287
return false;
12881288
if (a->mode!=b->mode)
12891289
return false;

‎src/backend/parser/gram.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.239 2001/08/0419:38:59 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.240 2001/08/0422:01:39 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -3280,11 +3280,11 @@ DeleteStmt: DELETE FROM relation_expr where_clause
32803280
}
32813281
;
32823282

3283-
LockStmt:LOCK_Popt_tablerelation_name_listopt_lock
3283+
LockStmt:LOCK_Popt_tablerelation_nameopt_lock
32843284
{
32853285
LockStmt *n = makeNode(LockStmt);
32863286

3287-
n->rellist =$3;
3287+
n->relname =$3;
32883288
n->mode =$4;
32893289
$$ = (Node *)n;
32903290
}

‎src/include/nodes/parsenodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parsenodes.h,v 1.137 2001/08/0419:38:59 momjian Exp $
10+
* $Id: parsenodes.h,v 1.138 2001/08/0422:01:39 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -760,7 +760,7 @@ typedef struct VariableResetStmt
760760
typedefstructLockStmt
761761
{
762762
NodeTagtype;
763-
List*rellist;/*relations to lock */
763+
char*relname;/*relation to lock */
764764
intmode;/* lock mode */
765765
}LockStmt;
766766

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ DeleteStmt: DELETE FROM relation_expr where_clause
24212421
}
24222422
;
24232423

2424-
LockStmt:LOCK_Popt_tablerelation_name_listopt_lock
2424+
LockStmt:LOCK_Popt_tablerelation_nameopt_lock
24252425
{
24262426
$$ = cat_str(4, make_str("lock"),$2,$3,$4);
24272427
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp