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

Commit8f9622b

Browse files
committed
Make DDL operations play nicely with Serializable Snapshot Isolation.
Truncating or dropping a table is treated like deletion of all tuples, andcheck for conflicts accordingly. If a table is clustered or rewritten byALTER TABLE, all predicate locks on the heap are promoted to relation-levellocks, because the tuple or page ids of any existing tuples will change andwon't be valid after rewriting the table. Arguably ALTER TABLE should betreated like a mass-UPDATE of every row, but if you e.g change the datatypeof a column, you could also argue that it's just a change to the physicallayout, not a logical change. Reindexing promotes all locks on the index torelation-level lock on the heap.Kevin Grittner, with a lot of cosmetic changes by me.
1 parent16925c1 commit8f9622b

File tree

7 files changed

+499
-80
lines changed

7 files changed

+499
-80
lines changed

‎src/backend/catalog/heap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include"parser/parse_relation.h"
6464
#include"storage/bufmgr.h"
6565
#include"storage/freespace.h"
66+
#include"storage/predicate.h"
6667
#include"storage/smgr.h"
6768
#include"utils/acl.h"
6869
#include"utils/builtins.h"
@@ -1657,6 +1658,14 @@ heap_drop_with_catalog(Oid relid)
16571658
*/
16581659
CheckTableNotInUse(rel,"DROP TABLE");
16591660

1661+
/*
1662+
* This effectively deletes all rows in the table, and may be done in a
1663+
* serializable transaction. In that case we must record a rw-conflict in
1664+
* to this transaction from each transaction holding a predicate lock on
1665+
* the table.
1666+
*/
1667+
CheckTableForSerializableConflictIn(rel);
1668+
16601669
/*
16611670
* Delete pg_foreign_table tuple first.
16621671
*/

‎src/backend/catalog/index.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include"parser/parser.h"
5555
#include"storage/bufmgr.h"
5656
#include"storage/lmgr.h"
57+
#include"storage/predicate.h"
5758
#include"storage/procarray.h"
5859
#include"storage/smgr.h"
5960
#include"utils/builtins.h"
@@ -1311,6 +1312,12 @@ index_drop(Oid indexId)
13111312
*/
13121313
CheckTableNotInUse(userIndexRelation,"DROP INDEX");
13131314

1315+
/*
1316+
* All predicate locks on the index are about to be made invalid. Promote
1317+
* them to relation locks on the heap.
1318+
*/
1319+
TransferPredicateLocksToHeapRelation(userIndexRelation);
1320+
13141321
/*
13151322
* Schedule physical removal of the files
13161323
*/
@@ -2799,6 +2806,12 @@ reindex_index(Oid indexId, bool skip_constraint_checks)
27992806
*/
28002807
CheckTableNotInUse(iRel,"REINDEX INDEX");
28012808

2809+
/*
2810+
* All predicate locks on the index are about to be made invalid. Promote
2811+
* them to relation locks on the heap.
2812+
*/
2813+
TransferPredicateLocksToHeapRelation(iRel);
2814+
28022815
PG_TRY();
28032816
{
28042817
/* Suppress use of the target index while rebuilding it */

‎src/backend/commands/cluster.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include"optimizer/planner.h"
4040
#include"storage/bufmgr.h"
4141
#include"storage/lmgr.h"
42+
#include"storage/predicate.h"
4243
#include"storage/procarray.h"
4344
#include"storage/smgr.h"
4445
#include"utils/acl.h"
@@ -385,6 +386,14 @@ cluster_rel(Oid tableOid, Oid indexOid, bool recheck, bool verbose,
385386
if (OidIsValid(indexOid))
386387
check_index_is_clusterable(OldHeap,indexOid,recheck,AccessExclusiveLock);
387388

389+
/*
390+
* All predicate locks on the tuples or pages are about to be made
391+
* invalid, because we move tuples around.Promote them to relation
392+
* locks. Predicate locks on indexes will be promoted when they are
393+
* reindexed.
394+
*/
395+
TransferPredicateLocksToHeapRelation(OldHeap);
396+
388397
/* rebuild_relation does all the dirty work */
389398
rebuild_relation(OldHeap,indexOid,freeze_min_age,freeze_table_age,
390399
verbose);

‎src/backend/commands/tablecmds.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include"storage/bufmgr.h"
7171
#include"storage/lmgr.h"
7272
#include"storage/lock.h"
73+
#include"storage/predicate.h"
7374
#include"storage/smgr.h"
7475
#include"utils/acl.h"
7576
#include"utils/builtins.h"
@@ -1039,6 +1040,14 @@ ExecuteTruncate(TruncateStmt *stmt)
10391040
Oidheap_relid;
10401041
Oidtoast_relid;
10411042

1043+
/*
1044+
* This effectively deletes all rows in the table, and may be done
1045+
* in a serializable transaction. In that case we must record a
1046+
* rw-conflict in to this transaction from each transaction
1047+
* holding a predicate lock on the table.
1048+
*/
1049+
CheckTableForSerializableConflictIn(rel);
1050+
10421051
/*
10431052
* Need the full transaction-safe pushups.
10441053
*
@@ -3529,6 +3538,16 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
35293538
(errmsg("verifying table \"%s\"",
35303539
RelationGetRelationName(oldrel))));
35313540

3541+
if (newrel)
3542+
{
3543+
/*
3544+
* All predicate locks on the tuples or pages are about to be made
3545+
* invalid, because we move tuples around.Promote them to
3546+
* relation locks.
3547+
*/
3548+
TransferPredicateLocksToHeapRelation(oldrel);
3549+
}
3550+
35323551
econtext=GetPerTupleExprContext(estate);
35333552

35343553
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp