Skip to content

Commit 6d2f210

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 549f0ab commit 6d2f210

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
@@ -53,6 +53,9 @@ struct ValidateIndexState;
5353
#define SCAN_SUPPORT_COLUMN_ORIENTED_SCAN (1 << 0) /* support column-oriented scanning*/
5454
#define SCAN_SUPPORT_RUNTIME_FILTER (1 << 1) /* support runtime filter scan */
5555

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

0 commit comments

Comments
 (0)