diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index ee61defd3..95979e9a7 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -1015,7 +1015,7 @@ static Oid ExecUpsert(ModifyTableState* state, TupleTableSlot* slot, TupleTableS return newid; } -extern Tuple ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot, Tuple oldtuple, Relation partRel); +extern Datum ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot, Relation partRel); /* ---------------------------------------------------------------- * ExecInsert * @@ -1343,9 +1343,9 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple case PARTTYPE_PARTITIONED_RELATION: { /* get partititon oid for insert the record */ - Tuple newtuple = ComputePartKeyExprTuple(result_relation_desc, estate, slot, tuple, NULL); - if (newtuple) - partition_id = heapTupleGetPartitionId(result_relation_desc, newtuple, false, estate->es_plannedstmt->hasIgnore); + Datum newval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, NULL); + if (newval) + partition_id = heapTupleGetPartitionId(result_relation_desc, (void*)newval, false, estate->es_plannedstmt->hasIgnore); else partition_id = heapTupleGetPartitionId(result_relation_desc, tuple, false, estate->es_plannedstmt->hasIgnore); /* if cannot find valid partition oid and sql has keyword ignore, return and don't insert */ @@ -1404,9 +1404,9 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple Partition subPart = NULL; /* get partititon oid for insert the record */ - Tuple newtuple = ComputePartKeyExprTuple(result_relation_desc, estate, slot, tuple, NULL); - if (newtuple) - partitionId = heapTupleGetPartitionId(result_relation_desc, newtuple, false, estate->es_plannedstmt->hasIgnore); + Datum newval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, NULL); + if (newval) + partitionId = heapTupleGetPartitionId(result_relation_desc, (void*)newval, false, estate->es_plannedstmt->hasIgnore); else partitionId = heapTupleGetPartitionId(result_relation_desc, tuple, false, estate->es_plannedstmt->hasIgnore); if (estate->es_plannedstmt->hasIgnore && partitionId == InvalidOid) { @@ -1425,9 +1425,9 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple } /* get subpartititon oid for insert the record */ - Tuple newsubtuple = ComputePartKeyExprTuple(result_relation_desc, estate, slot, tuple, partRel); - if (newsubtuple) - subPartitionId = heapTupleGetPartitionId(partRel, newsubtuple, false, estate->es_plannedstmt->hasIgnore); + Datum newsubval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, partRel); + if (newsubval) + subPartitionId = heapTupleGetPartitionId(partRel, (void*)newsubval, false, estate->es_plannedstmt->hasIgnore); else subPartitionId = heapTupleGetPartitionId(partRel, tuple, false, estate->es_plannedstmt->hasIgnore); if (estate->es_plannedstmt->hasIgnore && subPartitionId == InvalidOid) { @@ -2422,9 +2422,9 @@ lreplace: row_movement = false; new_partId = oldPartitionOid; } else { - Tuple newtuple = ComputePartKeyExprTuple(result_relation_desc, estate, slot, tuple, NULL); - if (newtuple) { - partitionRoutingForTuple(result_relation_desc, newtuple, u_sess->exec_cxt.route, can_ignore); + Datum newval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, NULL); + if (newval) { + partitionRoutingForTuple(result_relation_desc, (void*)newval, u_sess->exec_cxt.route, can_ignore); } else { partitionRoutingForTuple(result_relation_desc, tuple, u_sess->exec_cxt.route, can_ignore); } @@ -2434,9 +2434,9 @@ lreplace: if (RelationIsSubPartitioned(result_relation_desc)) { Partition part = partitionOpen(result_relation_desc, new_partId, RowExclusiveLock); Relation partRel = partitionGetRelation(result_relation_desc, part); - Tuple newsubtuple = ComputePartKeyExprTuple(result_relation_desc, estate, slot, tuple, partRel); - if (newsubtuple) { - partitionRoutingForTuple(partRel, newsubtuple, u_sess->exec_cxt.route, can_ignore); + Datum newsubval = ComputePartKeyExprTuple(result_relation_desc, estate, slot, partRel); + if (newsubval) { + partitionRoutingForTuple(partRel, (void*)newsubval, u_sess->exec_cxt.route, can_ignore); } else { partitionRoutingForTuple(partRel, tuple, u_sess->exec_cxt.route, can_ignore); } diff --git a/src/gausskernel/runtime/opfusion/opfusion_insert.cpp b/src/gausskernel/runtime/opfusion/opfusion_insert.cpp index 739ea7195..b7f46337b 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_insert.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_insert.cpp @@ -182,7 +182,7 @@ void InsertFusion::refreshParameterIfNecessary() } extern HeapTuple searchPgPartitionByParentIdCopy(char parttype, Oid parentId); -Tuple ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot, Tuple oldtuple, Relation partRel) +Datum ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot, Relation partRel) { Relation pgPartition = NULL; HeapTuple partitionedTuple = NULL; @@ -190,7 +190,6 @@ Tuple ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot Datum val = 0; char* partkeystr = ""; Node* partkeyexpr = NULL; - Tuple newtuple = NULL; Relation tmpRel = NULL; pgPartition = relation_open(PartitionRelationId, AccessShareLock); if (PointerIsValid(partRel)) @@ -204,7 +203,7 @@ Tuple ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot ReleaseSysCache(partitionedTuple); else heap_freetuple(partitionedTuple); - return newtuple; + return 0; } int2vector* partitionKey = NULL; Oid* partitionKeyDataType = NULL; @@ -240,18 +239,11 @@ Tuple ComputePartKeyExprTuple(Relation rel, EState *estate, TupleTableSlot *slot if (!isnull) val = datumCopy(val, boundary[0]->constbyval, boundary[0]->constlen); - bool nulls[rel->rd_att->natts] = {false}; - bool replaces[rel->rd_att->natts] = {false}; - Datum values[rel->rd_att->natts] = {0}; - values[partitionKey->values[0]-1] = val; - nulls[partitionKey->values[0]-1] = isnull; - replaces[partitionKey->values[0]-1] = true; - newtuple = tableam_tops_modify_tuple(oldtuple, rel->rd_att, values, nulls, replaces); if (PointerIsValid(partRel)) ReleaseSysCache(partitionedTuple); else heap_freetuple(partitionedTuple); - return newtuple; + return val; } unsigned long InsertFusion::ExecInsert(Relation rel, ResultRelInfo* result_rel_info) diff --git a/src/include/utils/partitionmap_gs.h b/src/include/utils/partitionmap_gs.h index 4fb196ae6..e4977873a 100644 --- a/src/include/utils/partitionmap_gs.h +++ b/src/include/utils/partitionmap_gs.h @@ -162,14 +162,15 @@ typedef struct HashPartitionMap { tuple_desc = (rel)->rd_att; \ for (i = 0; i < partkey_column_n; i++) { \ isnull = false; \ - column_raw = (is_ustore) \ - ? UHeapFastGetAttr((UHeapTuple)(tuple), partkey_column->values[i], tuple_desc, &isnull) \ - : fastgetattr((HeapTuple)(tuple), partkey_column->values[i], tuple_desc, &isnull); \ bool isNull = PartExprKeyIsNull(rel, NULL); \ if (isNull) { \ + column_raw = (is_ustore) \ + ? UHeapFastGetAttr((UHeapTuple)(tuple), partkey_column->values[i], tuple_desc, &isnull) \ + : fastgetattr((HeapTuple)(tuple), partkey_column->values[i], tuple_desc, &isnull); \ values[i] = \ transformDatum2Const((rel)->rd_att, partkey_column->values[i], column_raw, isnull, &consts[i]); \ } else { \ + column_raw = Datum(tuple); \ values[i] = \ transformDatum2ConstForPartKeyExpr((rel)->partMap, column_raw, isnull, &consts[i]); \ } \