This is an automated email from the ASF dual-hosted git repository.

chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/cbdb-postgres-merge by this 
push:
     new 2465a15f86e Add tuple lock in table may be inplace update
2465a15f86e is described below

commit 2465a15f86e5b25a7a877a8468bb4ecf55f7d822
Author: Jinbao Chen <[email protected]>
AuthorDate: Wed Oct 15 22:05:10 2025 +0800

    Add tuple lock in table may be inplace update
---
 src/backend/executor/nodeModifyTable.c | 14 ++++++++-
 src/bin/initdb/initdb.c                | 52 ++++++++++++++++++----------------
 2 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/src/backend/executor/nodeModifyTable.c 
b/src/backend/executor/nodeModifyTable.c
index 675e5bf47ad..c41e5bd67eb 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -3895,6 +3895,7 @@ ExecModifyTable(PlanState *pstate)
        HeapTupleData oldtupdata;
        HeapTuple       oldtuple;
        ItemPointer tupleid;
+       bool            tuplock;
        List       *relinfos = NIL;
        ListCell   *lc;
        PartitionTupleRouting *proute = node->mt_partition_tuple_routing;
@@ -4223,6 +4224,8 @@ ExecModifyTable(PlanState *pstate)
                                break;
 
                        case CMD_UPDATE:
+                               tuplock = false;
+                               
                                if (!AttributeNumberIsValid(action_attno))
                                {
                                        /* normal non-split UPDATE */
@@ -4237,6 +4240,7 @@ ExecModifyTable(PlanState *pstate)
                                        oldSlot = 
resultRelInfo->ri_oldTupleSlot;
                                        if (oldtuple != NULL)
                                        {
+                                               
Assert(!resultRelInfo->ri_needLockTagTuple);
                                                /* Use the wholerow junk attr 
as the old tuple. */
                                                
ExecForceStoreHeapTuple(oldtuple, oldSlot, false);
                                        }
@@ -4245,7 +4249,11 @@ ExecModifyTable(PlanState *pstate)
                                                /* Fetch the most recent 
version of old tuple. */
                                                Relation        relation = 
resultRelInfo->ri_RelationDesc;
 
-                                               Assert(tupleid != NULL);
+                                               if 
(resultRelInfo->ri_needLockTagTuple)
+                                               {
+                                                       LockTuple(relation, 
tupleid, InplaceUpdateTupleLock);
+                                                       tuplock = true;
+                                               }
                                                if 
(!table_tuple_fetch_row_version(relation, tupleid,
                                                                                
                                   SnapshotAny,
                                                                                
                                   oldSlot))
@@ -4253,10 +4261,14 @@ ExecModifyTable(PlanState *pstate)
                                        }
                                        slot = 
ExecGetUpdateNewTuple(resultRelInfo, context.planSlot,
                                                                                
                 oldSlot);
+                                       context.relaction = NULL;
 
                                        /* Now apply the update. */
                                        slot = ExecUpdate(&context, 
resultRelInfo, tupleid, oldtuple,
                                                                          slot, 
segid, node->canSetTag);
+                                       if (tuplock)
+                                               
UnlockTuple(resultRelInfo->ri_RelationDesc, tupleid,
+                                                                       
InplaceUpdateTupleLock);
                                }
                                else if (action == DML_INSERT)
                                {
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index c6818fdf71e..e360e2d91c2 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -301,8 +301,8 @@ static void set_info_version(void);
 static void setup_schema(FILE *cmdfd);
 static void setup_cdb_schema(FILE *cmdfd);
 static void setup_password_history(FILE *cmdfd);
-static void load_plpgsql(FILE *cmdfd);
-static void vacuum_db(FILE *cmdfd);
+//static void load_plpgsql(FILE *cmdfd);
+//static void vacuum_db(FILE *cmdfd);
 static void make_template0(FILE *cmdfd);
 static void make_postgres(FILE *cmdfd);
 static void trapsig(SIGNAL_ARGS);
@@ -2142,6 +2142,8 @@ setup_cdb_schema(FILE *cmdfd)
                        free(*line);
                }
 
+               PG_CMD_PUTS("\n");
+               
                free(lines);
                free(path);
        }
@@ -2150,30 +2152,30 @@ setup_cdb_schema(FILE *cmdfd)
 /*
  * load PL/pgSQL server-side language
  */
-static void
-load_plpgsql(FILE *cmdfd)
-{
-       PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
-}
+//static void
+//load_plpgsql(FILE *cmdfd)
+//{
+//     PG_CMD_PUTS("CREATE EXTENSION plpgsql;\n\n");
+//}
 
 /*
  * GPDB: load external table support
  */
-static void
-load_exttable(FILE *cmdfd)
-{
-       PG_CMD_PUTS("CREATE EXTENSION gp_exttable_fdw;\n\n");
-}
+//static void
+//load_exttable(FILE *cmdfd)
+//{
+//     PG_CMD_PUTS("CREATE EXTENSION gp_exttable_fdw;\n\n");
+//}
 
 /*
  * clean everything up in template1
  */
-static void
-vacuum_db(FILE *cmdfd)
-{
-       /* Run analyze before VACUUM so the statistics are frozen. */
-       PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
-}
+//static void
+//vacuum_db(FILE *cmdfd)
+//{
+//     /* Run analyze before VACUUM so the statistics are frozen. */
+//     PG_CMD_PUTS("ANALYZE;\n\nVACUUM FREEZE;\n\n");
+//}
 
 /*
  * copy template1 to template0
@@ -2226,7 +2228,7 @@ make_template0(FILE *cmdfd)
        /*
         * Finally vacuum to clean up dead rows in pg_database
         */
-       PG_CMD_PUTS("VACUUM pg_database;\n\n");
+       // PG_CMD_PUTS("VACUUM pg_database;\n\n");
 }
 
 /*
@@ -2245,7 +2247,7 @@ make_postgres(FILE *cmdfd)
        PG_CMD_PUTS("UPDATE pg_database SET "
                                "       datistemplate = 't' "
                                "    WHERE datname = 'postgres';\n\n");
-       PG_CMD_PUTS("VACUUM FULL pg_database;\n\n");
+       //PG_CMD_PUTS("VACUUM FULL pg_database;\n\n");
 }
 
 /*
@@ -3410,14 +3412,14 @@ initialize_data_directory(void)
 
        setup_schema(cmdfd);
 
-       load_plpgsql(cmdfd);
-
-       load_exttable(cmdfd);
+//     load_plpgsql(cmdfd);
+//
+//     load_exttable(cmdfd);
 
        /* sets up the Apache Cloudberry admin schema */
        setup_cdb_schema(cmdfd);
 
-       vacuum_db(cmdfd);
+//     vacuum_db(cmdfd);
 
        make_template0(cmdfd);
 
@@ -3427,7 +3429,7 @@ initialize_data_directory(void)
         * vacuum template1 to remove the dead tuples. otherwise, some mismatch 
error 
         * will be reported in gp_replica_check.
         */
-       vacuum_db(cmdfd);
+//     vacuum_db(cmdfd);
 
        PG_CMD_CLOSE;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to