From 78e748a74417ac725f146ce018de4e564dcd0722 Mon Sep 17 00:00:00 2001 From: chenxiaobin19 <1025221611@qq.com> Date: Mon, 28 Oct 2024 19:59:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=87=8F=E4=B8=8Breplace=E5=88=86=E9=85=8D=E8=BF=87=E5=A4=9A?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/executor/nodeModifyTable.cpp | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index 18510d378..6a00615f0 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -3306,27 +3306,21 @@ uint64 GetDeleteLimitCount(ExprContext* econtext, PlanState* scan, Limit *limitP return (uint64)iCount; } -static TupleTableSlot* ExecReplace(EState* estate, ModifyTableState* node, TupleTableSlot* slot, - TupleTableSlot* plan_slot, int2 bucketid, int hi_options, List* partition_list, char* partExprKeyStr, - bool replaceNull) +/* REPLACE INTO not support sequence, check columns to report ERROR */ +static void checkSequenceForReplace(Relation rel) { Form_pg_attribute att_tup; Oid seqOid = InvalidOid; - Relation rel = estate->es_result_relation_info->ri_RelationDesc; - TupleTableSlot* (*ExecInsert)( - ModifyTableState* state, TupleTableSlot*, TupleTableSlot*, EState*, bool, int, List**, char*, bool) = NULL; + static int tableNameSize = NAMEDATALEN * 2 + 2; + char tableName[tableNameSize] = {0}; - ExecInsert = ExecInsertT; - - /* REPLACE INTO not support sequence, check columns to report ERROR */ - for (int attrno=1; attrno<=rel->rd_att->natts; ++attrno) { + for (int attrno = 1; attrno <= rel->rd_att->natts; ++attrno) { att_tup = &rel->rd_att->attrs[attrno-1]; errno_t rc; char *nspname = get_namespace_name(rel->rd_rel->relnamespace); - char tableName[NAMEDATALEN*2+2] = {0}; text *tbname; text *attname; - rc = memset_s(tableName, NAMEDATALEN*2, 0, NAMEDATALEN*2); + rc = memset_s(tableName, tableNameSize, 0, tableNameSize); securec_check(rc, "\0", "\0"); if (nspname != NULL) { @@ -3334,13 +3328,13 @@ static TupleTableSlot* ExecReplace(EState* estate, ModifyTableState* node, Tuple int nspnameLen = strlen(nspname); int symLen = strlen(sym); int tbnameLen = strlen(rel->rd_rel->relname.data); - rc = memcpy_s(&tableName[0], NAMEDATALEN*2+2, nspname, nspnameLen); - securec_check(rc, "\0","\0"); - rc = memcpy_s(&tableName[nspnameLen], NAMEDATALEN*2+2, sym, symLen); - securec_check(rc, "\0","\0"); - rc = memcpy_s(&tableName[nspnameLen+symLen], NAMEDATALEN*2+2, rel->rd_rel->relname.data, tbnameLen); - securec_check(rc, "\0","\0"); - tableName[nspnameLen+symLen+tbnameLen] = 0; + rc = memcpy_s(&tableName[0], tableNameSize, nspname, nspnameLen); + securec_check(rc, "\0", "\0"); + rc = memcpy_s(&tableName[nspnameLen], tableNameSize, sym, symLen); + securec_check(rc, "\0", "\0"); + rc = memcpy_s(&tableName[nspnameLen + symLen], tableNameSize, rel->rd_rel->relname.data, tbnameLen); + securec_check(rc, "\0", "\0"); + tableName[nspnameLen + symLen + tbnameLen] = 0; tbname = cstring_to_text(&tableName[0]); } else { tbname = cstring_to_text(rel->rd_rel->relname.data); @@ -3348,11 +3342,20 @@ static TupleTableSlot* ExecReplace(EState* estate, ModifyTableState* node, Tuple attname = cstring_to_text(att_tup->attname.data); seqOid = pg_get_serial_sequence_oid(tbname, attname); - - if (OidIsValid(seqOid)) + if (OidIsValid(seqOid)) { elog(ERROR, "REPLACE can not work on sequence!"); + } } +} +static TupleTableSlot* ExecReplace(EState* estate, ModifyTableState* node, TupleTableSlot* slot, + TupleTableSlot* plan_slot, int2 bucketid, int hi_options, List* partition_list, char* partExprKeyStr, + bool replaceNull) +{ + TupleTableSlot* (*ExecInsert)( + ModifyTableState* state, TupleTableSlot*, TupleTableSlot*, EState*, bool, int, List**, char*, bool) = NULL; + + ExecInsert = ExecInsertT; /* set flag to start loop */ node->isConflict = true; @@ -3582,6 +3585,11 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) subPlanState->state->es_skip_early_free = true; subPlanState->state->es_skip_early_deinit_consumer = true; + + if (node->isReplace) { + checkSequenceForReplace(estate->es_result_relation_info->ri_RelationDesc); + } + /* * Fetch rows from subplan(s), and execute the required table modification * for each row.