Skip to content

Commit 8a042b1

Browse files
committed
Add a flag for table access method to force exclusive write
This commit adds a flag in table access method to force exclusive write. The feature allows writing of a table, i.e. insert/delete/ update, to be not concurrently safe.
1 parent 0b2eb33 commit 8a042b1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,6 +3186,11 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
31863186
{
31873187
resultRelInfo = &mtstate->resultRelInfo[i];
31883188

3189+
if (resultRelInfo->ri_RelationDesc->rd_tableam &&
3190+
(table_scan_flags(resultRelInfo->ri_RelationDesc) & SCAN_FORCE_BIG_WRITE_LOCK))
3191+
{
3192+
LockRelation(resultRelInfo->ri_RelationDesc, ExclusiveLock);
3193+
}
31893194
/* Let FDWs init themselves for foreign-table result rels */
31903195
if (!resultRelInfo->ri_usesFdwDirectModify &&
31913196
resultRelInfo->ri_FdwRoutine != NULL &&

src/include/access/tableam.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ struct ValidateIndexState;
5252
*/
5353
#define SCAN_SUPPORT_COLUMN_ORIENTED_SCAN (1 << 0) /* support column-oriented scanning*/
5454

55+
/* force to held big lock for write */
56+
#define SCAN_FORCE_BIG_WRITE_LOCK (1 << 1)
57+
5558
/*
5659
* Bitmask values for the flags argument to the scan_begin callback.
5760
*/

0 commit comments

Comments
 (0)