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

Commitf078110

Browse files
committed
Revert "Accept relations of any kind in LOCK TABLE".
Revert59ab4ac, as well as the followup fix33862cb, in allbranches. We need to think a bit harder about what the behaviorof LOCK TABLE on views should be, and there's no time for thatbefore next week's releases. We'll take another crack at thislater.Discussion:https://postgr.es/m/16703-e348f58aab3cf6cc@postgresql.org
1 parentf4fa4a8 commitf078110

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PostgreSQL documentation
1616

1717
<refnamediv>
1818
<refname>LOCK</refname>
19-
<refpurpose>lock anamed relation (table, etc)</refpurpose>
19+
<refpurpose>lock a table</refpurpose>
2020
</refnamediv>
2121

2222
<refsynopsisdiv>
@@ -34,9 +34,7 @@ LOCK [ TABLE ] [ ONLY ] <replaceable class="parameter">name</replaceable> [ * ]
3434
<title>Description</title>
3535

3636
<para>
37-
<command>LOCK TABLE</command> obtains a table-level lock on a
38-
relation (table, partitioned table, foreign table, view,
39-
materialized view, index, composite type, sequence), waiting
37+
<command>LOCK TABLE</command> obtains a table-level lock, waiting
4038
if necessary for any conflicting locks to be released. If
4139
<literal>NOWAIT</literal> is specified, <command>LOCK
4240
TABLE</command> does not wait to acquire the desired lock: if it
@@ -117,18 +115,17 @@ LOCK [ TABLE ] [ ONLY ] <replaceable class="parameter">name</replaceable> [ * ]
117115
<term><replaceable class="parameter">name</replaceable></term>
118116
<listitem>
119117
<para>
120-
The name (optionally schema-qualified) of an existingrelation to
121-
lock. If <literal>ONLY</literal> is specified beforea table name, only that
118+
The name (optionally schema-qualified) of an existingtable to
119+
lock. If <literal>ONLY</literal> is specified beforethe table name, only that
122120
table is locked. If <literal>ONLY</literal> is not specified, the table and all
123121
its descendant tables (if any) are locked. Optionally, <literal>*</literal>
124122
can be specified after the table name to explicitly indicate that
125-
descendant tables are included. When locking a view, all relations appearing
126-
in the view definition are locked, regardless of <literal>ONLY</literal>.
123+
descendant tables are included.
127124
</para>
128125

129126
<para>
130127
The command <literal>LOCK TABLE a, b;</literal> is equivalent to
131-
<literal>LOCK TABLE a; LOCK TABLE b;</literal>. Therelations are locked
128+
<literal>LOCK TABLE a; LOCK TABLE b;</literal>. Thetables are locked
132129
one-by-one in the order specified in the <command>LOCK
133130
TABLE</command> command.
134131
</para>

‎src/backend/commands/lockcmds.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ RangeVarCallbackForLockTable(const RangeVar *rv, Oid relid, Oid oldrelid,
9595
return;/* woops, concurrently dropped; no permissions
9696
* check */
9797

98+
/* Currently, we only allow plain tables or views to be locked */
99+
if (relkind!=RELKIND_RELATION&&relkind!=RELKIND_PARTITIONED_TABLE&&
100+
relkind!=RELKIND_VIEW)
101+
ereport(ERROR,
102+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
103+
errmsg("\"%s\" is not a table or view",
104+
rv->relname)));
105+
98106
/*
99107
* Make note if a temporary relation has been accessed in this
100108
* transaction.
@@ -201,13 +209,11 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context)
201209
foreach(rtable,query->rtable)
202210
{
203211
RangeTblEntry*rte=lfirst(rtable);
204-
Oidrelid;
205212
AclResultaclresult;
206213

207-
/* ignore all non-relation RTEs */
208-
if (rte->rtekind!=RTE_RELATION)
209-
continue;
210-
relid=rte->relid;
214+
Oidrelid=rte->relid;
215+
charrelkind=rte->relkind;
216+
char*relname=get_rel_name(relid);
211217

212218
/*
213219
* The OLD and NEW placeholder entries in the view's rtable are
@@ -218,6 +224,11 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context)
218224
strcmp(rte->eref->aliasname,"new")==0))
219225
continue;
220226

227+
/* Currently, we only allow plain tables or views to be locked. */
228+
if (relkind!=RELKIND_RELATION&&relkind!=RELKIND_PARTITIONED_TABLE&&
229+
relkind!=RELKIND_VIEW)
230+
continue;
231+
221232
/*
222233
* We might be dealing with a self-referential view. If so, we
223234
* can just stop recursing, since we already locked it.
@@ -228,8 +239,7 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context)
228239
/* Check permissions with the view owner's privilege. */
229240
aclresult=LockTableAclCheck(relid,context->lockmode,context->viewowner);
230241
if (aclresult!=ACLCHECK_OK)
231-
aclcheck_error(aclresult,get_relkind_objtype(rte->relkind),
232-
get_rel_name(relid));
242+
aclcheck_error(aclresult,get_relkind_objtype(relkind),relname);
233243

234244
/* We have enough rights to lock the relation; do so. */
235245
if (!context->nowait)
@@ -238,9 +248,9 @@ LockViewRecurse_walker(Node *node, LockViewRecurse_context *context)
238248
ereport(ERROR,
239249
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
240250
errmsg("could not obtain lock on relation \"%s\"",
241-
get_rel_name(relid))));
251+
relname)));
242252

243-
if (rte->relkind==RELKIND_VIEW)
253+
if (relkind==RELKIND_VIEW)
244254
LockViewRecurse(relid,context->lockmode,context->nowait,
245255
context->ancestor_views);
246256
elseif (rte->inh)

‎src/test/regress/expected/lock.out

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ CREATE VIEW lock_view3 AS SELECT * from lock_view2;
1212
CREATE VIEW lock_view4 AS SELECT (select a from lock_tbl1a limit 1) from lock_tbl1;
1313
CREATE VIEW lock_view5 AS SELECT * from lock_tbl1 where a in (select * from lock_tbl1a);
1414
CREATE VIEW lock_view6 AS SELECT * from (select * from lock_tbl1) sub;
15-
CREATE MATERIALIZED VIEW lock_mv1 AS SELECT * FROM lock_view6;
16-
CREATE INDEX lock_mvi1 ON lock_mv1 (a);
17-
CREATE SEQUENCE lock_seq;
1815
CREATE ROLE regress_rol_lock1;
1916
ALTER ROLE regress_rol_lock1 SET search_path = lock_schema1;
2017
GRANT USAGE ON SCHEMA lock_schema1 TO regress_rol_lock1;
@@ -151,16 +148,9 @@ BEGIN;
151148
LOCK TABLE ONLY lock_tbl1;
152149
ROLLBACK;
153150
RESET ROLE;
154-
-- Lock other relations
155-
BEGIN TRANSACTION;
156-
LOCK TABLE lock_mv1;
157-
LOCK TABLE lock_mvi1;
158-
LOCK TABLE lock_seq;
159-
ROLLBACK;
160151
--
161152
-- Clean up
162153
--
163-
DROP MATERIALIZED VIEW lock_mv1;
164154
DROP VIEW lock_view7;
165155
DROP VIEW lock_view6;
166156
DROP VIEW lock_view5;
@@ -172,7 +162,6 @@ DROP TABLE lock_tbl3;
172162
DROP TABLE lock_tbl2;
173163
DROP TABLE lock_tbl1;
174164
DROP TABLE lock_tbl1a;
175-
DROP SEQUENCE lock_seq;
176165
DROP SCHEMA lock_schema1 CASCADE;
177166
DROP ROLE regress_rol_lock1;
178167
-- atomic ops tests

‎src/test/regress/sql/lock.sql

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ CREATE VIEW lock_view3 AS SELECT * from lock_view2;
1313
CREATEVIEWlock_view4ASSELECT (select afrom lock_tbl1alimit1)from lock_tbl1;
1414
CREATEVIEWlock_view5ASSELECT*from lock_tbl1where ain (select*from lock_tbl1a);
1515
CREATEVIEWlock_view6ASSELECT*from (select*from lock_tbl1) sub;
16-
CREATE MATERIALIZED VIEW lock_mv1ASSELECT*FROM lock_view6;
17-
CREATEINDEXlock_mvi1ON lock_mv1 (a);
18-
CREATESEQUENCElock_seq;
1916
CREATE ROLE regress_rol_lock1;
2017
ALTER ROLE regress_rol_lock1SET search_path= lock_schema1;
2118
GRANT USAGEON SCHEMA lock_schema1 TO regress_rol_lock1;
@@ -116,18 +113,9 @@ LOCK TABLE ONLY lock_tbl1;
116113
ROLLBACK;
117114
RESET ROLE;
118115

119-
-- Lock other relations
120-
BEGIN TRANSACTION;
121-
LOCK TABLE lock_mv1;
122-
LOCK TABLE lock_mvi1;
123-
LOCK TABLE lock_seq;
124-
ROLLBACK;
125-
126-
127116
--
128117
-- Clean up
129118
--
130-
DROP MATERIALIZED VIEW lock_mv1;
131119
DROPVIEW lock_view7;
132120
DROPVIEW lock_view6;
133121
DROPVIEW lock_view5;
@@ -138,7 +126,6 @@ DROP TABLE lock_tbl3;
138126
DROPTABLE lock_tbl2;
139127
DROPTABLE lock_tbl1;
140128
DROPTABLE lock_tbl1a;
141-
DROPSEQUENCE lock_seq;
142129
DROPSCHEMA lock_schema1 CASCADE;
143130
DROP ROLE regress_rol_lock1;
144131

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp