diff --git a/src/common/backend/catalog/index.cpp b/src/common/backend/catalog/index.cpp index f870d68f7..a9c9fa4d7 100644 --- a/src/common/backend/catalog/index.cpp +++ b/src/common/backend/catalog/index.cpp @@ -4210,7 +4210,7 @@ double IndexBuildUHeapScan(Relation heapRelation, Relation indexRelation, IndexI */ estate = CreateExecutorState(); econtext = GetPerTupleExprContext(estate); - slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation), false, GetTableAmRoutine(heapRelation->rd_tam_type)); + slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation), false, heapRelation->rd_tam_ops); /* Arrange for econtext's scan tuple to be the tuple under test */ econtext->ecxt_scantuple = slot; @@ -6320,7 +6320,7 @@ void ScanHeapInsertCBI(Relation parentRel, Relation heapRel, Relation idxRel, Oi tupleDesc = heapRel->rd_att; estate = CreateExecutorState(); econtext = GetPerTupleExprContext(estate); - slot = MakeSingleTupleTableSlot(RelationGetDescr(parentRel), false, GetTableAmRoutine(parentRel->rd_tam_type)); + slot = MakeSingleTupleTableSlot(RelationGetDescr(parentRel), false, parentRel->rd_tam_ops); econtext->ecxt_scantuple = slot; /* Set up execution state for predicate, if any. */ predicate = (List*)ExecPrepareExpr((Expr*)idxInfo->ii_Predicate, estate); @@ -6548,7 +6548,7 @@ void ScanPartitionInsertIndex(Relation partTableRel, Relation partRel, const Lis if (PointerIsValid(indexRelList)) { estate = CreateExecutorState(); - slot = MakeSingleTupleTableSlot(RelationGetDescr(partTableRel), false, GetTableAmRoutine(partTableRel->rd_tam_type)); + slot = MakeSingleTupleTableSlot(RelationGetDescr(partTableRel), false, partTableRel->rd_tam_ops); } scan = scan_handler_tbl_beginscan(partRel, SnapshotNow, 0, NULL); @@ -6768,7 +6768,7 @@ void ScanPartitionDeleteGPITuples(Relation partTableRel, Relation partRel, const if (PointerIsValid(indexRelList)) { estate = CreateExecutorState(); - slot = MakeSingleTupleTableSlot(RelationGetDescr(partTableRel), false, GetTableAmRoutine(partTableRel->rd_tam_type)); + slot = MakeSingleTupleTableSlot(RelationGetDescr(partTableRel), false, partTableRel->rd_tam_ops); } scan = scan_handler_tbl_beginscan(partRel, SnapshotNow, 0, NULL); diff --git a/src/common/backend/utils/cache/knl_globaltabdefcache.cpp b/src/common/backend/utils/cache/knl_globaltabdefcache.cpp index 97caa8c00..bbfa4fcda 100644 --- a/src/common/backend/utils/cache/knl_globaltabdefcache.cpp +++ b/src/common/backend/utils/cache/knl_globaltabdefcache.cpp @@ -686,7 +686,7 @@ Relation BuildRelationFromPartRel(Relation rel, Partition part, bytea* merge_rel relation->rd_am = CopyRelationAm(rel); relation->rd_indnkeyatts = rel->rd_indnkeyatts; - relation->rd_tam_type = rel->rd_tam_type; + relation->rd_tam_ops = rel->rd_tam_ops; if (!OidIsValid(rel->rd_rel->relam)) { relation->rd_indexcxt = NULL; diff --git a/src/common/backend/utils/cache/partcache.cpp b/src/common/backend/utils/cache/partcache.cpp index d05cbc726..154e80ed1 100644 --- a/src/common/backend/utils/cache/partcache.cpp +++ b/src/common/backend/utils/cache/partcache.cpp @@ -1558,7 +1558,7 @@ Relation partitionGetRelation(Relation rel, Partition part) relation->rd_indextuple = rel->rd_indextuple; relation->rd_am = rel->rd_am; relation->rd_indnkeyatts = rel->rd_indnkeyatts; - relation->rd_tam_type = rel->rd_tam_type; + relation->rd_tam_ops = rel->rd_tam_ops; if (!OidIsValid(rel->rd_rel->relam)) { relation->rd_indexcxt = NULL; diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index a0f493c38..71c237622 100644 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -1434,9 +1434,9 @@ static Relation AllocateRelationDesc(Form_pg_class relp) relation->rd_rel = relationForm; /* and allocate attribute tuple form storage */ - relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts, relationForm->relhasoids, NULL); + relation->rd_att = CreateTemplateTupleDesc(relationForm->relnatts, relationForm->relhasoids); //TODO:this should be TAM_invalid when merge ustore - relation->rd_tam_type = TAM_HEAP; + relation->rd_tam_ops = TableAmHeap; /* which we mark as a reference-counted tupdesc */ relation->rd_att->tdrefcount = 1; @@ -2013,7 +2013,7 @@ static Relation CatalogRelationBuildDesc(const char* relationName, Oid relationR relation->rd_rel->relhasoids = hasoids; relation->rd_rel->relnatts = (int16)natts; // Catalog tables are heap table type. - relation->rd_tam_type = TAM_HEAP; + relation->rd_tam_ops = TableAmHeap; relation->rd_att = CreateTemplateTupleDesc(natts, hasoids, TableAmHeap); relation->rd_att->tdrefcount = 1; /* mark as refcounted */ relation->rd_att->tdtypeid = relationReltype; @@ -2242,9 +2242,9 @@ Relation RelationBuildDesc(Oid targetRelId, bool insertIt, bool buildkey) /* get the table access method type from reloptions * and populate them in relation and tuple descriptor */ - relation->rd_tam_type = - get_tableam_from_reloptions(relation->rd_options, relation->rd_rel->relkind, relation->rd_rel->relam); - relation->rd_att->td_tam_ops = GetTableAmRoutine(relation->rd_tam_type); + relation->rd_tam_ops = GetTableAmRoutine( + get_tableam_from_reloptions(relation->rd_options, relation->rd_rel->relkind, relation->rd_rel->relam)); + relation->rd_att->td_tam_ops = relation->rd_tam_ops; relation->rd_indexsplit = get_indexsplit_from_reloptions(relation->rd_options, relation->rd_rel->relam); @@ -3035,7 +3035,7 @@ extern void formrdesc(const char* relationName, Oid relationReltype, bool isshar pg_database, pg_authid, pg_auth_members, pg_class, pg_attribute, pg_proc, and pg_type */ relation->rd_att = CreateTemplateTupleDesc(natts, hasoids); - relation->rd_tam_type = TAM_HEAP; + relation->rd_tam_ops = TableAmHeap; relation->rd_att->tdrefcount = 1; /* mark as refcounted */ relation->rd_att->tdtypeid = relationReltype; @@ -3150,7 +3150,7 @@ Relation RelationIdGetRelation(Oid relationId) if (EnableLocalSysCache()) { Relation rel = t_thrd.lsc_cxt.lsc->tabdefcache.RelationIdGetRelation(relationId); if (rel != NULL) { - rel->rd_att->td_tam_ops = GetTableAmRoutine(rel->rd_tam_type); + rel->rd_att->td_tam_ops = rel->rd_tam_ops; } return rel; } @@ -3184,7 +3184,7 @@ Relation RelationIdGetRelation(Oid relationId) if (rd->rd_rel->relpersistence == RELPERSISTENCE_TEMP) (void)checkGroup(relationId, RELATION_IS_OTHER_TEMP(rd)); - rd->rd_att->td_tam_ops = GetTableAmRoutine(rd->rd_tam_type); + rd->rd_att->td_tam_ops = rd->rd_tam_ops; return rd; } @@ -3202,7 +3202,7 @@ Relation RelationIdGetRelation(Oid relationId) } if (rd != NULL) { - rd->rd_att->td_tam_ops = GetTableAmRoutine(rd->rd_tam_type); + rd->rd_att->td_tam_ops = rd->rd_tam_ops; } return rd; } @@ -4431,6 +4431,7 @@ Relation RelationBuildLocalRelation(const char* relname, Oid relnamespace, Tuple int i; bool has_not_null = false; bool nailit = false; + const TableAmRoutine* tam_ops = GetTableAmRoutine(tam_type); AssertArg(natts >= 0); @@ -4506,9 +4507,9 @@ Relation RelationBuildLocalRelation(const char* relname, Oid relnamespace, Tuple * catalogs. We can copy attnotnull constraints here, however. */ rel->rd_att = CreateTupleDescCopy(tupDesc); - rel->rd_tam_type = tam_type; + rel->rd_tam_ops = tam_ops; rel->rd_indexsplit = relindexsplit; - rel->rd_att->td_tam_ops = GetTableAmRoutine(tam_type); + rel->rd_att->td_tam_ops = tam_ops; rel->rd_att->tdrefcount = 1; /* mark as refcounted */ has_not_null = false; for (i = 0; i < natts; i++) { diff --git a/src/common/backend/utils/sort/tuplesort.cpp b/src/common/backend/utils/sort/tuplesort.cpp index 9e6c6102a..3d3d2740c 100644 --- a/src/common/backend/utils/sort/tuplesort.cpp +++ b/src/common/backend/utils/sort/tuplesort.cpp @@ -3410,8 +3410,7 @@ static void copytup_heap(Tuplesortstate* state, SortTuple* stup, void* tup) /* set up first-column key value */ htup.t_len = tuple->t_len + MINIMAL_TUPLE_OFFSET; htup.t_data = (HeapTupleHeader)((char*)tuple - MINIMAL_TUPLE_OFFSET); - original = tableam_tops_tuple_getattr(&htup, state->sortKeys[0].ssup_attno, state->tupDesc, &stup->isnull1); - + original = tableam_tops_tuple_getattr(&htup, state->sortKeys[0].ssup_attno, state->tupDesc, &stup->isnull1); if (!state->sortKeys->abbrev_converter || stup->isnull1) { /* * Store ordinary Datum representation, or NULL value. If there is a diff --git a/src/gausskernel/bootstrap/bootstrap.cpp b/src/gausskernel/bootstrap/bootstrap.cpp index 139f4507d..6267875ea 100755 --- a/src/gausskernel/bootstrap/bootstrap.cpp +++ b/src/gausskernel/bootstrap/bootstrap.cpp @@ -740,7 +740,7 @@ void InsertOneTuple(Oid objectid) tupDesc = CreateTupleDesc(t_thrd.bootstrap_cxt.numattr, RelationGetForm(t_thrd.bootstrap_cxt.boot_reldesc)->relhasoids, t_thrd.bootstrap_cxt.attrtypes, - GetTableAmRoutine(t_thrd.bootstrap_cxt.boot_reldesc->rd_tam_type)); + t_thrd.bootstrap_cxt.boot_reldesc->rd_tam_ops); tuple = (HeapTuple) tableam_tops_form_tuple(tupDesc, values, Nulls); if (objectid != (Oid)0) HeapTupleSetOid(tuple, objectid); diff --git a/src/gausskernel/optimizer/commands/analyze.cpp b/src/gausskernel/optimizer/commands/analyze.cpp index 7e9a383bc..93d16f755 100755 --- a/src/gausskernel/optimizer/commands/analyze.cpp +++ b/src/gausskernel/optimizer/commands/analyze.cpp @@ -2571,7 +2571,7 @@ retry: } /* TO DO: Need to switch this to inplaceheapam_scan_analyze_next_block after we have tableam. */ - TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(onerel), false, GetTableAmRoutine(onerel->rd_tam_type)); + TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(onerel), false, onerel->rd_tam_ops); maxoffset = UHeapPageGetMaxOffsetNumber(targpage); /* Inner loop over all tuples on the selected page */ diff --git a/src/gausskernel/optimizer/commands/cluster.cpp b/src/gausskernel/optimizer/commands/cluster.cpp index afa644a4f..9dc914569 100755 --- a/src/gausskernel/optimizer/commands/cluster.cpp +++ b/src/gausskernel/optimizer/commands/cluster.cpp @@ -2382,7 +2382,7 @@ static void copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, int if (isNull) { relfrozenxid = OldHeap->rd_rel->relfrozenxid; - if (OldHeap->rd_tam_type == TAM_USTORE) { + if (OldHeap->rd_tam_ops == TableAmUstore) { elog(ERROR, "cluster not supported in ustore"); } diff --git a/src/gausskernel/optimizer/commands/copy.cpp b/src/gausskernel/optimizer/commands/copy.cpp index babc1f3b4..5e1541537 100644 --- a/src/gausskernel/optimizer/commands/copy.cpp +++ b/src/gausskernel/optimizer/commands/copy.cpp @@ -4037,7 +4037,7 @@ uint64 CopyFrom(CopyState cstate) estate->es_range_table = cstate->range_table; /* Set up a tuple slot too */ - myslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(cstate->rel->rd_tam_type)); + myslot = ExecInitExtraTupleSlot(estate, cstate->rel->rd_tam_ops); ExecSetSlotDescriptor(myslot, tupDesc); /* Triggers might need a slot as well */ estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate); @@ -4563,7 +4563,7 @@ uint64 CopyFrom(CopyState cstate) #endif /* And now we can form the input tuple. */ - tuple = (Tuple)tableam_tops_form_tuple(tupDesc, values, nulls, GetTableAmRoutine(cstate->rel->rd_tam_type)); + tuple = (Tuple)tableam_tops_form_tuple(tupDesc, values, nulls, cstate->rel->rd_tam_ops); if (loaded_oid != InvalidOid) HeapTupleSetOid((HeapTuple)tuple, loaded_oid); diff --git a/src/gausskernel/optimizer/commands/indexcmds.cpp b/src/gausskernel/optimizer/commands/indexcmds.cpp index 15a7a839c..019b9970d 100644 --- a/src/gausskernel/optimizer/commands/indexcmds.cpp +++ b/src/gausskernel/optimizer/commands/indexcmds.cpp @@ -757,7 +757,7 @@ Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_al SetUserIdAndSecContext(rel->rd_rel->relowner, root_save_sec_context | SECURITY_RESTRICTED_OPERATION); /* Forbidden to create gin index on ustore table. */ - if (rel->rd_tam_type == TAM_USTORE) { + if (rel->rd_tam_ops == TableAmUstore) { if (strcmp(stmt->accessMethod, "btree") == 0) { elog(ERROR, "btree index is not supported for ustore, please use ubtree instead"); } @@ -776,7 +776,7 @@ Oid DefineIndex(Oid relationId, IndexStmt* stmt, Oid indexRelationId, bool is_al } if (strcmp(stmt->accessMethod, "ubtree") == 0 && - rel->rd_tam_type != TAM_USTORE) { + rel->rd_tam_ops != TableAmUstore) { elog(ERROR, "ubtree index is only supported for ustore"); } diff --git a/src/gausskernel/optimizer/commands/matview.cpp b/src/gausskernel/optimizer/commands/matview.cpp index 299979d6e..10d7a5840 100755 --- a/src/gausskernel/optimizer/commands/matview.cpp +++ b/src/gausskernel/optimizer/commands/matview.cpp @@ -1257,7 +1257,7 @@ static void ExecCreateMatInc(QueryDesc*queryDesc, Query *query, Relation matview while ((tuple = (HeapTuple) tableam_scan_getnexttuple(scan, ForwardScanDirection)) != NULL) { HeapTuple tmpTuple = NULL; /* here we want handle every tuple. */ - if (rel->rd_tam_type == TAM_USTORE) { + if (rel->rd_tam_ops == TableAmUstore) { tmpTuple = UHeapToHeap(rel->rd_att, (UHeapTuple)tuple); tmpTuple->t_xid_base = ((UHeapTuple)tuple)->t_xid_base; tmpTuple->t_data->t_choice.t_heap.t_xmin = ((UHeapTuple)tuple)->disk_tuple->xid; diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index 43043b71f..59929f0f4 100644 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -9096,8 +9096,8 @@ static void ATRewriteTableInternal(AlteredTableInfo* tab, Relation oldrel, Relat * tuples are the same, the tupDescs might not be (consider ADD COLUMN * without a default). */ - oldslot = MakeSingleTupleTableSlot(oldTupDesc, false, GetTableAmRoutine(oldrel->rd_tam_type)); - newslot = MakeSingleTupleTableSlot(newTupDesc, false, GetTableAmRoutine(oldrel->rd_tam_type)); + oldslot = MakeSingleTupleTableSlot(oldTupDesc, false, oldrel->rd_tam_ops); + newslot = MakeSingleTupleTableSlot(newTupDesc, false, oldrel->rd_tam_ops); /* Preallocate values/isnull arrays */ i = Max(newTupDesc->natts, oldTupDesc->natts); @@ -11709,7 +11709,7 @@ static void ATExecAddConstraint(List** wqueue, AlteredTableInfo* tab, Relation r (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("column store unsupport constraint \"%s\"", GetConstraintType(newConstraint->contype)))); - if (rel->rd_tam_type == TAM_USTORE && newConstraint->deferrable == true) { + if (rel->rd_tam_ops == TableAmUstore && newConstraint->deferrable == true) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmodule(MOD_COMMAND), @@ -12879,7 +12879,7 @@ static void validateCheckConstraint(Relation rel, HeapTuple constrtup) List* exprstate = (List*)ExecPrepareExpr((Expr*)make_ands_implicit(origexpr), estate); ExprContext* econtext = GetPerTupleExprContext(estate); TupleDesc tupdesc = RelationGetDescr(rel); - TupleTableSlot* slot = MakeSingleTupleTableSlot(tupdesc, false, GetTableAmRoutine(rel->rd_tam_type)); + TupleTableSlot* slot = MakeSingleTupleTableSlot(tupdesc, false, rel->rd_tam_ops); econtext->ecxt_scantuple = slot; diff --git a/src/gausskernel/optimizer/util/dataskew.cpp b/src/gausskernel/optimizer/util/dataskew.cpp index ed6a39fe4..210f15c63 100755 --- a/src/gausskernel/optimizer/util/dataskew.cpp +++ b/src/gausskernel/optimizer/util/dataskew.cpp @@ -1399,7 +1399,7 @@ bool SkewInfo::canValuePassQual(List* varList, List* valueList, Expr* expr) rte = planner_rt_fetch(rel->relid, m_root); heaprel = heap_open(rte->relid, NoLock); tupdesc = RelationGetDescr(heaprel); - slot = MakeSingleTupleTableSlot(tupdesc, false, GetTableAmRoutine(heaprel->rd_tam_type)); + slot = MakeSingleTupleTableSlot(tupdesc, false, heaprel->rd_tam_ops); slot->tts_nvalid = tupdesc->natts; heap_close(heaprel, NoLock); diff --git a/src/gausskernel/runtime/executor/execJunk.cpp b/src/gausskernel/runtime/executor/execJunk.cpp index a1b188ac3..4f99056ca 100644 --- a/src/gausskernel/runtime/executor/execJunk.cpp +++ b/src/gausskernel/runtime/executor/execJunk.cpp @@ -208,7 +208,7 @@ void ExecInitJunkAttr(EState* estate, CmdType operation, List* targetlist, Resul j = ExecInitJunkFilter(targetlist, result_rel_info->ri_RelationDesc->rd_att->tdhasoid, - ExecInitExtraTupleSlot(estate, GetTableAmRoutine(result_rel_info->ri_RelationDesc->rd_tam_type)), TableAmHeap); + ExecInitExtraTupleSlot(estate, result_rel_info->ri_RelationDesc->rd_tam_ops), TableAmHeap); if (operation == CMD_UPDATE || operation == CMD_DELETE || operation == CMD_MERGE) { /* For UPDATE/DELETE, find the appropriate junk attr now */ diff --git a/src/gausskernel/runtime/executor/execTuples.cpp b/src/gausskernel/runtime/executor/execTuples.cpp index a6dcf08cb..87b86148a 100644 --- a/src/gausskernel/runtime/executor/execTuples.cpp +++ b/src/gausskernel/runtime/executor/execTuples.cpp @@ -673,7 +673,8 @@ Datum ExecFetchSlotTupleDatum(TupleTableSlot* slot) * to scribble on. * -------------------------------- */ -HeapTuple ExecMaterializeSlot(TupleTableSlot* slot) +static FORCE_INLINE +HeapTuple ExecMaterializeSlot_impl(TupleTableSlot* slot) { /* * sanity checks @@ -684,6 +685,19 @@ HeapTuple ExecMaterializeSlot(TupleTableSlot* slot) return tableam_tslot_materialize(slot); } + +HeapTuple ExecMaterializeSlot(TupleTableSlot* slot) +{ + return ExecMaterializeSlot_impl(slot); +} + +Tuple heap_slot_get_tuple_from_slot(TupleTableSlot* slot) +{ + HeapTuple tuple = ExecMaterializeSlot_impl(slot); + tuple->tupInfo = 0; + return (Tuple) tuple; +} + /* -------------------------------- * ExecCopySlot * Copy the source slot's contents into the destination slot. diff --git a/src/gausskernel/runtime/executor/execUtils.cpp b/src/gausskernel/runtime/executor/execUtils.cpp index c7ca021ae..2810cb465 100644 --- a/src/gausskernel/runtime/executor/execUtils.cpp +++ b/src/gausskernel/runtime/executor/execUtils.cpp @@ -2138,7 +2138,7 @@ bool check_violation(Relation heap, Relation index, IndexInfo *indexInfo, ItemPo * to this slot. Be sure to save and restore caller's value for * scantuple. */ - existing_slot = MakeSingleTupleTableSlot(RelationGetDescr(heap), false, GetTableAmRoutine(heap->rd_tam_type)); + existing_slot = MakeSingleTupleTableSlot(RelationGetDescr(heap), false, heap->rd_tam_ops); econtext = GetPerTupleExprContext(estate); save_scantuple = econtext->ecxt_scantuple; econtext->ecxt_scantuple = existing_slot; diff --git a/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp b/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp index b2c287b1a..1b7e6885d 100644 --- a/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp +++ b/src/gausskernel/runtime/executor/nodeBitmapHeapscan.cpp @@ -807,8 +807,8 @@ BitmapHeapScanState* ExecInitBitmapHeapScan(BitmapHeapScan* node, EState* estate /* * tuple table initialization */ - ExecInitResultTupleSlot(estate, &scanstate->ss.ps, GetTableAmRoutine(currentRelation->rd_tam_type)); - ExecInitScanTupleSlot(estate, &scanstate->ss, GetTableAmRoutine(currentRelation->rd_tam_type)); + ExecInitResultTupleSlot(estate, &scanstate->ss.ps, currentRelation->rd_tam_ops); + ExecInitScanTupleSlot(estate, &scanstate->ss, currentRelation->rd_tam_ops); InitBitmapHeapScanNextMtd(scanstate); diff --git a/src/gausskernel/runtime/executor/nodeIndexonlyscan.cpp b/src/gausskernel/runtime/executor/nodeIndexonlyscan.cpp index 8034c7b6e..ee69070a0 100644 --- a/src/gausskernel/runtime/executor/nodeIndexonlyscan.cpp +++ b/src/gausskernel/runtime/executor/nodeIndexonlyscan.cpp @@ -139,7 +139,7 @@ static TupleTableSlot* IndexOnlyNext(IndexOnlyScanState* node) slot = node->ss.ss_ScanTupleSlot; isUHeap = RelationIsUstoreFormat(node->ss.ss_currentRelation); tmpslot = MakeSingleTupleTableSlot(RelationGetDescr(scandesc->heapRelation), - false, GetTableAmRoutine(scandesc->heapRelation->rd_tam_type)); + false, scandesc->heapRelation->rd_tam_ops); /* * OK, now that we have what we need, fetch the next tuple. @@ -589,8 +589,8 @@ IndexOnlyScanState* ExecInitIndexOnlyScan(IndexOnlyScan* node, EState* estate, i /* * tuple table initialization */ - ExecInitResultTupleSlot(estate, &indexstate->ss.ps, GetTableAmRoutine(currentRelation->rd_tam_type)); - ExecInitScanTupleSlot(estate, &indexstate->ss, GetTableAmRoutine(currentRelation->rd_tam_type)); + ExecInitResultTupleSlot(estate, &indexstate->ss.ps, currentRelation->rd_tam_ops); + ExecInitScanTupleSlot(estate, &indexstate->ss, currentRelation->rd_tam_ops); /* * Build the scan tuple type using the indextlist generated by the diff --git a/src/gausskernel/runtime/executor/nodeIndexscan.cpp b/src/gausskernel/runtime/executor/nodeIndexscan.cpp index 451303826..6d752de3f 100644 --- a/src/gausskernel/runtime/executor/nodeIndexscan.cpp +++ b/src/gausskernel/runtime/executor/nodeIndexscan.cpp @@ -693,14 +693,14 @@ IndexScanState* ExecInitIndexScan(IndexScan* node, EState* estate, int eflags) /* * tuple table initialization */ - ExecInitResultTupleSlot(estate, &index_state->ss.ps, GetTableAmRoutine(current_relation->rd_tam_type)); - ExecInitScanTupleSlot(estate, &index_state->ss, GetTableAmRoutine(current_relation->rd_tam_type)); + ExecInitResultTupleSlot(estate, &index_state->ss.ps, current_relation->rd_tam_ops); + ExecInitScanTupleSlot(estate, &index_state->ss, current_relation->rd_tam_ops); /* * get the scan type from the relation descriptor. */ ExecAssignScanType(&index_state->ss, CreateTupleDescCopy(RelationGetDescr(current_relation))); - index_state->ss.ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = GetTableAmRoutine(current_relation->rd_tam_type); + index_state->ss.ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = current_relation->rd_tam_ops; /* * Initialize result tuple type and projection info. diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index b93cde5b8..581e8e2da 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -1019,7 +1019,7 @@ static Oid ExecUpsert(ModifyTableState* state, TupleTableSlot* slot, TupleTableS /* try to insert tuple into mlog-table. */ if (targetrel != NULL && targetrel->rd_mlogoid != InvalidOid) { /* judge whether need to insert into mlog-table */ - if (targetrel->rd_tam_type == TAM_USTORE) { + if (targetrel->rd_tam_ops == TableAmUstore) { tuple = (Tuple)UHeapToHeap(targetrel->rd_att, (UHeapTuple)tuple); } insert_into_mlog_table(targetrel, targetrel->rd_mlogoid, (HeapTuple)tuple, @@ -1220,7 +1220,7 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple } else #endif if (useHeapMultiInsert) { - TupleTableSlot* tmp_slot = MakeSingleTupleTableSlot(slot->tts_tupleDescriptor, false, GetTableAmRoutine(result_relation_desc->rd_tam_type)); + TupleTableSlot* tmp_slot = MakeSingleTupleTableSlot(slot->tts_tupleDescriptor, false, result_relation_desc->rd_tam_ops); bool is_partition_rel = result_relation_desc->rd_rel->parttype == PARTTYPE_PARTITIONED_RELATION; Oid targetOid = InvalidOid; @@ -1282,7 +1282,7 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple tuple = tableam_tops_form_tuple(slot->tts_tupleDescriptor, slot->tts_values, slot->tts_isnull, - GetTableAmRoutine(result_relation_desc->rd_tam_type)); + result_relation_desc->rd_tam_ops); if (rel_isblockchain) { MemoryContext old_context = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); tuple = set_user_tuple_hash((HeapTuple)tuple, result_relation_desc); @@ -1569,7 +1569,7 @@ TupleTableSlot* ExecInsertT(ModifyTableState* state, TupleTableSlot* slot, Tuple /* try to insert tuple into mlog-table. */ if (target_rel != NULL && target_rel->rd_mlogoid != InvalidOid) { /* judge whether need to insert into mlog-table */ - if (target_rel->rd_tam_type == TAM_USTORE) { + if (target_rel->rd_tam_ops == TableAmUstore) { tuple = (Tuple)UHeapToHeap(target_rel->rd_att, (UHeapTuple)tuple); } insert_into_mlog_table(target_rel, target_rel->rd_mlogoid, (HeapTuple)tuple, @@ -1939,7 +1939,7 @@ end:; if (slot->tts_tupleDescriptor != RelationGetDescr(result_relation_desc)) { ExecSetSlotDescriptor(slot, RelationGetDescr(result_relation_desc)); } - slot->tts_tam_ops = GetTableAmRoutine(result_relation_desc->rd_tam_type); + slot->tts_tam_ops = result_relation_desc->rd_tam_ops; if (oldtuple != NULL) { Assert(!TTS_TABLEAM_IS_USTORE(slot)); del_tuple.t_data = oldtuple; @@ -3027,7 +3027,7 @@ ldelete: insert_into_mlog_table(result_relation_desc, result_relation_desc->rd_mlogoid, NULL, tupleid, tmfd.xmin, 'D'); /* 2. insert new tuple */ - if (result_relation_desc->rd_tam_type == TAM_USTORE) { + if (result_relation_desc->rd_tam_ops == TableAmUstore) { tuple = (Tuple)UHeapToHeap(result_relation_desc->rd_att, (UHeapTuple)tuple); } insert_into_mlog_table(result_relation_desc, result_relation_desc->rd_mlogoid, @@ -3531,7 +3531,7 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) if (estate->result_rel_index == 0) EvalPlanQualSetSlot(&node->mt_epqstate, plan_slot); slot = plan_slot; - slot->tts_tupleDescriptor->td_tam_ops = GetTableAmRoutine(result_rel_info->ri_RelationDesc->rd_tam_type); + slot->tts_tupleDescriptor->td_tam_ops = result_rel_info->ri_RelationDesc->rd_tam_ops; if (operation == CMD_MERGE) { if (junk_filter == NULL) { @@ -4056,7 +4056,7 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl * RETURNING list. We assume the rest will look the same. */ tup_desc = ExecTypeFromTL((List*)linitial(node->returningLists), false, false, - GetTableAmRoutine(mt_state->resultRelInfo->ri_RelationDesc->rd_tam_type)); + mt_state->resultRelInfo->ri_RelationDesc->rd_tam_ops); /* Set up a slot for the output of the RETURNING projection(s) */ ExecInitResultTupleSlot(estate, &mt_state->ps); @@ -4113,7 +4113,7 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl /* initialize slot for the existing tuple */ upsertState->us_existing = - ExecInitExtraTupleSlot(mt_state->ps.state, GetTableAmRoutine(result_rel_info->ri_RelationDesc->rd_tam_type)); + ExecInitExtraTupleSlot(mt_state->ps.state, result_rel_info->ri_RelationDesc->rd_tam_ops); ExecSetSlotDescriptor(upsertState->us_existing, result_rel_info->ri_RelationDesc->rd_att); upsertState->us_excludedtlist = node->exclRelTlist; @@ -4121,7 +4121,7 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl /* create target slot for UPDATE SET projection */ tupDesc = ExecTypeFromTL((List*)node->updateTlist, result_rel_info->ri_RelationDesc->rd_rel->relhasoids); upsertState->us_updateproj = - ExecInitExtraTupleSlot(mt_state->ps.state, GetTableAmRoutine(result_rel_info->ri_RelationDesc->rd_tam_type)); + ExecInitExtraTupleSlot(mt_state->ps.state, result_rel_info->ri_RelationDesc->rd_tam_ops); ExecSetSlotDescriptor(upsertState->us_updateproj, tupDesc); /* build UPDATE SET expression and projection state */ @@ -4275,7 +4275,7 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl */ if (estate->es_trig_tuple_slot == NULL) { result_rel_info = mt_state->resultRelInfo; - estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(result_rel_info->ri_RelationDesc->rd_tam_type)); + estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, result_rel_info->ri_RelationDesc->rd_tam_ops); } /* diff --git a/src/gausskernel/runtime/executor/nodeSamplescan.cpp b/src/gausskernel/runtime/executor/nodeSamplescan.cpp index 221c8e3f3..dfd9392f3 100644 --- a/src/gausskernel/runtime/executor/nodeSamplescan.cpp +++ b/src/gausskernel/runtime/executor/nodeSamplescan.cpp @@ -116,12 +116,12 @@ static inline UHeapTuple USampleFetchNextTuple(SeqScanState* node) TupleTableSlot* HeapSeqSampleNext(SeqScanState* node) { TupleTableSlot* slot = node->ss_ScanTupleSlot; - node->ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = GetTableAmRoutine(node->ss_currentRelation->rd_tam_type); + node->ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = node->ss_currentRelation->rd_tam_ops; HeapTuple tuple = SampleFetchNextTuple(node); return ExecMakeTupleSlot(tuple, GetTableScanDesc(node->ss_currentScanDesc, node->ss_currentRelation), slot, - GetTableAmRoutine(node->ss_currentRelation->rd_tam_type)); + node->ss_currentRelation->rd_tam_ops); } TupleTableSlot* UHeapSeqSampleNext(SeqScanState* node) @@ -174,11 +174,11 @@ TupleTableSlot* HbktSeqSampleNext(SeqScanState* node) (((RowTableSample*)node->sampleScanInfo.tsm_state)->resetSampleScan)(); } - node->ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = GetTableAmRoutine(node->ss_currentRelation->rd_tam_type); + node->ss_ScanTupleSlot->tts_tupleDescriptor->td_tam_ops = node->ss_currentRelation->rd_tam_ops; return ExecMakeTupleSlot( (Tuple) tuple, GetTableScanDesc(node->ss_currentScanDesc, node->ss_currentRelation), slot, - GetTableAmRoutine(node->ss_currentRelation->rd_tam_type)); + node->ss_currentRelation->rd_tam_ops); } /* diff --git a/src/gausskernel/runtime/executor/nodeSeqscan.cpp b/src/gausskernel/runtime/executor/nodeSeqscan.cpp index cacd745f8..40b4e7bfc 100644 --- a/src/gausskernel/runtime/executor/nodeSeqscan.cpp +++ b/src/gausskernel/runtime/executor/nodeSeqscan.cpp @@ -554,8 +554,8 @@ void InitScanRelation(SeqScanState* node, EState* estate, int eflags) /* * tuple table initialization */ - ExecInitResultTupleSlot(estate, &node->ps, GetTableAmRoutine(current_relation->rd_tam_type)); - ExecInitScanTupleSlot(estate, node, GetTableAmRoutine(current_relation->rd_tam_type)); + ExecInitResultTupleSlot(estate, &node->ps, current_relation->rd_tam_ops); + ExecInitScanTupleSlot(estate, node, current_relation->rd_tam_ops); if (((Scan*)node->ps.plan)->tablesample && node->sampleScanInfo.tsm_state == NULL) { if (isUstoreRel) { @@ -743,7 +743,7 @@ static SeqScanState *ExecInitSeqScanBatchMode(SeqScan *node, SeqScanState* scans scanstate->scanBatchState = scanBatchState; scanstate->ps.subPlan = NULL; - if (scanstate->ss_currentRelation->rd_tam_type == TAM_HEAP) { + if (scanstate->ss_currentRelation->rd_tam_ops == TableAmHeap) { HeapScanDesc heapDesc = (HeapScanDesc)(scanstate->ss_currentScanDesc); heapDesc->rs_ctupBatch = (HeapTupleData*)palloc(sizeof(HeapTupleData) * BatchMaxSize); } else { @@ -755,7 +755,7 @@ static SeqScanState *ExecInitSeqScanBatchMode(SeqScan *node, SeqScanState* scans (TupleTableSlot**)palloc(sizeof(TupleTableSlot*) * BatchMaxSize); for (i = 0; i < BatchMaxSize; i++) { TupleTableSlot* slot = ExecAllocTableSlot(&estate->es_tupleTable, - GetTableAmRoutine(scanstate->ss_currentRelation->rd_tam_type)); + scanstate->ss_currentRelation->rd_tam_ops); ExecSetSlotDescriptor(slot, scanstate->ss_ScanTupleSlot->tts_tupleDescriptor); scanBatchState->scanBatch.scanTupleSlotInBatch[i] = slot; } @@ -802,12 +802,12 @@ static inline void InitSeqNextMtd(SeqScan* node, SeqScanState* scanstate) if (!node->tablesample) { scanstate->ScanNextMtd = SeqNext; if(RELATION_OWN_BUCKET(scanstate->ss_currentRelation)) { - if(scanstate->ss_currentRelation->rd_tam_type == TAM_HEAP) + if(scanstate->ss_currentRelation->rd_tam_ops == TableAmHeap) scanstate->fillNextSlotFunc = seq_scan_getnext_template; else scanstate->fillNextSlotFunc = seq_scan_getnext_template; } else { - if(scanstate->ss_currentRelation->rd_tam_type == TAM_HEAP) + if(scanstate->ss_currentRelation->rd_tam_ops == TableAmHeap) scanstate->fillNextSlotFunc = seq_scan_getnext_template; else scanstate->fillNextSlotFunc = seq_scan_getnext_template; @@ -1011,7 +1011,7 @@ SeqScanState* ExecInitSeqScan(SeqScan* node, EState* estate, int eflags) */ ExecAssignResultTypeFromTL( &scanstate->ps, - GetTableAmRoutine(scanstate->ss_currentRelation->rd_tam_type)); + scanstate->ss_currentRelation->rd_tam_ops); ExecAssignScanProjectionInfo(scanstate); @@ -1236,7 +1236,7 @@ void ExecReScanSeqScan(SeqScanState* node) scan_handler_tbl_rescan(scan, NULL, node->ss_currentRelation); } - if ((scan != NULL) && (scan->rs_rd->rd_tam_type == TAM_USTORE)) { + if ((scan != NULL) && (scan->rs_rd->rd_tam_ops == TableAmUstore)) { scan->lastVar = -1; scan->boolArr = NULL; } @@ -1344,7 +1344,7 @@ static void ExecInitNextPartitionForSeqScan(SeqScanState* node) } if (node->scanBatchMode) { - if (node->ss_currentRelation->rd_tam_type == TAM_HEAP) { + if (node->ss_currentRelation->rd_tam_ops == TableAmHeap) { HeapScanDesc heapDesc = (HeapScanDesc)node->ss_currentScanDesc; heapDesc->rs_ctupBatch = (HeapTupleData*)palloc(sizeof(HeapTupleData) * BatchMaxSize); } else { diff --git a/src/gausskernel/runtime/executor/nodeTidscan.cpp b/src/gausskernel/runtime/executor/nodeTidscan.cpp index 60535116a..cebfc50f0 100644 --- a/src/gausskernel/runtime/executor/nodeTidscan.cpp +++ b/src/gausskernel/runtime/executor/nodeTidscan.cpp @@ -625,8 +625,8 @@ TidScanState* ExecInitTidScan(TidScan* node, EState* estate, int eflags) /* * tuple table initialization */ - ExecInitResultTupleSlot(estate, &tidstate->ss.ps, GetTableAmRoutine(current_relation->rd_tam_type)); - ExecInitScanTupleSlot(estate, &tidstate->ss, GetTableAmRoutine(current_relation->rd_tam_type)); + ExecInitResultTupleSlot(estate, &tidstate->ss.ps, current_relation->rd_tam_ops); + ExecInitScanTupleSlot(estate, &tidstate->ss, current_relation->rd_tam_ops); /* deal with partitioned table branch */ if (node->scan.isPartTbl) { diff --git a/src/gausskernel/runtime/opfusion/opfusion_delete.cpp b/src/gausskernel/runtime/opfusion/opfusion_delete.cpp index df27a42fd..d0ddeb05b 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_delete.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_delete.cpp @@ -78,6 +78,7 @@ void DeleteFusion::InitGlobals() m_global->m_tupDesc = CreateTupleDescCopy(RelationGetDescr(rel)); m_global->m_is_bucket_rel = RELATION_OWN_BUCKET(rel); m_global->m_table_type = RelationIsUstoreFormat(rel) ? TAM_USTORE : TAM_HEAP; + m_global->m_tupDesc->td_tam_ops = GetTableAmRoutine(m_global->m_table_type); m_global->m_exec_func_ptr = (OpFusionExecfuncType)&DeleteFusion::ExecDelete; heap_close(rel, AccessShareLock); diff --git a/src/gausskernel/runtime/opfusion/opfusion_indexonlyscan.cpp b/src/gausskernel/runtime/opfusion/opfusion_indexonlyscan.cpp index 6d518bf0d..004b9afa8 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_indexonlyscan.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_indexonlyscan.cpp @@ -223,7 +223,7 @@ TupleTableSlot *IndexOnlyScanFusion::getTupleSlotInternal() bool bucket_changed = false; TupleTableSlot* tmpreslot = NULL; tmpreslot = MakeSingleTupleTableSlot(RelationGetDescr(m_scandesc->heapRelation), - false, GetTableAmRoutine(m_scandesc->heapRelation->rd_tam_type)); + false, m_scandesc->heapRelation->rd_tam_ops); while ((tid = scan_handler_idx_getnext_tid(m_scandesc, *m_direction, &bucket_changed)) != NULL) { HeapTuple tuple = NULL; diff --git a/src/gausskernel/runtime/opfusion/opfusion_indexscan.cpp b/src/gausskernel/runtime/opfusion/opfusion_indexscan.cpp index 51868ecb4..03fc8b244 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_indexscan.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_indexscan.cpp @@ -93,7 +93,7 @@ IndexScanFusion::IndexScanFusion(IndexScan* node, PlannedStmt* planstmt, ParamLi m_direction = (ScanDirection*)palloc0(sizeof(ScanDirection)); Relation rel = m_rel; - m_tupDesc = ExecCleanTypeFromTL(m_targetList, false, GetTableAmRoutine(rel->rd_tam_type)); + m_tupDesc = ExecCleanTypeFromTL(m_targetList, false, rel->rd_tam_ops); m_attrno = (int16*)palloc(m_tupDesc->natts * sizeof(int16)); m_values = (Datum*)palloc(RelationGetDescr(rel)->natts * sizeof(Datum)); m_tmpvals = (Datum*)palloc(m_tupDesc->natts * sizeof(Datum)); @@ -168,7 +168,7 @@ void IndexScanFusion::Init(long max_rows) } m_epq_indexqual = m_node->indexqualorig; - m_reslot = MakeSingleTupleTableSlot(m_tupDesc, false, GetTableAmRoutine(m_rel->rd_tam_type)); + m_reslot = MakeSingleTupleTableSlot(m_tupDesc, false, m_rel->rd_tam_ops); } HeapTuple IndexScanFusion::getTuple() diff --git a/src/gausskernel/runtime/opfusion/opfusion_insert.cpp b/src/gausskernel/runtime/opfusion/opfusion_insert.cpp index 369165aec..129254865 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_insert.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_insert.cpp @@ -48,6 +48,7 @@ void InsertFusion::InitGlobals() m_global->m_natts = RelationGetDescr(rel)->natts; m_global->m_is_bucket_rel = RELATION_OWN_BUCKET(rel); m_global->m_tupDesc = CreateTupleDescCopy(RelationGetDescr(rel)); + m_global->m_tupDesc->td_tam_ops = GetTableAmRoutine(m_global->m_table_type); heap_close(rel, AccessShareLock); /* init param func const */ @@ -281,7 +282,7 @@ unsigned long InsertFusion::ExecInsert(Relation rel, ResultRelInfo* result_rel_i * step 2: begin insert * ************************/ Tuple tuple = tableam_tops_form_tuple(m_global->m_tupDesc, m_local.m_values, - m_local.m_isnull, GetTableAmRoutine(rel->rd_tam_type)); + m_local.m_isnull, rel->rd_tam_ops); Assert(tuple != NULL); if (RELATION_IS_PARTITIONED(rel)) { m_c_local.m_estate->esfRelations = NULL; @@ -368,7 +369,7 @@ unsigned long InsertFusion::ExecInsert(Relation rel, ResultRelInfo* result_rel_i if (rel != NULL && rel->rd_mlogoid != InvalidOid) { /* judge whether need to insert into mlog-table */ HeapTuple htuple = NULL; - if (rel->rd_tam_type == TAM_USTORE) { + if (rel->rd_tam_ops == TableAmUstore) { htuple = UHeapToHeap(rel->rd_att, (UHeapTuple)tuple); insert_into_mlog_table(rel, rel->rd_mlogoid, htuple, &htuple->t_self, GetCurrentTransactionId(), 'I'); diff --git a/src/gausskernel/runtime/opfusion/opfusion_selectforupdate.cpp b/src/gausskernel/runtime/opfusion/opfusion_selectforupdate.cpp index cb8169637..4d3480d08 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_selectforupdate.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_selectforupdate.cpp @@ -100,9 +100,10 @@ void SelectForUpdateFusion::InitGlobals() Relation rel = heap_open(m_global->m_reloid, AccessShareLock); m_global->m_natts = RelationGetDescr(rel)->natts; Assert(list_length(targetList) >= 2); - m_global->m_tupDesc = ExecCleanTypeFromTL(targetList, false, GetTableAmRoutine(rel->rd_tam_type)); + m_global->m_tupDesc = ExecCleanTypeFromTL(targetList, false, rel->rd_tam_ops); m_global->m_is_bucket_rel = RELATION_OWN_BUCKET(rel); m_global->m_table_type = RelationIsUstoreFormat(rel) ? TAM_USTORE : TAM_HEAP; + m_global->m_tupDesc->td_tam_ops = GetTableAmRoutine(m_global->m_table_type); m_global->m_exec_func_ptr = (OpFusionExecfuncType)&SelectForUpdateFusion::ExecSelectForUpdate; heap_close(rel, AccessShareLock); @@ -253,7 +254,7 @@ unsigned long SelectForUpdateFusion::ExecSelectForUpdate(Relation rel, ResultRel } tmptup = (HeapTuple)tableam_tops_form_tuple(m_global->m_tupDesc, m_local.m_tmpvals, m_local.m_tmpisnull, - GetTableAmRoutine(rel->rd_tam_type)); + rel->rd_tam_ops); if (bucket_rel) { bucketCloseRelation(bucket_rel); } @@ -378,7 +379,7 @@ unsigned long SelectForUpdateFusion::ExecSelectForUpdate(Relation rel, ResultRel } tmptup = tableam_tops_form_tuple(m_global->m_tupDesc, m_local.m_tmpvals, m_local.m_tmpisnull, - GetTableAmRoutine(rel->rd_tam_type)); + rel->rd_tam_ops); Assert(tmptup != NULL); (void)ExecStoreTuple(tmptup, /* tuple to store */ diff --git a/src/gausskernel/runtime/opfusion/opfusion_update.cpp b/src/gausskernel/runtime/opfusion/opfusion_update.cpp index 146ef63f3..08dfa807b 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_update.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_update.cpp @@ -122,6 +122,7 @@ void UpdateFusion::InitGlobals() m_global->m_is_bucket_rel = RELATION_OWN_BUCKET(rel); m_global->m_natts = RelationGetDescr(rel)->natts; m_global->m_tupDesc = CreateTupleDescCopy(RelationGetDescr(rel)); + m_global->m_tupDesc->td_tam_ops = GetTableAmRoutine(m_global->m_table_type); hash_col_num = rel->rd_isblockchain ? 1 : 0; heap_close(rel, AccessShareLock); diff --git a/src/gausskernel/storage/access/common/heaptuple.cpp b/src/gausskernel/storage/access/common/heaptuple.cpp index 0ce5cf9fc..85fc0dc07 100644 --- a/src/gausskernel/storage/access/common/heaptuple.cpp +++ b/src/gausskernel/storage/access/common/heaptuple.cpp @@ -255,7 +255,8 @@ void heap_fill_tuple(TupleDesc tupleDesc, Datum *values, const bool *isnull, cha * heap_attisnull - returns TRUE iff tuple attribute is not present * ---------------- */ -bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupDesc) +static FORCE_INLINE +bool heap_attisnull_impl(HeapTuple tup, int attnum, TupleDesc tupDesc) { if (attnum > (int)HeapTupleHeaderGetNatts(tup->t_data, tupDesc)) { return true; @@ -291,6 +292,14 @@ bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupDesc) return false; } +bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupDesc) { + return heap_attisnull_impl(tup, attnum, tupDesc); +} + +bool heapam_attisnull(Tuple tup, int attnum, TupleDesc tuple_desc) { + return heap_attisnull_impl((HeapTuple)tup, attnum, tuple_desc); +} + /* get init default value from tupleDesc. * attrinitdefvals of tupleDesc come from the attrinitdefval of pg_attribute */ @@ -543,11 +552,13 @@ Datum nocachegetattr(HeapTuple tuple, uint32 attnum, TupleDesc tupleDesc) * has already determined that the attnum refers to a system attribute. * ---------------- */ -Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) +static FORCE_INLINE +Datum heap_getsysattr_impl(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) { Datum result; Assert(tup); + Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tup))); /* Currently, no sys attribute ever reads as NULL. */ *isnull = false; @@ -599,6 +610,14 @@ Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnu return result; } +Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) { + return heap_getsysattr_impl(tup, attnum, tupleDesc, isnull); +} + +Datum heapam_getsysattr(Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buff) { + return heap_getsysattr_impl((HeapTuple)tup, attnum, tuple_desc, isnull); +} + /* ---------------- * heap_copytuple && heapCopyCompressedTuple * @@ -616,7 +635,8 @@ Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnu * And macro HEAP_COPY_TUPLE are provided, both wrapper for uncompressed and compressed tuples. * ---------------- */ -HeapTuple heap_copytuple(HeapTuple tuple) +static FORCE_INLINE +HeapTuple heap_copytuple_impl(HeapTuple tuple) { HeapTuple newTuple; errno_t rc = EOK; @@ -684,6 +704,15 @@ void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest) securec_check(rc, "\0", "\0"); } +HeapTuple heap_copytuple(HeapTuple tuple) { + return heap_copytuple_impl(tuple); +} + +Tuple heapam_copytuple(Tuple tuple) { + Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); + return heap_copytuple((HeapTuple)tuple); +} + /* * heap_form_tuple * construct a tuple from the given values[] and isnull[] arrays, @@ -691,7 +720,8 @@ void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest) * * The result is allocated in the current memory context. */ -HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull) +static FORCE_INLINE +HeapTuple heap_form_tuple_impl(TupleDesc tupleDescriptor, Datum *values, bool *isnull) { HeapTuple tuple; /* return tuple */ HeapTupleHeader td; /* tuple data */ @@ -797,6 +827,16 @@ HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull return tuple; } +HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull) +{ + return heap_form_tuple_impl(tupleDescriptor, values, isnull); +} + +Tuple heapam_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull) +{ + return (Tuple)heap_form_tuple_impl(tupleDescriptor, values, isnull); +} + /* * heap_formtuple * @@ -838,7 +878,8 @@ HeapTuple heap_formtuple(TupleDesc tupleDescriptor, Datum *values, const char *n * * The result is allocated in the current memory context. */ -HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, const bool *replIsnull, +static FORCE_INLINE +HeapTuple heap_modify_tuple_impl(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, const bool *replIsnull, const bool *doReplace) { int numberOfAttributes = tupleDesc->natts; @@ -897,6 +938,18 @@ HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replVal return newTuple; } +HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, const bool *replIsnull, + const bool *doReplace) +{ + return heap_modify_tuple_impl(tuple, tupleDesc, replValues, replIsnull, doReplace); +} + +Tuple heapam_modify_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace) +{ + return (Tuple)heap_modify_tuple_impl((HeapTuple)tuple, tuple_desc, repl_values, repl_isnull, do_replace); +} + + /* * heap_modifytuple * @@ -947,7 +1000,8 @@ HeapTuple heap_modifytuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValu * heap_getattr; the loop will become O(N^2) as soon as any * noncacheable attribute offsets are involved. */ -void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull) +static FORCE_INLINE void +heap_deform_tuple_impl(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull) { HeapTupleHeader tup = tuple->t_data; bool hasnulls = HeapTupleHasNulls(tuple); @@ -1051,6 +1105,18 @@ void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool } } +void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull) +{ + heap_deform_tuple_impl(tuple, tupleDesc, values, isnull); +} + +void heapam_deform_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull) +{ + Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); + return heap_deform_tuple_impl((HeapTuple)tuple, tuple_desc, values, isnull); +} + + /* * heap_deformtuple * @@ -2659,7 +2725,8 @@ HeapTuple heap_form_cmprs_tuple(TupleDesc tupleDescriptor, FormCmprTupleData *cm * heap_getattr; the loop will become O(N^2) as soon as any * noncacheable attribute offsets are involved. */ -void heap_deform_cmprs_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, char *cmprsInfo) +static FORCE_INLINE void +heap_deform_cmprs_tuple_impl(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, char *cmprsInfo) { HeapTupleHeader tup = tuple->t_data; bool hasnulls = HeapTupleHasNulls(tuple); @@ -2742,7 +2809,21 @@ void heap_deform_cmprs_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values } } -void heap_deform_tuple2(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer) + +void heap_deform_cmprs_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, char *cmprsInfo) +{ + heap_deform_cmprs_tuple_impl(tuple, tupleDesc, values, isnull, cmprsInfo); +} + +void heapam_deform_cmprs_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info) +{ + Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); + heap_deform_cmprs_tuple_impl((HeapTuple)tuple, tuple_desc, values, isnull, cmprs_info); +} + + +static FORCE_INLINE void +heap_deform_tuple2_impl(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer) { Assert((tuple != NULL) && (tuple->t_data != NULL)); if (!HEAP_TUPLE_IS_COMPRESSED(tuple->t_data)) { @@ -2756,6 +2837,17 @@ void heap_deform_tuple2(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, boo heap_deform_cmprs_tuple(tuple, tupleDesc, values, isnull, (char *)getPageDict(page)); } +void heap_deform_tuple2(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer) +{ + return heap_deform_tuple2_impl(tuple, tupleDesc, values, isnull, buffer); +} + +void heapam_deform_tuple2(Tuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer) +{ + Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); + return heap_deform_tuple2_impl((HeapTuple)tuple, tupleDesc, values, isnull, buffer); +} + /* deform the passed heap tuple. * call heap_deform_tuple() if it's not compressed, * otherwise call heap_deform_cmprs_tuple(). @@ -3022,7 +3114,7 @@ void heap_slot_clear(TupleTableSlot *slot) * * @pram slot: slot to be materialized. */ -void heap_slot_materialize(TupleTableSlot *slot) +HeapTuple heap_slot_materialize(TupleTableSlot *slot) { /* * sanity checks @@ -3036,7 +3128,7 @@ void heap_slot_materialize(TupleTableSlot *slot) * nothing to do. */ if (slot->tts_tuple && TTS_SHOULDFREE(slot) && !HEAP_TUPLE_IS_COMPRESSED(((HeapTuple)slot->tts_tuple)->t_data)) - return ; + return (HeapTuple)slot->tts_tuple;; /* * Otherwise, copy or build a physical tuple, and store it into the slot. @@ -3083,6 +3175,7 @@ void heap_slot_materialize(TupleTableSlot *slot) slot->tts_dataLen = -1; } #endif + return (HeapTuple)slot->tts_tuple; } /* @@ -3331,11 +3424,12 @@ HeapTuple heap_slot_copy_heap_tuple(TupleTableSlot *slot) * @param slot: slot to store tuple. * @param: should_free true if clear the slot's tuple contents by pfree_ext() during ExecClearTuple. */ -void heap_slot_store_heap_tuple(HeapTuple tuple, TupleTableSlot* slot, Buffer buffer, bool should_free, bool batchMode) +void heap_slot_store_heap_tuple(Tuple tup, TupleTableSlot* slot, Buffer buffer, bool should_free, bool batchMode) { /* * sanity checks */ + HeapTuple tuple = HeapTuple(tup); Assert(tuple != NULL); Assert(slot != NULL); Assert(slot->tts_tupleDescriptor != NULL); diff --git a/src/gausskernel/storage/access/heap/heapam.cpp b/src/gausskernel/storage/access/heap/heapam.cpp index 317e27250..14c6b0659 100755 --- a/src/gausskernel/storage/access/heap/heapam.cpp +++ b/src/gausskernel/storage/access/heap/heapam.cpp @@ -4129,7 +4129,7 @@ int heap_multi_insert(Relation relation, Relation parent, HeapTuple* tuples, int /* try to insert tuple into mlog-table. */ if (relation != NULL && relation->rd_mlogoid != InvalidOid) { /* judge whether need to insert into mlog-table */ - if (relation->rd_tam_type == TAM_USTORE) { + if (relation->rd_tam_ops == TableAmUstore) { heaptup = UHeapToHeap(relation->rd_att, (UHeapTuple)heaptup); } insert_into_mlog_table(relation, relation->rd_mlogoid, diff --git a/src/gausskernel/storage/access/index/indexam.cpp b/src/gausskernel/storage/access/index/indexam.cpp index ebd4ad3ec..c6527202a 100644 --- a/src/gausskernel/storage/access/index/indexam.cpp +++ b/src/gausskernel/storage/access/index/indexam.cpp @@ -767,7 +767,7 @@ bool IndexGetnextSlot(IndexScanDesc scan, ScanDirection direction, TupleTableSlo ItemPointer tid; TupleTableSlot* tmpslot = NULL; tmpslot = MakeSingleTupleTableSlot(RelationGetDescr(scan->heapRelation), - false, GetTableAmRoutine(scan->heapRelation->rd_tam_type)); + false, scan->heapRelation->rd_tam_ops); for (;;) { /* IO collector and IO scheduler */ #ifdef ENABLE_MULTIPLE_NODES diff --git a/src/gausskernel/storage/access/nbtree/nbtsort.cpp b/src/gausskernel/storage/access/nbtree/nbtsort.cpp index 021a343b5..729fa7085 100644 --- a/src/gausskernel/storage/access/nbtree/nbtsort.cpp +++ b/src/gausskernel/storage/access/nbtree/nbtsort.cpp @@ -1381,7 +1381,7 @@ static void _bt_parallel_scan_and_sort(BTSpool *btspool, BTSpool *btspool2, BTSh indexInfo->ii_Concurrent = false; /* do the heap scan */ - IndexBuildCallback callback = (btspool->heap->rd_tam_type == TAM_USTORE)? UBTreeBuildCallback : btbuildCallback; + IndexBuildCallback callback = (btspool->heap->rd_tam_ops == TableAmUstore)? UBTreeBuildCallback : btbuildCallback; if (btshared->isplain) { /* plain table or partition */ scan = tableam_scan_begin_parallel(btspool->heap, &btshared->heapdesc); @@ -1555,7 +1555,7 @@ static double _bt_spools_heapscan_utility(Relation heap, Relation index, BTBuil /* Fill spool using either serial or parallel heap scan */ if (!buildstate->btleader) { serial_build: - IndexBuildCallback callback = (heap->rd_tam_type == TAM_USTORE)? UBTreeBuildCallback : btbuildCallback; + IndexBuildCallback callback = (heap->rd_tam_ops == TableAmUstore)? UBTreeBuildCallback : btbuildCallback; if (RelationIsGlobalIndex(index)) { *allPartTuples = GlobalIndexBuildHeapScan(heap, index, indexInfo, callback, (void *)buildstate); } else if (RelationIsCrossBucketIndex(index)) { diff --git a/src/gausskernel/storage/access/table/tableam.cpp b/src/gausskernel/storage/access/table/tableam.cpp index 78c917bf5..f2b7029a8 100644 --- a/src/gausskernel/storage/access/table/tableam.cpp +++ b/src/gausskernel/storage/access/table/tableam.cpp @@ -51,192 +51,12 @@ #include "access/ustore/knl_utuple.h" #include "access/ustore/knl_uvisibility.h" -bool tableam_tops_page_get_item(Relation rel, Tuple tuple, Page page, - OffsetNumber tupleNo, BlockNumber destBlocks) -{ - return g_tableam_routines[rel->rd_tam_type]->tops_page_get_item(rel, tuple, page, tupleNo, destBlocks); -} -OffsetNumber tableam_tops_page_get_max_offsetnumber(Relation rel, Page page) -{ - return g_tableam_routines[rel->rd_tam_type]->tops_page_get_max_offsetnumber(page); -} -Size tableam_tops_page_get_freespace(Relation rel, Page page) -{ - return g_tableam_routines[rel->rd_tam_type]->tops_page_get_freespace(page); -} -bool tableam_tops_tuple_fetch_row_version(TidScanState* node, Relation relation, ItemPointer tid, - Snapshot snapshot, TupleTableSlot *slot) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_tuple_fetch_row_version(node, relation, tid, snapshot, slot); -} - -Tuple tableam_tops_copy_tuple(Tuple tuple) -{ - AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_copy_tuple(tuple); -} - -MinimalTuple tableam_tops_copy_minimal_tuple(MinimalTuple mtup) -{ - return heap_copy_minimal_tuple(mtup); -} - -void tableam_tops_free_minimal_tuple(MinimalTuple mtup) -{ - heap_free_minimal_tuple(mtup); -} - -Tuple tableam_tops_new_tuple(Relation relation, ItemPointer tid) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_new_tuple(relation, tid); -} - -TransactionId tableam_tops_get_conflictXid(Relation relation, Tuple tup) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_get_conflictXid(tup); -} - -void tableam_tops_destroy_tuple(Relation relation, Tuple tuple) -{ - g_tableam_routines[relation->rd_tam_type]->tops_destroy_tuple(tuple); -} - -void tableam_tops_add_to_bulk_insert_select(Relation relation, CopyFromBulk bulk, Tuple tup, - bool needCopy) -{ - g_tableam_routines[relation->rd_tam_type]->tops_add_to_bulk_insert_select(bulk, tup, needCopy); -} - -void tableam_tops_add_to_bulk(Relation relation, - CopyFromBulk bulk, Tuple tup, bool needCopy) -{ - g_tableam_routines[relation->rd_tam_type]->tops_add_to_bulk(bulk, tup, needCopy); -} - -ItemPointer tableam_tops_get_t_self(Relation relation, Tuple tup) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_get_t_self(tup); -} - -void tableam_tops_exec_delete_index_tuples(TupleTableSlot *slot, Relation relation, - ModifyTableState *node, ItemPointer tupleid, ExecIndexTuplesState exec_index_tuples_state, - Bitmapset *modifiedIdxAttrs) -{ - g_tableam_routines[relation->rd_tam_type]->tops_exec_delete_index_tuples(slot, relation, node, tupleid, - exec_index_tuples_state, modifiedIdxAttrs); -} - -List *tableam_tops_exec_update_index_tuples(TupleTableSlot *slot, TupleTableSlot *oldslot, - Relation relation, ModifyTableState *node, Tuple tuple, ItemPointer tupleid, - ExecIndexTuplesState exec_index_tuples_state, int2 bucketid, Bitmapset *modifiedIdxAttrs) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_exec_update_index_tuples(slot, oldslot, relation, node, - tuple, tupleid, exec_index_tuples_state, bucketid, modifiedIdxAttrs); -} - -uint32 tableam_tops_get_tuple_type(Relation relation) -{ - return g_tableam_routines[relation->rd_tam_type]->tops_get_tuple_type(); -} - -void tableam_tops_copy_from_insert_batch(Relation rel, EState* estate, CommandId mycid, int hiOptions, - ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, BulkInsertState bistate, int nBufferedTuples, - Tuple* bufferedTuples, Partition partition, int2 bucketId) -{ - g_tableam_routines[rel->rd_tam_type]->tops_copy_from_insert_batch(rel, estate, mycid, hiOptions, resultRelInfo, - myslot, bistate, nBufferedTuples, bufferedTuples, partition, bucketId); -} - -void tableam_tops_update_tuple_with_oid(Relation relation, Tuple tup, TupleTableSlot *slot) -{ - g_tableam_routines[relation->rd_tam_type]->tops_update_tuple_with_oid(relation, tup, slot); -} - -Datum HeapamTopsTupleFastGetattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool *is_null) +static Datum heapam_fastgetattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool *is_null) { + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); return fastgetattr((HeapTuple)tuple, att_num, tuple_desc, is_null); } -/* ------------------------------------------------------------------------ - * DQL AM APIs - * ------------------------------------------------------------------------ - */ -bool tableam_tuple_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, - bool keep_buf, Relation stats_relation) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_fetch(relation, snapshot, tuple, userbuf, keep_buf, - stats_relation); -} - -bool tableam_tuple_satisfies_snapshot(Relation relation, HeapTuple tuple, Snapshot snapshot, - Buffer buffer) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_satisfies_snapshot(relation, tuple, snapshot, buffer); -} - -void tableam_tuple_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_get_latest_tid(relation, snapshot, tid); -} - -Oid tableam_tuple_insert(Relation relation, Tuple tup, CommandId cid, int options, - struct BulkInsertStateData *bistate) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_insert(relation, tup, cid, options, bistate); -} - -int tableam_tuple_multi_insert(Relation relation, Relation parent, Tuple *tuples, int ntuples, - CommandId cid, int options, struct BulkInsertStateData *bistate, HeapMultiInsertExtraArgs *args) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_multi_insert(relation, parent, tuples, ntuples, cid, - options, bistate, args); -} - -TM_Result tableam_tuple_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, - Snapshot snapshot, bool wait, TupleTableSlot **oldslot, TM_FailureData *tmfd, bool allow_delete_self) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_delete(relation, tid, cid, crosscheck, snapshot, wait, - oldslot, tmfd, allow_delete_self); -} - - -TM_Result tableam_tuple_update(Relation relation, Relation parentRelation, ItemPointer otid, Tuple newtup, - CommandId cid, Snapshot crosscheck, Snapshot snapshot, bool wait, TupleTableSlot **oldslot, TM_FailureData *tmfd, - bool *update_indexes, Bitmapset **modifiedIdxAttrs, bool allow_update_self, - bool allow_inplace_update, LockTupleMode *lockmode) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_update(relation, parentRelation, otid, newtup, cid, - crosscheck, snapshot, wait, oldslot, tmfd, lockmode, update_indexes, modifiedIdxAttrs, allow_update_self, - allow_inplace_update); -} - -TM_Result tableam_tuple_lock(Relation relation, Tuple tuple, Buffer *buffer, CommandId cid, - LockTupleMode mode, LockWaitPolicy waitPolicy, TM_FailureData *tmfd, bool allow_lock_self, bool follow_updates, bool eval, - Snapshot snapshot, ItemPointer tid, bool isSelectForUpdate, bool isUpsert, TransactionId conflictXid, - int waitSec) -{ - return g_tableam_routines[relation->rd_tam_type]->tuple_lock(relation, tuple, buffer, cid, mode, waitPolicy, tmfd, - allow_lock_self, follow_updates, eval, snapshot, tid, isSelectForUpdate, isUpsert, conflictXid, - waitSec); -} - -Tuple tableam_tuple_lock_updated(CommandId cid, Relation relation, int lockmode, ItemPointer tid, - TransactionId priorXmax, Snapshot snapshot, bool isSelectForUpdate) -{ - return (Tuple)g_tableam_routines[relation->rd_tam_type]->tuple_lock_updated(cid, relation, lockmode, tid, priorXmax, - snapshot, isSelectForUpdate); -} - -void tableam_tuple_check_visible(Relation relation, Snapshot snapshot, Tuple tuple, Buffer buffer) -{ - g_tableam_routines[relation->rd_tam_type]->tuple_check_visible(snapshot, tuple, buffer); -} - -void tableam_tuple_abort_speculative(Relation relation, Tuple tuple) -{ - g_tableam_routines[relation->rd_tam_type]->tuple_abort_speculative(relation, tuple); -} - /* ----------------------------------------------------------------------- * SCAN AM APIS FOR HEAP * ------------------------------------------------------------------------ @@ -247,114 +67,11 @@ IndexFetchTableData *tableam_scan_index_fetch_begin(Relation rel) return HeapamScanIndexFetchBegin(rel); } -void tableam_scan_index_fetch_reset(IndexFetchTableData *scan) -{ - heapam_index_fetch_reset(scan); -} - void tableam_scan_index_fetch_end(IndexFetchTableData *scan) { HeapamScanIndexFetchEnd(scan); } -Tuple tableam_scan_index_fetch_tuple(IndexScanDesc scan, bool *all_dead, bool* has_cur_xact_write) -{ - return g_tableam_routines[scan->heapRelation->rd_tam_type]->scan_index_fetch_tuple(scan, all_dead, - has_cur_xact_write); -} - -TableScanDesc tableam_scan_begin(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, - RangeScanInRedis rangeScanInRedis) -{ - return g_tableam_routines[relation->rd_tam_type]->scan_begin(relation, snapshot, nkeys, key, rangeScanInRedis); -} - -TableScanDesc tableam_scan_begin_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key) -{ - return g_tableam_routines[relation->rd_tam_type]->scan_begin_bm(relation, snapshot, nkeys, key); -} - -TableScanDesc tableam_scan_begin_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, - bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis) -{ - return g_tableam_routines[relation->rd_tam_type]->scan_begin_sampling(relation, snapshot, nkeys, key, allow_strat, - allow_sync, rangeScanInRedis); -} - - -TableScanDesc tableam_scan_begin_parallel(Relation relation, ParallelHeapScanDesc parallel_scan) -{ - return g_tableam_routines[relation->rd_tam_type]->scan_begin_parallel(relation, parallel_scan); -} - -Tuple tableam_scan_getnexttuple(TableScanDesc sscan, ScanDirection direction, bool* has_cur_xact_write) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getnexttuple(sscan, direction, has_cur_xact_write); -} - -bool tableam_scan_gettuplebatchmode(TableScanDesc sscan, ScanDirection direction) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_GetNextBatch(sscan, direction); -} - -void tableam_scan_getpage(TableScanDesc sscan, BlockNumber page) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_getpage(sscan, page); -} - -Tuple tableam_scan_gettuple_for_verify(TableScanDesc sscan, ScanDirection direction, bool isValidRelationPage) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_gettuple_for_verify(sscan, - direction, isValidRelationPage); -} - -void tableam_scan_end(TableScanDesc sscan) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_end(sscan); -} - -void tableam_scan_rescan(TableScanDesc sscan, ScanKey key) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_rescan(sscan, key); -} - -void tableam_scan_restrpos(TableScanDesc sscan) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_restrpos(sscan); -} - -void tableam_scan_markpos(TableScanDesc sscan) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_markpos(sscan); -} - -void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir) -{ - return g_tableam_routines[sscan->rs_rd->rd_tam_type]->scan_init_parallel_seqscan(sscan, dop, dir); -} - -double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan) -{ - return g_tableam_routines[heapRelation->rd_tam_type]->index_build_scan(heapRelation, indexRelation, indexInfo, - allow_sync, callback, callback_state, scan); -} - - -void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - Snapshot snapshot, v_i_state *state) -{ - return g_tableam_routines[heapRelation->rd_tam_type]->index_validate_scan(heapRelation, indexRelation, indexInfo, - snapshot, state); -} - -double tableam_relation_copy_for_cluster(Relation OldHeap, Relation OldIndex, Relation NewHeap, - TransactionId OldestXmin, TransactionId FreezeXid, bool verbose, bool use_sort, AdaptMem *memUsage) -{ - return g_tableam_routines[OldHeap->rd_tam_type]->relation_copy_for_cluster(OldHeap, OldIndex, NewHeap, OldestXmin, - FreezeXid, verbose, use_sort, memUsage); -} - /* * Implementation of heap accessor methods. */ @@ -364,7 +81,7 @@ Datum HeapamTopsGetsysattr(Tuple tup, int attnum, TupleDesc tuple_desc, bool* is return heap_getsysattr((HeapTuple)tup, attnum, tuple_desc, isnull); } -Datum HeapamTopsTupleGetattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null) +static Datum heapam_getattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool* is_null) { return heap_getattr((HeapTuple)tuple, att_num, tuple_desc, is_null); } @@ -374,7 +91,7 @@ bool HeapamTopsTupleAttisnull(Tuple tup, int attnum, TupleDesc tuple_desc) return heap_attisnull((HeapTuple)tup, attnum, tuple_desc); } -bool HeapamTopsPageGetItem(Relation rel, Tuple tuple, Page page, OffsetNumber tupleNo, BlockNumber destBlocks) +static bool HeapamTopsPageGetItem(Relation rel, Tuple tuple, Page page, OffsetNumber tupleNo, BlockNumber destBlocks) { HeapTupleHeader tupleHeader = NULL; ItemId tupleItem = NULL; @@ -394,13 +111,7 @@ bool HeapamTopsPageGetItem(Relation rel, Tuple tuple, Page page, OffsetNumber tu return true; } -Tuple HeapamTopsCopyTuple(Tuple tuple) -{ - Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); - return heap_copytuple((HeapTuple)tuple); -} - -Tuple HeapamTopsNewTuple(Relation relation, ItemPointer tid) +static Tuple HeapamTopsNewTuple(Relation relation, ItemPointer tid) { HeapTuple tuple = heaptup_alloc(HEAPTUPLESIZE); tuple->t_data = NULL; @@ -410,12 +121,12 @@ Tuple HeapamTopsNewTuple(Relation relation, ItemPointer tid) return (Tuple)tuple; } -TransactionId HeapamTopsGetConflictXid(Tuple tup) +static TransactionId HeapamTopsGetConflictXid(Tuple tup) { return InvalidTransactionId; } -void HeapamTopsDestroyTuple(Tuple tuple) +static void HeapamTopsDestroyTuple(Tuple tuple) { HeapTuple tup = (HeapTuple)tuple; if (tup->tupInfo == 1) { @@ -424,27 +135,17 @@ void HeapamTopsDestroyTuple(Tuple tuple) pfree_ext(tup); } -void HeapamTopsAddToBulkInsertSelect(CopyFromBulk bulk, Tuple tup, bool needCopy) -{ - HeapAddToBulkInsertSelect(bulk, tup, needCopy); -} - -void HeapamTopsAddToBulk(CopyFromBulk bulk, Tuple tup, bool needCopy) -{ - HeapAddToBulk(bulk, tup, needCopy); -} - -void HeapamTopsUpdateTupleWithOid (Relation rel, Tuple tuple, TupleTableSlot *slot) +static void HeapamTopsUpdateTupleWithOid (Relation rel, Tuple tuple, TupleTableSlot *slot) { return; } -ItemPointer HeapamTopsGetTSelf(Tuple tup) +static ItemPointer HeapamTopsGetTSelf(Tuple tup) { return &(((HeapTuple)tup)->t_self); } -void HeapamTopsExecDeleteIndexTuples(TupleTableSlot *slot, Relation relation, ModifyTableState *node, +static void HeapamTopsExecDeleteIndexTuples(TupleTableSlot *slot, Relation relation, ModifyTableState *node, ItemPointer tupleid, ExecIndexTuplesState exec_index_tuples_state, Bitmapset *modifiedIdxAttrs) { return; @@ -464,7 +165,7 @@ List *HeapamTopsExecUpdateIndexTuples(TupleTableSlot *slot, TupleTableSlot *olds return recheckIndexes; } -uint32 HeapamTopsGetTupleType() +static uint32 HeapamTopsGetTupleType() { return HEAP_TUPLE; } @@ -477,132 +178,7 @@ void HeapamTopsCopyFromInsertBatch(Relation rel, EState* estate, CommandId mycid (HeapTuple*) bufferedTuples, partition, bucketId); } -/* - * Clears the contents of the table slot that contains heap table tuple data. - */ -void HeapamTslotClear(TupleTableSlot *slot) -{ - return heap_slot_clear(slot); -} - -HeapTuple HeapamTslotMaterialize(TupleTableSlot *slot) -{ - heap_slot_materialize(slot); - return (HeapTuple)slot->tts_tuple; -} - -MinimalTuple HeapamTslotGetMinimalTuple(TupleTableSlot *slot) -{ - return heap_slot_get_minimal_tuple(slot); -} - -MinimalTuple HeapamTslotCopyMinimalTuple(TupleTableSlot *slot) -{ - return heap_slot_copy_minimal_tuple(slot); -} - -void HeapamTslotStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree) -{ - heap_slot_store_minimal_tuple(mtup, slot, shouldFree); -} - -HeapTuple HeapamTslotGetHeapTuple(TupleTableSlot* slot) -{ - return heap_slot_get_heap_tuple(slot); -} - -HeapTuple HeapamTslotCopyHeapTuple(TupleTableSlot *slot) -{ - return heap_slot_copy_heap_tuple(slot); -} - -void HeapamTslotStoreHeapTuple(Tuple tuple, TupleTableSlot* slot, Buffer buffer, bool shouldFree, bool batchMode) -{ - heap_slot_store_heap_tuple((HeapTuple)tuple, slot, buffer, shouldFree, batchMode); -} - -void HeapamTslotGetsomeattrs(TupleTableSlot *slot, int natts) -{ - heap_slot_getsomeattrs(slot, natts); -} - -void HeapamTslotFormBatch(TupleTableSlot *slot, VectorBatch* batch, int cur_rows, int natts) -{ - heap_slot_formbatch(slot, batch, cur_rows, natts); -} - -Datum HeapamTslotGetattr(TupleTableSlot* slot, int attnum, bool* isnull) -{ - return heap_slot_getattr(slot, attnum, isnull); -} - -void HeapamTslotGetallattrs(TupleTableSlot* slot) -{ - heap_slot_getallattrs(slot); -} - -bool HeapamTslotAttisnull(TupleTableSlot* slot, int attnum) -{ - return heap_slot_attisnull(slot, attnum); -} - -FORCE_INLINE Tuple HeapamTslotGetTupleFromSlot(TupleTableSlot* slot) -{ - HeapTuple tuple = ExecMaterializeSlot(slot); - tuple->tupInfo = 0; - return (Tuple) tuple; -} - -/* ------------------------------------------------------------------------ - * TABLE TUPLE AM APIs - * ------------------------------------------------------------------------ - */ - -MinimalTuple HeapamTopsFormMinimalTuple( - TupleDesc tuple_descriptor, Datum* values, const bool* isnull, MinimalTuple in_tuple) -{ - return heap_form_minimal_tuple(tuple_descriptor, values, isnull, in_tuple); -} - -Tuple HeapamTopsFormTuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull) -{ - return (Tuple)heap_form_tuple(tuple_descriptor, values, isnull); -} - -HeapTuple HeapamTopsFormCmprsTuple(TupleDesc tuple_descriptor, FormCmprTupleData* cmprs_info) -{ - return heap_form_cmprs_tuple(tuple_descriptor, cmprs_info); -} - -void HeapamTopsDeformTuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull) -{ - Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); - return heap_deform_tuple((HeapTuple)tuple, tuple_desc, values, isnull); -} - -void HeapamTopsDeformTuple2(Tuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer) -{ - Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); - return heap_deform_tuple2((HeapTuple)tuple, tupleDesc, values, isnull, buffer); -} - -void HeapamTopsDeformCmprsTuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info) -{ - Assert(TUPLE_IS_HEAP_TUPLE(HeapTuple(tuple))); - heap_deform_cmprs_tuple((HeapTuple)tuple, tuple_desc, values, isnull, cmprs_info); -} - -void HeapamTopsFillTuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit) -{ - heap_fill_tuple(tuple_desc, values, isnull, data, data_size, infomask, bit); -} - -Tuple HeapamTopsModifyTuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace) -{ - return (Tuple)heap_modify_tuple((HeapTuple)tuple, tuple_desc, repl_values, repl_isnull, do_replace); -} - -Tuple HeapamTopsOpFusionModifyTuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, +Tuple heapam_opfusion_modify_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, bool* repl_isnull, UpdateFusion* opf) { Tuple newTuple; @@ -856,45 +432,45 @@ static const TableAmRoutine g_heapam_methods = { * TABLE SLOT AM APIs * ------------------------------------------------------------------------ */ - tslot_clear : HeapamTslotClear, - tslot_materialize : HeapamTslotMaterialize, - tslot_get_minimal_tuple : HeapamTslotGetMinimalTuple, - tslot_copy_minimal_tuple : HeapamTslotCopyMinimalTuple, - tslot_store_minimal_tuple : HeapamTslotStoreMinimalTuple, - tslot_get_heap_tuple : HeapamTslotGetHeapTuple, - tslot_copy_heap_tuple : HeapamTslotCopyHeapTuple, - tslot_store_tuple : HeapamTslotStoreHeapTuple, - tslot_getsomeattrs : HeapamTslotGetsomeattrs, - tslot_formbatch : HeapamTslotFormBatch, - tslot_getattr : HeapamTslotGetattr, - tslot_getallattrs : HeapamTslotGetallattrs, - tslot_attisnull : HeapamTslotAttisnull, - tslot_get_tuple_from_slot : HeapamTslotGetTupleFromSlot, + tslot_clear : heap_slot_clear, + tslot_materialize : heap_slot_materialize, + tslot_get_minimal_tuple : heap_slot_get_minimal_tuple, + tslot_copy_minimal_tuple : heap_slot_copy_minimal_tuple, + tslot_store_minimal_tuple : heap_slot_store_minimal_tuple, + tslot_get_heap_tuple : heap_slot_get_heap_tuple, + tslot_copy_heap_tuple : heap_slot_copy_heap_tuple, + tslot_store_tuple : heap_slot_store_heap_tuple, + tslot_getsomeattrs : heap_slot_getsomeattrs, + tslot_formbatch : heap_slot_formbatch, + tslot_getattr : heap_slot_getattr, + tslot_getallattrs : heap_slot_getallattrs, + tslot_attisnull : heap_slot_attisnull, + tslot_get_tuple_from_slot : heap_slot_get_tuple_from_slot, /* ------------------------------------------------------------------------ * TABLE TUPLE AM APIs * ------------------------------------------------------------------------ */ - tops_getsysattr : HeapamTopsGetsysattr, - tops_form_minimal_tuple : HeapamTopsFormMinimalTuple, - tops_form_tuple : HeapamTopsFormTuple, - tops_form_cmprs_tuple : HeapamTopsFormCmprsTuple, - tops_deform_tuple : HeapamTopsDeformTuple, - tops_deform_tuple2 : HeapamTopsDeformTuple2, - tops_deform_cmprs_tuple : HeapamTopsDeformCmprsTuple, - tops_fill_tuple : HeapamTopsFillTuple, - tops_modify_tuple : HeapamTopsModifyTuple, - tops_opfusion_modify_tuple : HeapamTopsOpFusionModifyTuple, - tops_tuple_getattr : HeapamTopsTupleGetattr, - tops_tuple_fast_getattr : HeapamTopsTupleFastGetattr, - tops_tuple_attisnull : HeapamTopsTupleAttisnull, - tops_copy_tuple : HeapamTopsCopyTuple, + tops_getsysattr : heapam_getsysattr, + tops_form_minimal_tuple : heap_form_minimal_tuple, + tops_form_tuple : heapam_form_tuple, + tops_form_cmprs_tuple : heap_form_cmprs_tuple, + tops_deform_tuple : heapam_deform_tuple, + tops_deform_tuple2 : heapam_deform_tuple2, + tops_deform_cmprs_tuple : heapam_deform_cmprs_tuple, + tops_fill_tuple : heap_fill_tuple, + tops_modify_tuple : heapam_modify_tuple, + tops_opfusion_modify_tuple : heapam_opfusion_modify_tuple, + tops_tuple_getattr : heapam_getattr, + tops_tuple_fast_getattr : heapam_fastgetattr, + tops_tuple_attisnull : heapam_attisnull, + tops_copy_tuple : heapam_copytuple, tops_new_tuple : HeapamTopsNewTuple, tops_get_conflictXid : HeapamTopsGetConflictXid, tops_destroy_tuple : HeapamTopsDestroyTuple, - tops_add_to_bulk_insert_select : HeapamTopsAddToBulkInsertSelect, - tops_add_to_bulk : HeapamTopsAddToBulk, + tops_add_to_bulk_insert_select : HeapAddToBulkInsertSelect, + tops_add_to_bulk : HeapAddToBulk, tops_update_tuple_with_oid : HeapamTopsUpdateTupleWithOid, tops_get_t_self : HeapamTopsGetTSelf, tops_exec_delete_index_tuples : HeapamTopsExecDeleteIndexTuples, @@ -1020,7 +596,7 @@ void UHeapamTslotGetsomeattrs(TupleTableSlot *slot, int natts) UHeapSlotGetSomeAttrs(slot, natts); } -void UHeapamTslotGetallattrs(TupleTableSlot *slot) +void UHeapamTslotGetallattrs(TupleTableSlot *slot, bool need_transform_anyarray) { UHeapSlotGetAllAttrs(slot); } @@ -1030,7 +606,7 @@ void UHeapamTslotFormBatch(TupleTableSlot *slot, VectorBatch* batch, int cur_row UHeapSlotFormBatch(slot, batch, cur_rows, natts); } -Datum UHeapamTslotGetattr(TupleTableSlot *slot, int attnum, bool *isnull) +Datum UHeapamTslotGetattr(TupleTableSlot *slot, int attnum, bool *isnull, bool need_transform_anyarray) { return UHeapSlotGetAttr(slot, attnum, isnull); } @@ -1587,7 +1163,7 @@ static const TableAmRoutine g_ustoream_methods = { tops_deform_tuple : UHeapamTopsDeformTuple, tops_deform_tuple2 : UHeapamTopsDeformTuple2, tops_deform_cmprs_tuple : UHeapamTopsDeformCmprsTuple, /* Not implemented yet */ - tops_fill_tuple : HeapamTopsFillTuple, /* Not implemented yet */ + tops_fill_tuple : heap_fill_tuple, /* Not implemented yet */ tops_modify_tuple : UHeapamTopsModifyTuple, tops_opfusion_modify_tuple : UHeapamTopsOpFusionModifyTuple, tops_tuple_getattr : UHeapamTopsTupleGetattr, @@ -1673,4 +1249,4 @@ const TableAmRoutine * const g_tableam_routines[] = { }; const TableAmRoutine* TableAmHeap = &g_heapam_methods; -const TableAmRoutine* TableAmUstore = &g_ustoream_methods; \ No newline at end of file +const TableAmRoutine* TableAmUstore = &g_ustoream_methods; diff --git a/src/gausskernel/storage/access/ustore/knl_uscan.cpp b/src/gausskernel/storage/access/ustore/knl_uscan.cpp index 471e0ef2e..ced4067b3 100644 --- a/src/gausskernel/storage/access/ustore/knl_uscan.cpp +++ b/src/gausskernel/storage/access/ustore/knl_uscan.cpp @@ -738,7 +738,7 @@ static void UHeapinitscan(TableScanDesc sscan, ScanKey key, bool isRescan) scan->rs_base.rs_cbuf = InvalidBuffer; scan->rs_base.rs_cblock = InvalidBlockNumber; - if (scan->rs_base.rs_rd->rd_tam_type == TAM_USTORE) { + if (scan->rs_base.rs_rd->rd_tam_ops == TableAmUstore) { scan->rs_base.lastVar = -1; scan->rs_base.boolArr = NULL; } diff --git a/src/gausskernel/storage/access/ustore/knl_utuptoaster.cpp b/src/gausskernel/storage/access/ustore/knl_utuptoaster.cpp index 079060bff..efd6613e3 100644 --- a/src/gausskernel/storage/access/ustore/knl_utuptoaster.cpp +++ b/src/gausskernel/storage/access/ustore/knl_utuptoaster.cpp @@ -57,7 +57,7 @@ Oid UHeapGetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn ScanKeyData key; bool collides = false; Assert(RelationIsUstoreFormat(relation) || RelationIsToast(relation)); - TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(relation), false, GetTableAmRoutine(relation->rd_tam_type)); + TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(relation), false, relation->rd_tam_ops); /* Generate new OIDs until we find one not in the table */ do { CHECK_FOR_INTERRUPTS(); @@ -898,7 +898,7 @@ static void UHeapToastDeleteDatum(Relation rel, Datum value, int options) /* The toast table of ustore table should also be of ustore type */ Assert(RelationIsUstoreFormat(toastrel)); /* should index must be ustore format ? */ - TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, GetTableAmRoutine(toastrel->rd_tam_type)); + TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, toastrel->rd_tam_ops); /* * Setup a scan key to find chunks with matching va_valueid @@ -961,7 +961,7 @@ struct varlena *UHeapInternalToastFetchDatum(struct varatt_external toastPointer SET_VARSIZE(result, ressize + VARHDRSZ); toastTupDesc = toastrel->rd_att; - TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, GetTableAmRoutine(toastrel->rd_tam_type)); + TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, toastrel->rd_tam_ops); /* * Setup a scan key to fetch from the index by va_valueid @@ -1133,7 +1133,7 @@ struct varlena *UHeapInternalToastFetchDatumSlice(struct varatt_external toastPo * Open the toast relation and its index */ toastTupDesc = toastrel->rd_att; - TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, GetTableAmRoutine(toastrel->rd_tam_type)); + TupleTableSlot *slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, toastrel->rd_tam_ops); /* * Setup a scan key to fetch from the index. This is either two keys or @@ -1268,7 +1268,7 @@ static bool UHeapToastRelValueidExists(Relation toastrel, Oid valueid) SysScanDesc toastscan; TupleTableSlot *slot = NULL; Assert(RelationIsUstoreFormat(toastrel)); - slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, GetTableAmRoutine(toastrel->rd_tam_type)); + slot = MakeSingleTupleTableSlot(RelationGetDescr(toastrel), false, toastrel->rd_tam_ops); /* * Setup a scan key to find chunks with matching va_valueid diff --git a/src/gausskernel/storage/replication/logical/worker.cpp b/src/gausskernel/storage/replication/logical/worker.cpp index 105d3cba5..e7dea482b 100644 --- a/src/gausskernel/storage/replication/logical/worker.cpp +++ b/src/gausskernel/storage/replication/logical/worker.cpp @@ -201,7 +201,7 @@ static EState *create_estate_for_relation(LogicalRepRelMapEntry *rel) /* Triggers might need a slot */ if (resultRelInfo->ri_TrigDesc) - estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); /* Prepare to catch AFTER triggers. */ AfterTriggerBeginQuery(); @@ -598,7 +598,7 @@ static void apply_handle_insert(StringInfo s) /* Initialize the executor state. */ estate = create_estate_for_relation(rel); - remoteslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + remoteslot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); ExecSetSlotDescriptor(remoteslot, RelationGetDescr(rel->localrel)); /* Input functions may need an active snapshot, so get one */ @@ -724,9 +724,9 @@ static void apply_handle_update(StringInfo s) /* Initialize the executor state. */ estate = create_estate_for_relation(rel); - remoteslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + remoteslot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); ExecSetSlotDescriptor(remoteslot, RelationGetDescr(rel->localrel)); - localslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + localslot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); ExecSetSlotDescriptor(localslot, RelationGetDescr(rel->localrel)); EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1); @@ -842,9 +842,9 @@ static void apply_handle_delete(StringInfo s) /* Initialize the executor state. */ estate = create_estate_for_relation(rel); - remoteslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + remoteslot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); ExecSetSlotDescriptor(remoteslot, RelationGetDescr(rel->localrel)); - localslot = ExecInitExtraTupleSlot(estate, GetTableAmRoutine(rel->localrel->rd_tam_type)); + localslot = ExecInitExtraTupleSlot(estate, rel->localrel->rd_tam_ops); ExecSetSlotDescriptor(localslot, RelationGetDescr(rel->localrel)); EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1); diff --git a/src/gausskernel/storage/tcap/tcap_drop.cpp b/src/gausskernel/storage/tcap/tcap_drop.cpp index 3d4b43214..6da5d8cee 100644 --- a/src/gausskernel/storage/tcap/tcap_drop.cpp +++ b/src/gausskernel/storage/tcap/tcap_drop.cpp @@ -1320,7 +1320,7 @@ void TrRestoreDrop(const TimeCapsuleStmt *stmt) if (desc.relid != 0 && (desc.type == RB_OBJ_TABLE)) { stmt->relation->relname = desc.name; rel = heap_openrv(stmt->relation, AccessExclusiveLock); - if (rel->rd_tam_type == TAM_HEAP) { + if (rel->rd_tam_ops == TableAmHeap) { heap_close(rel, NoLock); elog(ERROR, "timecapsule does not support astore yet"); return; diff --git a/src/gausskernel/storage/tcap/tcap_manager.cpp b/src/gausskernel/storage/tcap/tcap_manager.cpp index bec2aa4e7..23d3b0b2e 100644 --- a/src/gausskernel/storage/tcap/tcap_manager.cpp +++ b/src/gausskernel/storage/tcap/tcap_manager.cpp @@ -730,7 +730,7 @@ bool NeedTrComm(Oid relid) /* table is non ordinary table, or */ classForm->relkind != RELKIND_RELATION || /* is non heap table, or */ - rel->rd_tam_type == TAM_HEAP || + rel->rd_tam_ops == TableAmHeap || /* is non regular table, or */ classForm->relpersistence != RELPERSISTENCE_PERMANENT || /* is shared table across databases, or */ diff --git a/src/gausskernel/storage/tcap/tcap_truncate.cpp b/src/gausskernel/storage/tcap/tcap_truncate.cpp index 531b11ea0..e63d74231 100644 --- a/src/gausskernel/storage/tcap/tcap_truncate.cpp +++ b/src/gausskernel/storage/tcap/tcap_truncate.cpp @@ -484,7 +484,7 @@ void TrRestoreTruncate(const TimeCapsuleStmt *stmt) rel = heap_openrv(stmt->relation, AccessExclusiveLock); relid = RelationGetRelid(rel); - if (rel->rd_tam_type == TAM_HEAP) { + if (rel->rd_tam_ops == TableAmHeap) { heap_close(rel, NoLock); elog(ERROR, "timecapsule does not support astore yet"); return; diff --git a/src/gausskernel/storage/tcap/tcap_version.cpp b/src/gausskernel/storage/tcap/tcap_version.cpp index 6c5c7fbf1..abd373f17 100644 --- a/src/gausskernel/storage/tcap/tcap_version.cpp +++ b/src/gausskernel/storage/tcap/tcap_version.cpp @@ -134,7 +134,7 @@ static bool TvFeatureSupport(Oid relid, char **errstr, bool isTimecapsuleTable) *errstr = "timecapsule feature does not support system table"; } else if (classForm->relpersistence != RELPERSISTENCE_PERMANENT) { *errstr = "timecapsule feature does not support non-permanent table"; - } else if (rel->rd_tam_type == TAM_HEAP) { + } else if (rel->rd_tam_ops == TableAmHeap) { *errstr = "timecapsule feature does not support heap table"; } else if ((RELATION_HAS_BUCKET(rel) || RELATION_OWN_BUCKET(rel))) { *errstr = "timecapsule feature does not support hash-bucket table"; @@ -834,7 +834,7 @@ static void TvUheapInsertLostImpl(Relation rel, Relation partRel, Partition p, recheckIndexes = ExecInsertIndexTuples(myslot, &tuple->ctid, estate, partRel, p, InvalidBktId, NULL, NULL); if (relRel != NULL && relRel->rd_mlogoid != InvalidOid) { HeapTuple htup = NULL; - Assert(relRel->rd_tam_type == TAM_USTORE); + Assert(relRel->rd_tam_ops == TableAmUstore); htup = (HeapTuple)UHeapToHeap(relRel->rd_att, (UHeapTuple)tuple); insert_into_mlog_table(relRel, relRel->rd_mlogoid, (HeapTuple)tuple, &(((HeapTuple)tuple)->t_self), GetCurrentTransactionId(), 'I'); diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index 3272dc1d7..e4308bd3a 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -201,7 +201,7 @@ typedef struct TableAmRoutine { * @param attnum: index of the atribute to be extracted. * @param isnull: set to true, if the attribute is NULL. */ - Datum (*tslot_getattr)(TupleTableSlot *slot, int attnum, bool *isnull); + Datum (*tslot_getattr)(TupleTableSlot *slot, int attnum, bool *isnull, bool need_transform_anyarray); /* * This function forces all the entries of slot's Datum/isnull array to be valid @@ -210,7 +210,7 @@ typedef struct TableAmRoutine { * * @param slot: TableTuple slot from this attributes are extracted */ - void (*tslot_getallattrs)(TupleTableSlot *slot); + void (*tslot_getallattrs)(TupleTableSlot *slot, bool need_transform_anyarray); /* * Detects if specified attribute is null without actually fetching it. @@ -498,7 +498,6 @@ typedef struct TableAmRoutine { void (*tcap_insert_lost)(Relation relation, Snapshot snap); } TableAmRoutine; - extern const TableAmRoutine * const g_tableam_routines[]; extern void HeapamScanIndexFetchEnd(IndexFetchTableData *scan); extern void heapam_index_fetch_reset(IndexFetchTableData *scan); @@ -510,7 +509,7 @@ static inline const TableAmRoutine* GetTableAmRoutine(TableAmType type) return type == TAM_HEAP ? TableAmHeap : TableAmUstore; } -static inline TableAmType GetTableAmType(const TableAmRoutine* ops) +static inline TableAmType GetTableAmType(const TableAmRoutine* ops) { Assert(ops == TableAmHeap || ops == TableAmUstore); return ops == TableAmHeap ? TAM_HEAP : TAM_USTORE; @@ -524,7 +523,7 @@ static inline TableAmType GetTableAmType(const TableAmRoutine* ops) static inline Tuple tableam_tslot_get_tuple_from_slot(Relation relation, TupleTableSlot *slot) { slot->tts_tupleDescriptor->tdhasuids = RELATION_HAS_UIDS(relation); - return g_tableam_routines[relation->rd_tam_type]->tslot_get_tuple_from_slot(slot); + return relation->rd_tam_ops->tslot_get_tuple_from_slot(slot); } /* @@ -567,9 +566,11 @@ static inline HeapTuple tableam_tslot_copy_heap_tuple(TupleTableSlot *slot) static inline void tableam_tslot_store_tuple(Tuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree, bool batchMode) { - g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tslot_store_tuple(tuple, slot, buffer, shouldFree, batchMode); + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == slot->tts_tam_ops); + slot->tts_tam_ops->tslot_store_tuple(tuple, slot, buffer, shouldFree, batchMode); } + static inline void tableam_tslot_getsomeattrs(TupleTableSlot *slot, int natts) { slot->tts_tam_ops->tslot_getsomeattrs(slot, natts); @@ -580,14 +581,14 @@ static inline void tableam_tslot_formbatch(TupleTableSlot* slot, VectorBatch* ba slot->tts_tam_ops->tslot_formbatch(slot, batch, cur_rows, natts); } -static inline Datum tableam_tslot_getattr(TupleTableSlot *slot, int attnum, bool *isnull) +static inline Datum tableam_tslot_getattr(TupleTableSlot *slot, int attnum, bool *isnull, bool need_transform_anyarray = false) { - return slot->tts_tam_ops->tslot_getattr(slot, attnum, isnull); + return slot->tts_tam_ops->tslot_getattr(slot, attnum, isnull, need_transform_anyarray); } -static inline void tableam_tslot_getallattrs(TupleTableSlot *slot) +static inline void tableam_tslot_getallattrs(TupleTableSlot *slot, bool need_transform_anyarray = false) { - return slot->tts_tam_ops->tslot_getallattrs(slot); + return slot->tts_tam_ops->tslot_getallattrs(slot, need_transform_anyarray); } static inline bool tableam_tslot_attisnull(TupleTableSlot *slot, int attnum) @@ -604,51 +605,53 @@ static inline Datum tableam_tops_getsysattr(Tuple tuple, int attnum, TupleDesc t Buffer buf = InvalidBuffer) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_getsysattr(tuple, attnum, tuple_desc, isnull, buf); + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_getsysattr(tuple, attnum, tuple_desc, isnull, buf); } static inline MinimalTuple tableam_tops_form_minimal_tuple(TupleDesc tuple_descriptor, Datum *values, const bool *isnull, MinimalTuple in_tuple, const TableAmRoutine* tam_ops = TableAmHeap) { - Assert(tuple_descriptor->td_tam_ops == tam_ops); - return tuple_descriptor->td_tam_ops->tops_form_minimal_tuple(tuple_descriptor, values, isnull, + return tam_ops->tops_form_minimal_tuple(tuple_descriptor, values, isnull, in_tuple); } static inline Tuple tableam_tops_form_tuple(TupleDesc tuple_descriptor, Datum *values, bool *isnull, const TableAmRoutine* tam_ops = TableAmHeap) { - Assert(tuple_descriptor->td_tam_ops == tam_ops); - return tuple_descriptor->td_tam_ops->tops_form_tuple(tuple_descriptor, values, isnull); + return tam_ops->tops_form_tuple(tuple_descriptor, values, isnull); } static inline Tuple tableam_tops_form_cmprs_tuple(TupleDesc tuple_descriptor, FormCmprTupleData *cmprs_info, const TableAmRoutine* tam_ops = TableAmHeap) { - Assert(tuple_descriptor->td_tam_ops == tam_ops); - return tuple_descriptor->td_tam_ops->tops_form_cmprs_tuple(tuple_descriptor, cmprs_info); + return tam_ops->tops_form_cmprs_tuple(tuple_descriptor, cmprs_info); } static inline void tableam_tops_deform_tuple(Tuple tuple, TupleDesc tuple_desc, Datum *values, bool *isnull) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_tuple(tuple, tuple_desc, values, isnull); + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_deform_tuple(tuple, tuple_desc, values, isnull); } static inline void tableam_tops_deform_tuple2(Tuple tuple, TupleDesc tuple_desc, Datum *values, bool *isnull, Buffer buffer) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_tuple2(tuple, tuple_desc, values, isnull, buffer); + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_deform_tuple2(tuple, tuple_desc, values, isnull, buffer); } static inline void tableam_tops_deform_cmprs_tuple(Tuple tuple, TupleDesc tuple_desc, Datum *values, bool *isnull, char *cmprs_info) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_deform_cmprs_tuple(tuple, tuple_desc, values, isnull, + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_deform_cmprs_tuple(tuple, tuple_desc, values, isnull, cmprs_info); } + static inline void tableam_tops_fill_tuple(TupleDesc tuple_desc, Datum *values, const bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit) { @@ -664,7 +667,8 @@ static inline Tuple tableam_tops_modify_tuple(Tuple tuple, TupleDesc tuple_desc, const bool *repl_isnull, const bool *do_replace) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_modify_tuple(tuple, tuple_desc, repl_values, + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_modify_tuple(tuple, tuple_desc, repl_values, repl_isnull, do_replace); } @@ -672,7 +676,8 @@ static inline Tuple tableam_tops_opfusion_modify_tuple(Tuple tuple, TupleDesc tu Datum* repl_values, bool* repl_isnull, UpdateFusion* opf) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_opfusion_modify_tuple(tuple, tuple_desc, + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_opfusion_modify_tuple(tuple, tuple_desc, repl_values, repl_isnull, opf); } @@ -690,14 +695,16 @@ static inline Tuple tableam_tops_opfusion_modify_tuple(Tuple tuple, TupleDesc tu static inline Datum tableam_tops_tuple_getattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool *is_null) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_getattr(tuple, att_num, + //FIXME: Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return GetTableAmRoutine((TableAmType)(GetTabelAmIndexTuple(tuple)))->tops_tuple_getattr(tuple, att_num, tuple_desc, is_null); } static inline Datum tableam_tops_tuple_fast_getattr(Tuple tuple, int att_num, TupleDesc tuple_desc, bool *is_null) { AssertValidTuple(tuple); - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_fast_getattr(tuple, att_num, + Assert(g_tableam_routines[GetTabelAmIndexTuple(tuple)] == tuple_desc->td_tam_ops); + return tuple_desc->td_tam_ops->tops_tuple_fast_getattr(tuple, att_num, tuple_desc, is_null); } @@ -707,60 +714,191 @@ static inline bool tableam_tops_tuple_attisnull(Tuple tuple, int attnum, TupleDe * We allow a NULL tupledesc for relations not expected to have missing * values, such as catalog relations and indexes. */ - return g_tableam_routines[GetTabelAmIndexTuple(tuple)]->tops_tuple_attisnull(tuple, attnum, tuple_desc); + return GetTableAmRoutine((TableAmType)(GetTabelAmIndexTuple(tuple)))->tops_tuple_attisnull(tuple, attnum, tuple_desc); } -extern Tuple tableam_tops_copy_tuple(Tuple tuple); -extern MinimalTuple tableam_tops_copy_minimal_tuple(MinimalTuple mtup); -extern void tableam_tops_free_minimal_tuple(MinimalTuple mtup); -extern Tuple tableam_tops_new_tuple(Relation relation, ItemPointer tid); -extern TransactionId tableam_tops_get_conflictXid(Relation relation, Tuple tup); -extern void tableam_tops_destroy_tuple(Relation relation, Tuple tuple); -extern void tableam_tops_add_to_bulk_insert_select(Relation relation, CopyFromBulk bulk, Tuple tup, - bool needCopy); -extern void tableam_tops_add_to_bulk(Relation relation, - CopyFromBulk bulk, Tuple tup, bool needCopy); -extern ItemPointer tableam_tops_get_t_self(Relation relation, Tuple tup); -extern void tableam_tops_exec_delete_index_tuples(TupleTableSlot *slot, Relation relation, +static inline Tuple tableam_tops_copy_tuple(Tuple tuple) +{ + AssertValidTuple(tuple); + return GetTableAmRoutine((TableAmType)(GetTabelAmIndexTuple(tuple)))->tops_copy_tuple(tuple); +} + +static inline MinimalTuple tableam_tops_copy_minimal_tuple(MinimalTuple mtup) +{ + return heap_copy_minimal_tuple(mtup); +} + +static inline void tableam_tops_free_minimal_tuple(MinimalTuple mtup) +{ + heap_free_minimal_tuple(mtup); +} + +static inline Tuple tableam_tops_new_tuple(Relation relation, ItemPointer tid) +{ + return relation->rd_tam_ops->tops_new_tuple(relation, tid); +} + +static inline TransactionId tableam_tops_get_conflictXid(Relation relation, Tuple tup) +{ + return relation->rd_tam_ops->tops_get_conflictXid(tup); +} + +static inline void tableam_tops_destroy_tuple(Relation relation, Tuple tuple) +{ + relation->rd_tam_ops->tops_destroy_tuple(tuple); +} + +static inline void tableam_tops_add_to_bulk_insert_select(Relation relation, CopyFromBulk bulk, Tuple tup, + bool needCopy) +{ + relation->rd_tam_ops->tops_add_to_bulk_insert_select(bulk, tup, needCopy); +} + +static inline void tableam_tops_add_to_bulk(Relation relation, + CopyFromBulk bulk, Tuple tup, bool needCopy) +{ + relation->rd_tam_ops->tops_add_to_bulk(bulk, tup, needCopy); +} + +static inline ItemPointer tableam_tops_get_t_self(Relation relation, Tuple tup) +{ + return relation->rd_tam_ops->tops_get_t_self(tup); +} + +static inline void tableam_tops_exec_delete_index_tuples(TupleTableSlot *slot, Relation relation, ModifyTableState *node, ItemPointer tupleid, ExecIndexTuplesState exec_index_tuples_state, - Bitmapset *modifiedIdxAttrs); -extern List *tableam_tops_exec_update_index_tuples(TupleTableSlot *slot, TupleTableSlot *oldslot, + Bitmapset *modifiedIdxAttrs) +{ + relation->rd_tam_ops->tops_exec_delete_index_tuples(slot, relation, node, tupleid, + exec_index_tuples_state, modifiedIdxAttrs); +} + +static inline List *tableam_tops_exec_update_index_tuples(TupleTableSlot *slot, TupleTableSlot *oldslot, Relation relation, ModifyTableState *node, Tuple tuple, ItemPointer tupleid, - ExecIndexTuplesState exec_index_tuples_state, int2 bucketid, Bitmapset *modifiedIdxAttrs); -extern uint32 tableam_tops_get_tuple_type(Relation relation); -extern void tableam_tops_copy_from_insert_batch(Relation rel, EState* estate, CommandId mycid, int hiOptions, + ExecIndexTuplesState exec_index_tuples_state, int2 bucketid, Bitmapset *modifiedIdxAttrs) +{ + return relation->rd_tam_ops->tops_exec_update_index_tuples(slot, oldslot, relation, node, + tuple, tupleid, exec_index_tuples_state, bucketid, modifiedIdxAttrs); +} + +static inline uint32 tableam_tops_get_tuple_type(Relation relation) +{ + return relation->rd_tam_ops->tops_get_tuple_type(); +} + +static inline void tableam_tops_copy_from_insert_batch(Relation rel, EState* estate, CommandId mycid, int hiOptions, ResultRelInfo* resultRelInfo, TupleTableSlot* myslot, BulkInsertState bistate, int nBufferedTuples, - Tuple* bufferedTuples, Partition partition, int2 bucketId); -extern bool tableam_tops_page_get_item(Relation rel, Tuple tuple, Page page, - OffsetNumber tupleNo, BlockNumber destBlocks); -extern OffsetNumber tableam_tops_page_get_max_offsetnumber(Relation rel, Page page); -extern Size tableam_tops_page_get_freespace(Relation rel, Page page); -extern bool tableam_tops_tuple_fetch_row_version(TidScanState* node, Relation relation, ItemPointer tid, - Snapshot snapshot, TupleTableSlot *slot); -extern void tableam_tops_update_tuple_with_oid(Relation relation, Tuple tup, TupleTableSlot *slot); -extern bool tableam_tuple_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, - bool keep_buf, Relation stats_relation); -extern bool tableam_tuple_satisfies_snapshot(Relation relation, HeapTuple tuple, Snapshot snapshot, - Buffer buffer); -extern void tableam_tuple_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid); -extern Oid tableam_tuple_insert(Relation relation, Tuple tup, CommandId cid, int options, - struct BulkInsertStateData *bistate); -extern int tableam_tuple_multi_insert(Relation relation, Relation parent, Tuple *tuples, int ntuples, - CommandId cid, int options, struct BulkInsertStateData *bistate, HeapMultiInsertExtraArgs *args); -extern TM_Result tableam_tuple_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, - Snapshot snapshot, bool wait, TupleTableSlot **oldslot, TM_FailureData *tmfd, bool allow_delete_self = false); -extern TM_Result tableam_tuple_update(Relation relation, Relation parentRelation, ItemPointer otid, Tuple newtup, + Tuple* bufferedTuples, Partition partition, int2 bucketId) +{ + rel->rd_tam_ops->tops_copy_from_insert_batch(rel, estate, mycid, hiOptions, resultRelInfo, + myslot, bistate, nBufferedTuples, bufferedTuples, partition, bucketId); +} + +static inline bool tableam_tops_page_get_item(Relation rel, Tuple tuple, Page page, + OffsetNumber tupleNo, BlockNumber destBlocks) +{ + return rel->rd_tam_ops->tops_page_get_item(rel, tuple, page, tupleNo, destBlocks); +} + +static inline OffsetNumber tableam_tops_page_get_max_offsetnumber(Relation rel, Page page) +{ + return rel->rd_tam_ops->tops_page_get_max_offsetnumber(page); +} + +static inline Size tableam_tops_page_get_freespace(Relation rel, Page page) +{ + return rel->rd_tam_ops->tops_page_get_freespace(page); +} + +static inline bool tableam_tops_tuple_fetch_row_version(TidScanState* node, Relation relation, ItemPointer tid, + Snapshot snapshot, TupleTableSlot *slot) +{ + return relation->rd_tam_ops->tops_tuple_fetch_row_version(node, relation, tid, snapshot, slot); +} + +static inline void tableam_tops_update_tuple_with_oid(Relation relation, Tuple tup, TupleTableSlot *slot) +{ + relation->rd_tam_ops->tops_update_tuple_with_oid(relation, tup, slot); +} + +/* ------------------------------------------------------------------------ + * DQL AM APIs + * ------------------------------------------------------------------------ + */ +static inline bool tableam_tuple_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, + bool keep_buf, Relation stats_relation) +{ + return relation->rd_tam_ops->tuple_fetch(relation, snapshot, tuple, userbuf, keep_buf, + stats_relation); +} + +static inline bool tableam_tuple_satisfies_snapshot(Relation relation, HeapTuple tuple, Snapshot snapshot, + Buffer buffer) +{ + return relation->rd_tam_ops->tuple_satisfies_snapshot(relation, tuple, snapshot, buffer); +} + +static inline void tableam_tuple_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid) +{ + return relation->rd_tam_ops->tuple_get_latest_tid(relation, snapshot, tid); +} + +static inline Oid tableam_tuple_insert(Relation relation, Tuple tup, CommandId cid, int options, + struct BulkInsertStateData *bistate) +{ + return relation->rd_tam_ops->tuple_insert(relation, tup, cid, options, bistate); +} + +static inline int tableam_tuple_multi_insert(Relation relation, Relation parent, Tuple *tuples, int ntuples, + CommandId cid, int options, struct BulkInsertStateData *bistate, HeapMultiInsertExtraArgs *args) +{ + return relation->rd_tam_ops->tuple_multi_insert(relation, parent, tuples, ntuples, cid, + options, bistate, args); +} + +static inline TM_Result tableam_tuple_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, + Snapshot snapshot, bool wait, TupleTableSlot **oldslot, TM_FailureData *tmfd, bool allow_delete_self = false) +{ + return relation->rd_tam_ops->tuple_delete(relation, tid, cid, crosscheck, snapshot, wait, + oldslot, tmfd, allow_delete_self); +} + +static inline TM_Result tableam_tuple_update(Relation relation, Relation parentRelation, ItemPointer otid, Tuple newtup, CommandId cid, Snapshot crosscheck, Snapshot snapshot, bool wait, TupleTableSlot **oldslot, TM_FailureData *tmfd, bool *update_indexes, Bitmapset **modifiedIdxAttrs, bool allow_update_self = false, - bool allow_inplace_update = true, LockTupleMode *lockmode = NULL); -extern TM_Result tableam_tuple_lock(Relation relation, Tuple tuple, Buffer *buffer, CommandId cid, - LockTupleMode mode, LockWaitPolicy waitPolicy, TM_FailureData *tmfd, bool allow_lock_self, bool follow_updates, bool eval, + bool allow_inplace_update = true, LockTupleMode *lockmode = NULL) +{ + return relation->rd_tam_ops->tuple_update(relation, parentRelation, otid, newtup, cid, + crosscheck, snapshot, wait, oldslot, tmfd, lockmode, update_indexes, modifiedIdxAttrs, allow_update_self, + allow_inplace_update); +} + +static inline TM_Result tableam_tuple_lock(Relation relation, Tuple tuple, Buffer *buffer, CommandId cid, + LockTupleMode mode, LockWaitPolicy nowait, TM_FailureData *tmfd, bool allow_lock_self, bool follow_updates, bool eval, Snapshot snapshot, ItemPointer tid, bool isSelectForUpdate, bool isUpsert = false, - TransactionId conflictXid = InvalidTransactionId, int waitSec = 0); -extern Tuple tableam_tuple_lock_updated(CommandId cid, Relation relation, int lockmode, ItemPointer tid, - TransactionId priorXmax, Snapshot snapshot = NULL, bool isSelectForUpdate = false); -extern void tableam_tuple_check_visible(Relation relation, Snapshot snapshot, Tuple tuple, Buffer buffer); -extern void tableam_tuple_abort_speculative(Relation relation, Tuple tuple); + TransactionId conflictXid = InvalidTransactionId, int waitSec = 0) +{ + return relation->rd_tam_ops->tuple_lock(relation, tuple, buffer, cid, mode, nowait, tmfd, + allow_lock_self, follow_updates, eval, snapshot, tid, isSelectForUpdate, isUpsert, conflictXid, + waitSec); +} + +static inline Tuple tableam_tuple_lock_updated(CommandId cid, Relation relation, int lockmode, ItemPointer tid, + TransactionId priorXmax, Snapshot snapshot = NULL, bool isSelectForUpdate = false) +{ + return (Tuple)relation->rd_tam_ops->tuple_lock_updated(cid, relation, lockmode, tid, priorXmax, + snapshot, isSelectForUpdate); +} + +static inline void tableam_tuple_check_visible(Relation relation, Snapshot snapshot, Tuple tuple, Buffer buffer) +{ + relation->rd_tam_ops->tuple_check_visible(snapshot, tuple, buffer); +} + +static inline void tableam_tuple_abort_speculative(Relation relation, Tuple tuple) +{ + relation->rd_tam_ops->tuple_abort_speculative(relation, tuple); +} /* ----------------------------------------------------------------------- * SCAN AM APIS FOR HEAP @@ -768,52 +906,146 @@ extern void tableam_tuple_abort_speculative(Relation relation, Tuple tuple); */ extern IndexFetchTableData *tableam_scan_index_fetch_begin(Relation rel); -extern void tableam_scan_index_fetch_reset(IndexFetchTableData *scan); + +static inline void tableam_scan_index_fetch_reset(IndexFetchTableData *scan) +{ + heapam_index_fetch_reset(scan); +} + extern void tableam_scan_index_fetch_end(IndexFetchTableData *scan); -extern Tuple tableam_scan_index_fetch_tuple(IndexScanDesc scan, bool *all_dead, bool* has_cur_xact_write = NULL); -extern TableScanDesc tableam_scan_begin(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, - RangeScanInRedis rangeScanInRedis = { false, 0, 0 }); -extern TableScanDesc tableam_scan_begin_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key); -extern TableScanDesc tableam_scan_begin_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, - bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis = { false, 0, 0 }); -extern TableScanDesc tableam_scan_begin_parallel(Relation relation, ParallelHeapScanDesc parallel_scan); -extern Tuple tableam_scan_getnexttuple(TableScanDesc sscan, ScanDirection direction, bool* has_cur_xact_write = NULL); -extern bool tableam_scan_gettuplebatchmode(TableScanDesc sscan, ScanDirection direction); -extern void tableam_scan_getpage(TableScanDesc sscan, BlockNumber page); -extern Tuple tableam_scan_gettuple_for_verify(TableScanDesc sscan, ScanDirection direction, bool isValidRelationPage); -extern void tableam_scan_end(TableScanDesc sscan); -extern void tableam_scan_rescan(TableScanDesc sscan, ScanKey key); -extern void tableam_scan_restrpos(TableScanDesc sscan); -extern void tableam_scan_markpos(TableScanDesc sscan); -extern void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir); -extern double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan); -extern void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, - Snapshot snapshot, v_i_state *state); -extern double tableam_relation_copy_for_cluster(Relation OldHeap, Relation OldIndex, Relation NewHeap, - TransactionId OldestXmin, TransactionId FreezeXid, bool verbose, bool use_sort, AdaptMem *memUsage); + +static inline Tuple tableam_scan_index_fetch_tuple(IndexScanDesc scan, bool *all_dead, bool* has_cur_xact_write = NULL) +{ + return scan->heapRelation->rd_tam_ops->scan_index_fetch_tuple(scan, all_dead, has_cur_xact_write); +} + +static inline TableScanDesc tableam_scan_begin(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + RangeScanInRedis rangeScanInRedis = { false, 0, 0 }) +{ + return relation->rd_tam_ops->scan_begin(relation, snapshot, nkeys, key, rangeScanInRedis); +} + +static inline TableScanDesc tableam_scan_begin_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key) +{ + return relation->rd_tam_ops->scan_begin_bm(relation, snapshot, nkeys, key); +} + +static inline TableScanDesc tableam_scan_begin_sampling(Relation relation, Snapshot snapshot, int nkeys, ScanKey key, + bool allow_strat, bool allow_sync, RangeScanInRedis rangeScanInRedis = { false, 0, 0 } ) +{ + return relation->rd_tam_ops->scan_begin_sampling(relation, snapshot, nkeys, key, allow_strat, + allow_sync, rangeScanInRedis); +} + +static inline TableScanDesc tableam_scan_begin_parallel(Relation relation, ParallelHeapScanDesc parallel_scan) +{ + return relation->rd_tam_ops->scan_begin_parallel(relation, parallel_scan); +} + +static inline Tuple tableam_scan_getnexttuple(TableScanDesc sscan, ScanDirection direction, bool* has_cur_xact_write = NULL) +{ + return sscan->rs_rd->rd_tam_ops->scan_getnexttuple(sscan, direction, has_cur_xact_write); +} + +static inline bool tableam_scan_gettuplebatchmode(TableScanDesc sscan, ScanDirection direction) +{ + return sscan->rs_rd->rd_tam_ops->scan_GetNextBatch(sscan, direction); +} + +static inline void tableam_scan_getpage(TableScanDesc sscan, BlockNumber page) +{ + return sscan->rs_rd->rd_tam_ops->scan_getpage(sscan, page); +} + +static inline Tuple tableam_scan_gettuple_for_verify(TableScanDesc sscan, ScanDirection direction, bool isValidRelationPage) +{ + return sscan->rs_rd->rd_tam_ops->scan_gettuple_for_verify(sscan, + direction, isValidRelationPage); +} + +static inline void tableam_scan_end(TableScanDesc sscan) +{ + return sscan->rs_rd->rd_tam_ops->scan_end(sscan); +} + +static inline void tableam_scan_rescan(TableScanDesc sscan, ScanKey key) +{ + return sscan->rs_rd->rd_tam_ops->scan_rescan(sscan, key); +} + +static inline void tableam_scan_restrpos(TableScanDesc sscan) +{ + return sscan->rs_rd->rd_tam_ops->scan_restrpos(sscan); +} + +static inline void tableam_scan_markpos(TableScanDesc sscan) +{ + return sscan->rs_rd->rd_tam_ops->scan_markpos(sscan); +} + +static inline void tableam_scan_init_parallel_seqscan(TableScanDesc sscan, int32 dop, ScanDirection dir) +{ + return sscan->rs_rd->rd_tam_ops->scan_init_parallel_seqscan(sscan, dop, dir); +} + +static inline double tableam_index_build_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + bool allow_sync, IndexBuildCallback callback, void *callback_state, TableScanDesc scan) +{ + return heapRelation->rd_tam_ops->index_build_scan(heapRelation, indexRelation, indexInfo, + allow_sync, callback, callback_state, scan); +} + +static inline void tableam_index_validate_scan(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, + Snapshot snapshot, v_i_state *state) +{ + return heapRelation->rd_tam_ops->index_validate_scan(heapRelation, indexRelation, indexInfo, + snapshot, state); +} + +static inline double tableam_relation_copy_for_cluster(Relation OldHeap, Relation OldIndex, Relation NewHeap, + TransactionId OldestXmin, TransactionId FreezeXid, bool verbose, bool use_sort, AdaptMem *memUsage) +{ + return OldHeap->rd_tam_ops->relation_copy_for_cluster(OldHeap, OldIndex, NewHeap, OldestXmin, + FreezeXid, verbose, use_sort, memUsage); +} + static inline void tableam_tcap_promote_lock(Relation relation, LOCKMODE *lockmode) { - return g_tableam_routines[relation->rd_tam_type]->tcap_promote_lock(relation, lockmode); + return relation->rd_tam_ops->tcap_promote_lock(relation, lockmode); } static inline bool tableam_tcap_validate_snap(Relation relation, Snapshot snap) { - return g_tableam_routines[relation->rd_tam_type]->tcap_validate_snap(relation, snap); + return relation->rd_tam_ops->tcap_validate_snap(relation, snap); } static inline void tableam_tcap_delete_delta(Relation relation, Snapshot snap) { - return g_tableam_routines[relation->rd_tam_type]->tcap_delete_delta(relation, snap); + return relation->rd_tam_ops->tcap_delete_delta(relation, snap); } static inline void tableam_tcap_insert_lost(Relation relation, Snapshot snap) { - return g_tableam_routines[relation->rd_tam_type]->tcap_insert_lost(relation, snap); + return relation->rd_tam_ops->tcap_insert_lost(relation, snap); } extern TM_Result HeapamTupleUpdate(Relation relation, Relation parentRelation, ItemPointer otid, Tuple newtup, CommandId cid, Snapshot crosscheck, Snapshot snapshot, bool wait, TM_FailureData *tmfd, bool *update_indexes, Bitmapset **modifiedIdxAttrs, bool allow_update_self = false, bool allow_inplace_update = true); +/* ------------------------------------------------------------------------ + * HEAP AM APIs + * ------------------------------------------------------------------------ + */ +extern Tuple heap_slot_get_tuple_from_slot(TupleTableSlot* slot); +extern Datum heapam_getsysattr(Tuple tup, int attnum, TupleDesc tuple_desc, bool* isnull, Buffer buff); +extern Tuple heapam_form_tuple(TupleDesc tuple_descriptor, Datum* values, bool* isnull); +extern void heapam_deform_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull); +extern void heapam_deform_tuple2(Tuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull, Buffer buffer); +extern void heapam_deform_cmprs_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* values, bool* isnull, char* cmprs_info); +extern void heapam_fill_tuple(TupleDesc tuple_desc, Datum* values, const bool* isnull, char* data, Size data_size, uint16* infomask, bits8* bit); +extern Tuple heapam_modify_tuple(Tuple tuple, TupleDesc tuple_desc, Datum* repl_values, const bool* repl_isnull, const bool* do_replace); +extern bool heapam_attisnull(Tuple tup, int attnum, TupleDesc tuple_desc); +extern Tuple heapam_copytuple(Tuple tuple); + #endif /* TABLEAM_H */ diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h index 65c85f71a..437541893 100644 --- a/src/include/executor/tuptable.h +++ b/src/include/executor/tuptable.h @@ -210,13 +210,13 @@ extern TupleTableSlot* ExecCopySlot(TupleTableSlot* dstslot, TupleTableSlot* src /* heap table specific slot/tuple operations*/ /* definitions are found in access/common/heaptuple.c */ extern void heap_slot_clear(TupleTableSlot* slot); -extern void heap_slot_materialize(TupleTableSlot* slot); +extern HeapTuple heap_slot_materialize(TupleTableSlot* slot); extern MinimalTuple heap_slot_get_minimal_tuple(TupleTableSlot *slot); extern MinimalTuple heap_slot_copy_minimal_tuple(TupleTableSlot *slot); extern void heap_slot_store_minimal_tuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree); extern HeapTuple heap_slot_get_heap_tuple (TupleTableSlot* slot); extern HeapTuple heap_slot_copy_heap_tuple (TupleTableSlot *slot); -extern void heap_slot_store_heap_tuple(HeapTuple tuple, TupleTableSlot* slot, Buffer buffer, bool shouldFree, bool batchMode); +extern void heap_slot_store_heap_tuple(Tuple tup, TupleTableSlot* slot, Buffer buffer, bool shouldFree, bool batchMode); extern Datum heap_slot_getattr(TupleTableSlot* slot, int attnum, bool* isnull, bool need_transform_anyarray = false); extern void heap_slot_getallattrs(TupleTableSlot* slot, bool need_transform_anyarray = false); extern void slot_getallattrsfast(TupleTableSlot *slot, int maxIdx); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index bcd3b6322..c60381ac3 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -134,6 +134,8 @@ typedef struct RelationData { char rd_indexvalid; /* state of rd_indexlist: 0 = not valid, 1 = * valid, 2 = temporarily forced */ bool rd_islocaltemp; /* rel is a temp rel of this session */ + bool is_compressed; + bool rd_isblockchain; /* relation is in blockchain schema */ /* * rd_createSubid is the ID of the highest subtransaction the rel has @@ -150,8 +152,8 @@ typedef struct RelationData { Form_pg_class rd_rel; /* RELATION tuple */ TupleDesc rd_att; /* tuple descriptor */ + const TableAmRoutine* rd_tam_ops; /* implementation of table AM */ Oid rd_id; /* relation's object id */ - bool rd_isblockchain; /* relation is in blockchain schema */ char relreplident; /* see REPLICA_IDENTITY_xxx constants */ LockInfoData rd_lockInfo; /* lock mgr's info for locking relation */ @@ -196,7 +198,6 @@ typedef struct RelationData { Form_pg_am rd_am; /* pg_am tuple for index's AM */ int rd_indnkeyatts; /* index relation's indexkey nums */ - TableAmType rd_tam_type; /*Table accessor method type*/ int1 rd_indexsplit; /* determines the page split method to use */ /* @@ -292,7 +293,6 @@ typedef struct RelationData { /* Is under the context of creating crossbucket index? */ bool newcbi; - bool is_compressed; bool come_from_partrel; /* used only for gsc, keep it preserved if you modify the rel, otherwise set it null */ struct LocalRelationEntry *entry; diff --git a/src/include/utils/rel_gs.h b/src/include/utils/rel_gs.h index 13ca06d2c..2a425d7c0 100644 --- a/src/include/utils/rel_gs.h +++ b/src/include/utils/rel_gs.h @@ -301,12 +301,12 @@ static inline int8 get_indexsplit_from_reloptions(bytea *reloptions, Oid amoid) #define RelationIsUstoreFormat(relation) \ ((RELKIND_RELATION == relation->rd_rel->relkind || \ RELKIND_TOASTVALUE == relation->rd_rel->relkind) && \ - relation->rd_tam_type == TAM_USTORE) + relation->rd_tam_ops == TableAmUstore) #define RelationIsAstoreFormat(relation) \ ((RELKIND_RELATION == relation->rd_rel->relkind || \ RELKIND_TOASTVALUE == relation->rd_rel->relkind) && \ - relation->rd_tam_type == TAM_HEAP) + relation->rd_tam_ops == TableAmHeap) #define RelationIsUBTree(relation) (relation->rd_rel->relam == UBTREE_AM_OID) #define RelationIsUstoreIndex(relation) (RelationIsUBTree(relation))