Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
77a69a2e
Commit
77a69a2e
authored
Aug 10, 2001
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch to LOCK multiple tables in one LOCK command.
Neil Padgett
parent
49eb4f47
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
35 deletions
+54
-35
doc/src/sgml/ref/lock.sgml
doc/src/sgml/ref/lock.sgml
+12
-4
src/backend/commands/command.c
src/backend/commands/command.c
+31
-20
src/backend/nodes/copyfuncs.c
src/backend/nodes/copyfuncs.c
+3
-3
src/backend/nodes/equalfuncs.c
src/backend/nodes/equalfuncs.c
+2
-2
src/backend/parser/gram.y
src/backend/parser/gram.y
+3
-3
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+2
-2
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/preproc.y
+1
-1
No files found.
doc/src/sgml/ref/lock.sgml
View file @
77a69a2e
<!--
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.2
6 2001/08/04 22:01:38
momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/lock.sgml,v 1.2
7 2001/08/10 14:30:14
momjian Exp $
Postgres documentation
Postgres documentation
-->
-->
...
@@ -15,7 +15,7 @@ Postgres documentation
...
@@ -15,7 +15,7 @@ Postgres documentation
LOCK
LOCK
</refname>
</refname>
<refpurpose>
<refpurpose>
Explicitly lock a table inside a transaction
Explicitly lock a table
/ tables
inside a transaction
</refpurpose>
</refpurpose>
</refnamediv>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdiv>
...
@@ -23,8 +23,8 @@ Postgres documentation
...
@@ -23,8 +23,8 @@ Postgres documentation
<date>2001-07-09</date>
<date>2001-07-09</date>
</refsynopsisdivinfo>
</refsynopsisdivinfo>
<synopsis>
<synopsis>
LOCK [ TABLE ] <replaceable class="PARAMETER">name</replaceable>
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>
[, ...]
IN <replaceable class="PARAMETER">lockmode</replaceable> MODE
where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
where <replaceable class="PARAMETER">lockmode</replaceable> is one of:
...
@@ -373,6 +373,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
...
@@ -373,6 +373,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
An example for this rule was given previously when discussing the
An example for this rule was given previously when discussing the
use of SHARE ROW EXCLUSIVE mode rather than SHARE mode.
use of SHARE ROW EXCLUSIVE mode rather than SHARE mode.
</para>
</para>
</listitem>
</listitem>
</itemizedlist>
</itemizedlist>
...
@@ -383,6 +384,12 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
...
@@ -383,6 +384,12 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
</para>
</para>
</note>
</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">
<refsect2 id="R2-SQL-LOCK-3">
<refsect2info>
<refsect2info>
<date>1999-06-08</date>
<date>1999-06-08</date>
...
@@ -406,6 +413,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
...
@@ -406,6 +413,7 @@ ERROR <replaceable class="PARAMETER">name</replaceable>: Table does not exist.
<para>
<para>
<command>LOCK</command> works only inside transactions.
<command>LOCK</command> works only inside transactions.
</para>
</para>
</refsect2>
</refsect2>
</refsect1>
</refsect1>
...
...
src/backend/commands/command.c
View file @
77a69a2e
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.13
8 2001/08/04 22:01:38
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.13
9 2001/08/10 14:30:14
momjian Exp $
*
*
* NOTES
* NOTES
* The PerformAddAttribute() code, like most of the relation
* The PerformAddAttribute() code, like most of the relation
...
@@ -1984,8 +1984,7 @@ needs_toast_table(Relation rel)
...
@@ -1984,8 +1984,7 @@ needs_toast_table(Relation rel)
MAXALIGN
(
data_length
);
MAXALIGN
(
data_length
);
return
(
tuple_length
>
TOAST_TUPLE_THRESHOLD
);
return
(
tuple_length
>
TOAST_TUPLE_THRESHOLD
);
}
}
/*
/*
*
*
* LOCK TABLE
* LOCK TABLE
...
@@ -1994,26 +1993,38 @@ needs_toast_table(Relation rel)
...
@@ -1994,26 +1993,38 @@ needs_toast_table(Relation rel)
void
void
LockTableCommand
(
LockStmt
*
lockstmt
)
LockTableCommand
(
LockStmt
*
lockstmt
)
{
{
Relation
rel
;
List
*
p
;
int
aclresult
;
Relation
rel
;
rel
=
heap_openr
(
lockstmt
->
relname
,
NoLock
);
/* Iterate over the list and open, lock, and close the relations
one at a time
if
(
rel
->
rd_rel
->
relkind
!=
RELKIND_RELATION
)
*/
elog
(
ERROR
,
"LOCK TABLE: %s is not a table"
,
lockstmt
->
relname
);
if
(
lockstmt
->
mode
==
AccessShareLock
)
aclresult
=
pg_aclcheck
(
lockstmt
->
relname
,
GetUserId
(),
ACL_SELECT
);
else
aclresult
=
pg_aclcheck
(
lockstmt
->
relname
,
GetUserId
(),
ACL_UPDATE
|
ACL_DELETE
);
if
(
aclresult
!=
ACLCHECK_OK
)
foreach
(
p
,
lockstmt
->
rellist
)
elog
(
ERROR
,
"LOCK TABLE: permission denied"
);
{
char
*
relname
=
strVal
(
lfirst
(
p
));
int
aclresult
;
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
);
LockRelation
(
rel
,
lockstmt
->
mode
);
if
(
aclresult
!=
ACLCHECK_OK
)
elog
(
ERROR
,
"LOCK TABLE: permission denied"
);
heap_close
(
rel
,
NoLock
);
/* close rel, keep lock */
LockRelation
(
rel
,
lockstmt
->
mode
);
heap_close
(
rel
,
NoLock
);
/* close rel, keep lock */
}
}
}
...
...
src/backend/nodes/copyfuncs.c
View file @
77a69a2e
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.15
0 2001/08/04 22:01:38
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.15
1 2001/08/10 14:30:14
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -2425,8 +2425,8 @@ _copyLockStmt(LockStmt *from)
...
@@ -2425,8 +2425,8 @@ _copyLockStmt(LockStmt *from)
{
{
LockStmt
*
newnode
=
makeNode
(
LockStmt
);
LockStmt
*
newnode
=
makeNode
(
LockStmt
);
if
(
from
->
relname
)
Node_Copy
(
from
,
newnode
,
rellist
);
newnode
->
relname
=
pstrdup
(
from
->
relname
);
newnode
->
mode
=
from
->
mode
;
newnode
->
mode
=
from
->
mode
;
return
newnode
;
return
newnode
;
...
...
src/backend/nodes/equalfuncs.c
View file @
77a69a2e
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.9
8 2001/08/04 22:01:38
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.9
9 2001/08/10 14:30:14
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1283,7 +1283,7 @@ _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
...
@@ -1283,7 +1283,7 @@ _equalDropUserStmt(DropUserStmt *a, DropUserStmt *b)
static
bool
static
bool
_equalLockStmt
(
LockStmt
*
a
,
LockStmt
*
b
)
_equalLockStmt
(
LockStmt
*
a
,
LockStmt
*
b
)
{
{
if
(
!
equal
str
(
a
->
relname
,
b
->
relname
))
if
(
!
equal
(
a
->
rellist
,
b
->
rellist
))
return
false
;
return
false
;
if
(
a
->
mode
!=
b
->
mode
)
if
(
a
->
mode
!=
b
->
mode
)
return
false
;
return
false
;
...
...
src/backend/parser/gram.y
View file @
77a69a2e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.24
1 2001/08/06 05:42:48
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.24
2 2001/08/10 14:30:14
momjian Exp $
*
*
* HISTORY
* HISTORY
* AUTHOR DATE MAJOR EVENT
* AUTHOR DATE MAJOR EVENT
...
@@ -3281,11 +3281,11 @@ DeleteStmt: DELETE FROM relation_expr where_clause
...
@@ -3281,11 +3281,11 @@ DeleteStmt: DELETE FROM relation_expr where_clause
}
}
;
;
LockStmt: LOCK_P opt_table relation_name opt_lock
LockStmt: LOCK_P opt_table relation_name
_list
opt_lock
{
{
LockStmt *n = makeNode(LockStmt);
LockStmt *n = makeNode(LockStmt);
n->rel
name
= $3;
n->rel
list
= $3;
n->mode = $4;
n->mode = $4;
$$ = (Node *)n;
$$ = (Node *)n;
}
}
...
...
src/include/nodes/parsenodes.h
View file @
77a69a2e
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: parsenodes.h,v 1.13
8 2001/08/04 22:01:39
momjian Exp $
* $Id: parsenodes.h,v 1.13
9 2001/08/10 14:30:15
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -760,7 +760,7 @@ typedef struct VariableResetStmt
...
@@ -760,7 +760,7 @@ typedef struct VariableResetStmt
typedef
struct
LockStmt
typedef
struct
LockStmt
{
{
NodeTag
type
;
NodeTag
type
;
char
*
relname
;
/* relation
to lock */
List
*
rellist
;
/* relations
to lock */
int
mode
;
/* lock mode */
int
mode
;
/* lock mode */
}
LockStmt
;
}
LockStmt
;
...
...
src/interfaces/ecpg/preproc/preproc.y
View file @
77a69a2e
...
@@ -2421,7 +2421,7 @@ DeleteStmt: DELETE FROM relation_expr where_clause
...
@@ -2421,7 +2421,7 @@ DeleteStmt: DELETE FROM relation_expr where_clause
}
}
;
;
LockStmt: LOCK_P opt_table relation_name opt_lock
LockStmt: LOCK_P opt_table relation_name
_list
opt_lock
{
{
$$ = cat_str(4, make_str("lock"), $2, $3, $4);
$$ = cat_str(4, make_str("lock"), $2, $3, $4);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment