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

Commitc9b75c5

Browse files
committed
Simplify restriction handling of two-phase commit for temporary objects
There were two flags used to track the access to temporary tables andto the temporary namespace of a session which are used to restrictPREPARE TRANSACTION, however the first control flag is a conceptincluded in the second. This removes the flag for temporary tabletracking, keeping around only the one at namespace level.Author: Michael PaquierReviewed-by: Álvaro HerreraDiscussion:https://postgr.es/m/20190118053126.GH1883@paquier.xyz
1 parentdf4c904 commitc9b75c5

File tree

7 files changed

+25
-38
lines changed

7 files changed

+25
-38
lines changed

‎src/backend/access/common/relation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ relation_open(Oid relationId, LOCKMODE lockmode)
7171

7272
/* Make note that we've accessed a temporary relation */
7373
if (RelationUsesLocalBuffers(r))
74-
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPREL;
74+
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPNAMESPACE;
7575

7676
pgstat_initstats(r);
7777

@@ -121,7 +121,7 @@ try_relation_open(Oid relationId, LOCKMODE lockmode)
121121

122122
/* Make note that we've accessed a temporary relation */
123123
if (RelationUsesLocalBuffers(r))
124-
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPREL;
124+
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPNAMESPACE;
125125

126126
pgstat_initstats(r);
127127

‎src/backend/access/transam/xact.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,29 +2266,22 @@ PrepareTransaction(void)
22662266
* clean up the source backend's local buffers and ON COMMIT state if the
22672267
* prepared xact includes a DROP of a temp table.
22682268
*
2269+
* Other objects types, like functions, operators or extensions, share the
2270+
* same restriction as they should not be created, locked or dropped as
2271+
* this can mess up with this session or even a follow-up session trying
2272+
* to use the same temporary namespace.
2273+
*
22692274
* We must check this after executing any ON COMMIT actions, because they
22702275
* might still access a temp relation.
22712276
*
22722277
* XXX In principle this could be relaxed to allow some useful special
22732278
* cases, such as a temp table created and dropped all within the
22742279
* transaction. That seems to require much more bookkeeping though.
22752280
*/
2276-
if ((MyXactFlags&XACT_FLAGS_ACCESSEDTEMPREL))
2277-
ereport(ERROR,
2278-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2279-
errmsg("cannot PREPARE a transaction that has operated on temporary tables")));
2280-
2281-
/*
2282-
* Similarly, PREPARE TRANSACTION is not allowed if the temporary
2283-
* namespace has been involved in this transaction as we cannot allow it
2284-
* to create, lock, or even drop objects within the temporary namespace
2285-
* as this can mess up with this session or even a follow-up session
2286-
* trying to use the same temporary namespace.
2287-
*/
22882281
if ((MyXactFlags&XACT_FLAGS_ACCESSEDTEMPNAMESPACE))
22892282
ereport(ERROR,
22902283
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2291-
errmsg("cannot PREPARE a transaction that has operated on temporarynamespace")));
2284+
errmsg("cannot PREPARE a transaction that has operated on temporaryobjects")));
22922285

22932286
/*
22942287
* Likewise, don't allow PREPARE after pg_export_snapshot. This could be

‎src/backend/commands/lockcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ RangeVarCallbackForLockTable(const RangeVar *rv, Oid relid, Oid oldrelid,
108108
*/
109109
relpersistence=get_rel_persistence(relid);
110110
if (relpersistence==RELPERSISTENCE_TEMP)
111-
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPREL;
111+
MyXactFlags |=XACT_FLAGS_ACCESSEDTEMPNAMESPACE;
112112

113113
/* Check permissions. */
114114
aclresult=LockTableAclCheck(relid,lockmode,GetUserId());

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13642,7 +13642,7 @@ PreCommit_on_commit_actions(void)
1364213642
* relations, we can skip truncating ON COMMIT DELETE ROWS
1364313643
* tables, as they must still be empty.
1364413644
*/
13645-
if ((MyXactFlags&XACT_FLAGS_ACCESSEDTEMPREL))
13645+
if ((MyXactFlags&XACT_FLAGS_ACCESSEDTEMPNAMESPACE))
1364613646
oids_to_truncate=lappend_oid(oids_to_truncate,oc->relid);
1364713647
break;
1364813648
caseONCOMMIT_DROP:

‎src/include/access/xact.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,17 @@ extern intsynchronous_commit;
8787
externintMyXactFlags;
8888

8989
/*
90-
*XACT_FLAGS_ACCESSEDTEMPREL - set when a temporaryrelation is accessed. We
91-
* don't allow PREPARE TRANSACTION in that case.
90+
*XACT_FLAGS_ACCESSEDTEMPNAMESPACE - set when a temporaryobject is accessed.
91+
*Wedon't allow PREPARE TRANSACTION in that case.
9292
*/
93-
#defineXACT_FLAGS_ACCESSEDTEMPREL(1U << 0)
93+
#defineXACT_FLAGS_ACCESSEDTEMPNAMESPACE(1U << 0)
9494

9595
/*
9696
* XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK - records whether the top level xact
9797
* logged any Access Exclusive Locks.
9898
*/
9999
#defineXACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK(1U << 1)
100100

101-
/*
102-
* XACT_FLAGS_ACCESSEDTEMPNAMESPACE - set when a temporary namespace is
103-
* accessed. We don't allow PREPARE TRANSACTION in that case.
104-
*/
105-
#defineXACT_FLAGS_ACCESSEDTEMPNAMESPACE(1U << 2)
106-
107101
/*
108102
*start- and end-of-transaction callbacks for dynamically loaded modules
109103
*/

‎src/test/modules/test_extensions/expected/test_extensions.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ SELECT create_extension_with_temp_schema();
148148
(1 row)
149149

150150
PREPARE TRANSACTION 'twophase_extension';
151-
ERROR: cannot PREPARE a transaction that has operated on temporarynamespace
151+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
152152
-- Clean up
153153
DROP TABLE test_ext4_tab;
154154
DROP FUNCTION create_extension_with_temp_schema();

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,32 +310,32 @@ begin;
310310
create function pg_temp.twophase_func() returns void as
311311
$$ select '2pc_func'::text $$ language sql;
312312
prepare transaction 'twophase_func';
313-
ERROR: cannot PREPARE a transaction that has operated on temporarynamespace
313+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
314314
-- Function drop
315315
create function pg_temp.twophase_func() returns void as
316316
$$ select '2pc_func'::text $$ language sql;
317317
begin;
318318
drop function pg_temp.twophase_func();
319319
prepare transaction 'twophase_func';
320-
ERROR: cannot PREPARE a transaction that has operated on temporarynamespace
320+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
321321
-- Operator creation
322322
begin;
323323
create operator pg_temp.@@ (leftarg = int4, rightarg = int4, procedure = int4mi);
324324
prepare transaction 'twophase_operator';
325-
ERROR: cannot PREPARE a transaction that has operated on temporarynamespace
325+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
326326
-- These generate errors about temporary tables.
327327
begin;
328328
create type pg_temp.twophase_type as (a int);
329329
prepare transaction 'twophase_type';
330-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
330+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
331331
begin;
332332
create view pg_temp.twophase_view as select 1;
333333
prepare transaction 'twophase_view';
334-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
334+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
335335
begin;
336336
create sequence pg_temp.twophase_seq;
337337
prepare transaction 'twophase_sequence';
338-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
338+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
339339
-- Temporary tables cannot be used with two-phase commit.
340340
create temp table twophase_tab (a int);
341341
begin;
@@ -345,19 +345,19 @@ select a from twophase_tab;
345345
(0 rows)
346346

347347
prepare transaction 'twophase_tab';
348-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
348+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
349349
begin;
350350
insert into twophase_tab values (1);
351351
prepare transaction 'twophase_tab';
352-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
352+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
353353
begin;
354354
lock twophase_tab in access exclusive mode;
355355
prepare transaction 'twophase_tab';
356-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
356+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
357357
begin;
358358
drop table twophase_tab;
359359
prepare transaction 'twophase_tab';
360-
ERROR: cannot PREPARE a transaction that has operated on temporarytables
360+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects
361361
-- Corner case: current_schema may create a temporary schema if namespace
362362
-- creation is pending, so check after that. First reset the connection
363363
-- to remove the temporary namespace, and make sure that non-parallel plans
@@ -374,4 +374,4 @@ SELECT current_schema() ~ 'pg_temp' AS is_temp_schema;
374374
(1 row)
375375

376376
PREPARE TRANSACTION 'twophase_search';
377-
ERROR: cannot PREPARE a transaction that has operated on temporarynamespace
377+
ERROR: cannot PREPARE a transaction that has operated on temporaryobjects

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp