From 58ee84b870221a70f8995fd27f1de0e83ec5602a Mon Sep 17 00:00:00 2001 From: kommih Date: Wed, 16 Jan 2019 18:43:47 +1100 Subject: [PATCH] Reduce the use of HeapTuple t_tableOid Except trigger and where the HeapTuple is generated and passed from slots, still the t_tableOid is used. This needs to be replaced when the t_tableOid is stored as a seperate variable/parameter. --- contrib/hstore/hstore_io.c | 2 - contrib/pg_visibility/pg_visibility.c | 1 - contrib/pgstattuple/pgstatapprox.c | 1 - contrib/pgstattuple/pgstattuple.c | 3 +- contrib/postgres_fdw/postgres_fdw.c | 14 ++++++- src/backend/access/common/heaptuple.c | 7 ---- src/backend/access/heap/heapam.c | 41 ++++++------------- src/backend/access/heap/heapam_handler.c | 29 ++++++------- src/backend/access/heap/heapam_visibility.c | 20 ++++----- src/backend/access/heap/pruneheap.c | 2 - src/backend/access/heap/tuptoaster.c | 3 -- src/backend/access/heap/vacuumlazy.c | 2 - src/backend/access/index/genam.c | 4 +- src/backend/catalog/indexing.c | 2 +- src/backend/commands/analyze.c | 2 +- src/backend/commands/functioncmds.c | 3 +- src/backend/commands/schemacmds.c | 1 - src/backend/commands/trigger.c | 21 +++++----- src/backend/executor/execExprInterp.c | 1 - src/backend/executor/execTuples.c | 25 +++++++---- src/backend/executor/execUtils.c | 2 - src/backend/executor/nodeAgg.c | 3 +- src/backend/executor/nodeGather.c | 1 + src/backend/executor/nodeGatherMerge.c | 1 + src/backend/executor/nodeIndexonlyscan.c | 4 +- src/backend/executor/nodeIndexscan.c | 3 +- src/backend/executor/nodeModifyTable.c | 6 +-- src/backend/executor/nodeSetOp.c | 1 + src/backend/executor/spi.c | 1 - src/backend/executor/tqueue.c | 1 - src/backend/replication/logical/decode.c | 9 ---- .../replication/logical/reorderbuffer.c | 4 +- src/backend/utils/adt/expandedrecord.c | 1 - src/backend/utils/adt/jsonfuncs.c | 2 - src/backend/utils/adt/rowtypes.c | 10 ----- src/backend/utils/cache/catcache.c | 1 - src/backend/utils/sort/tuplesort.c | 7 ++-- src/include/access/heapam.h | 2 +- src/include/executor/tuptable.h | 5 +-- src/include/utils/tqual.h | 1 + src/pl/plpgsql/src/pl_exec.c | 2 - src/test/regress/regress.c | 1 - 42 files changed, 98 insertions(+), 154 deletions(-) diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c index 745497c76f..05244e77ef 100644 --- a/contrib/hstore/hstore_io.c +++ b/contrib/hstore/hstore_io.c @@ -845,7 +845,6 @@ hstore_from_record(PG_FUNCTION_ARGS) /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(rec); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = rec; values = (Datum *) palloc(ncolumns * sizeof(Datum)); @@ -998,7 +997,6 @@ hstore_populate_record(PG_FUNCTION_ARGS) /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(rec); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = rec; } diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c index ce9ca704f6..1b1e00d724 100644 --- a/contrib/pg_visibility/pg_visibility.c +++ b/contrib/pg_visibility/pg_visibility.c @@ -655,7 +655,6 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen) ItemPointerSet(&(tuple.t_self), blkno, offnum); tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid); tuple.t_len = ItemIdGetLength(itemid); - tuple.t_tableOid = relid; /* * If we're checking whether the page is all-visible, we expect diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c index c59fd10dc1..cef8606550 100644 --- a/contrib/pgstattuple/pgstatapprox.c +++ b/contrib/pgstattuple/pgstatapprox.c @@ -152,7 +152,6 @@ statapprox_heap(Relation rel, output_type *stat) tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid); tuple.t_len = ItemIdGetLength(itemid); - tuple.t_tableOid = RelationGetRelid(rel); /* * We follow VACUUM's lead in counting INSERT_IN_PROGRESS tuples diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index 520438d779..a39b03bde5 100644 --- a/contrib/pgstattuple/pgstattuple.c +++ b/contrib/pgstattuple/pgstattuple.c @@ -344,7 +344,8 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_SHARE); - if (HeapTupleSatisfies(tuple, &SnapshotDirty, hscan->rs_cbuf)) + if (HeapTupleSatisfies(tuple, RelationGetRelid(hscan->rs_scan.rs_rd), + &SnapshotDirty, hscan->rs_cbuf)) { stat.tuple_len += tuple->t_len; stat.tuple_count++; diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index cc5b928950..5355e0e00e 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -1445,6 +1445,8 @@ postgresIterateForeignScan(ForeignScanState *node) */ ExecStoreHeapTuple(fsstate->tuples[fsstate->next_tuple++], slot, + fsstate->rel ? + RelationGetRelid(fsstate->rel) : InvalidOid, false); return slot; @@ -3538,7 +3540,11 @@ store_returning_result(PgFdwModifyState *fmstate, NULL, fmstate->temp_cxt); /* tuple will be deleted when it is cleared from the slot */ - ExecStoreHeapTuple(newtup, slot, true); + ExecStoreHeapTuple(newtup, + slot, + fmstate->rel ? + RelationGetRelid(fmstate->rel) : InvalidOid, + true); } PG_CATCH(); { @@ -3810,7 +3816,11 @@ get_returning_data(ForeignScanState *node) dmstate->retrieved_attrs, node, dmstate->temp_cxt); - ExecStoreHeapTuple(newtup, slot, false); + ExecStoreHeapTuple(newtup, + slot, + dmstate->rel ? + RelationGetRelid(dmstate->rel) : InvalidOid, + false); } PG_CATCH(); { diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 06dd628a5b..5beef33291 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -689,7 +689,6 @@ heap_copytuple(HeapTuple tuple) newTuple = (HeapTuple) palloc(HEAPTUPLESIZE + tuple->t_len); newTuple->t_len = tuple->t_len; newTuple->t_self = tuple->t_self; - newTuple->t_tableOid = tuple->t_tableOid; newTuple->t_data = (HeapTupleHeader) ((char *) newTuple + HEAPTUPLESIZE); memcpy((char *) newTuple->t_data, (char *) tuple->t_data, tuple->t_len); return newTuple; @@ -715,7 +714,6 @@ heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest) dest->t_len = src->t_len; dest->t_self = src->t_self; - dest->t_tableOid = src->t_tableOid; dest->t_data = (HeapTupleHeader) palloc(src->t_len); memcpy((char *) dest->t_data, (char *) src->t_data, src->t_len); } @@ -850,7 +848,6 @@ expand_tuple(HeapTuple *targetHeapTuple, = targetTHeader = (HeapTupleHeader) ((char *) *targetHeapTuple + HEAPTUPLESIZE); (*targetHeapTuple)->t_len = len; - (*targetHeapTuple)->t_tableOid = sourceTuple->t_tableOid; (*targetHeapTuple)->t_self = sourceTuple->t_self; targetTHeader->t_infomask = sourceTHeader->t_infomask; @@ -1078,7 +1075,6 @@ heap_form_tuple(TupleDesc tupleDescriptor, */ tuple->t_len = len; ItemPointerSetInvalid(&(tuple->t_self)); - tuple->t_tableOid = InvalidOid; HeapTupleHeaderSetDatumLength(td, len); HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid); @@ -1162,7 +1158,6 @@ heap_modify_tuple(HeapTuple tuple, */ newTuple->t_data->t_ctid = tuple->t_data->t_ctid; newTuple->t_self = tuple->t_self; - newTuple->t_tableOid = tuple->t_tableOid; return newTuple; } @@ -1225,7 +1220,6 @@ heap_modify_tuple_by_cols(HeapTuple tuple, */ newTuple->t_data->t_ctid = tuple->t_data->t_ctid; newTuple->t_self = tuple->t_self; - newTuple->t_tableOid = tuple->t_tableOid; return newTuple; } @@ -1465,7 +1459,6 @@ heap_tuple_from_minimal_tuple(MinimalTuple mtup) result = (HeapTuple) palloc(HEAPTUPLESIZE + len); result->t_len = len; ItemPointerSetInvalid(&(result->t_self)); - result->t_tableOid = InvalidOid; result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE); memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len); memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2)); diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index f769d828ff..22080fc5bc 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -423,7 +423,6 @@ heapgetpage(TableScanDesc sscan, BlockNumber page) HeapTupleData loctup; bool valid; - loctup.t_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); loctup.t_data = (HeapTupleHeader) PageGetItem((Page) dp, lpp); loctup.t_len = ItemIdGetLength(lpp); ItemPointerSet(&(loctup.t_self), page, lineoff); @@ -431,7 +430,8 @@ heapgetpage(TableScanDesc sscan, BlockNumber page) if (all_visible) valid = true; else - valid = HeapTupleSatisfies(&loctup, snapshot, buffer); + valid = HeapTupleSatisfies(&loctup, RelationGetRelid(scan->rs_scan.rs_rd), + snapshot, buffer); CheckForSerializableConflictOut(valid, scan->rs_scan.rs_rd, &loctup, buffer, snapshot); @@ -646,7 +646,8 @@ heapgettup(HeapScanDesc scan, /* * if current tuple qualifies, return it. */ - valid = HeapTupleSatisfies(tuple, snapshot, scan->rs_cbuf); + valid = HeapTupleSatisfies(tuple, RelationGetRelid(scan->rs_scan.rs_rd), + snapshot, scan->rs_cbuf); CheckForSerializableConflictOut(valid, scan->rs_scan.rs_rd, tuple, scan->rs_cbuf, snapshot); @@ -1442,9 +1443,6 @@ heap_beginscan(Relation relation, Snapshot snapshot, if (!is_bitmapscan && snapshot) PredicateLockRelation(relation, snapshot); - /* we only need to set this up once */ - scan->rs_ctup.t_tableOid = RelationGetRelid(relation); - /* * we do this here instead of in initscan() because heap_rescan also calls * initscan() and we don't want to allocate memory again @@ -1657,6 +1655,7 @@ heap_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *s pgstat_count_heap_getnext(scan->rs_scan.rs_rd); + slot->tts_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); return ExecStoreBufferHeapTuple(&scan->rs_ctup, slot, scan->rs_cbuf); } @@ -1760,12 +1759,11 @@ heap_fetch(Relation relation, ItemPointerCopy(tid, &(tuple->t_self)); tuple->t_data = (HeapTupleHeader) PageGetItem(page, lp); tuple->t_len = ItemIdGetLength(lp); - tuple->t_tableOid = RelationGetRelid(relation); /* * check time qualification of tuple, then release lock */ - valid = HeapTupleSatisfies(tuple, snapshot, buffer); + valid = HeapTupleSatisfies(tuple, RelationGetRelid(relation), snapshot, buffer); if (valid) PredicateLockTuple(relation, tuple, snapshot); @@ -1870,7 +1868,6 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, heapTuple->t_data = (HeapTupleHeader) PageGetItem(dp, lp); heapTuple->t_len = ItemIdGetLength(lp); - heapTuple->t_tableOid = RelationGetRelid(relation); ItemPointerSetOffsetNumber(&heapTuple->t_self, offnum); /* @@ -1907,7 +1904,8 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer, ItemPointerSet(&(heapTuple->t_self), BufferGetBlockNumber(buffer), offnum); /* If it's visible per the snapshot, we must return it */ - valid = HeapTupleSatisfies(heapTuple, snapshot, buffer); + valid = HeapTupleSatisfies(heapTuple, RelationGetRelid(relation), + snapshot, buffer); CheckForSerializableConflictOut(valid, relation, heapTuple, buffer, snapshot); /* reset to original, non-redirected, tid */ @@ -2064,7 +2062,6 @@ heap_get_latest_tid(Relation relation, tp.t_self = ctid; tp.t_data = (HeapTupleHeader) PageGetItem(page, lp); tp.t_len = ItemIdGetLength(lp); - tp.t_tableOid = RelationGetRelid(relation); /* * After following a t_ctid link, we might arrive at an unrelated @@ -2081,7 +2078,7 @@ heap_get_latest_tid(Relation relation, * Check time qualification of tuple; if visible, set it as the new * result candidate. */ - valid = HeapTupleSatisfies(&tp, snapshot, buffer); + valid = HeapTupleSatisfies(&tp, RelationGetRelid(relation), snapshot, buffer); CheckForSerializableConflictOut(valid, relation, &tp, buffer, snapshot); if (valid) *tid = ctid; @@ -2433,7 +2430,6 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid, HeapTupleHeaderSetCmin(tup->t_data, cid); HeapTupleHeaderSetXmax(tup->t_data, 0); /* for cleanliness */ - tup->t_tableOid = RelationGetRelid(relation); /* * If the new tuple is too big for storage or contains already toasted @@ -2491,9 +2487,6 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples, { heaptuples[i] = heap_prepare_insert(relation, ExecFetchSlotHeapTuple(slots[i], true, NULL), xid, cid, options); - - if (slots[i]->tts_tableOid != InvalidOid) - heaptuples[i]->t_tableOid = slots[i]->tts_tableOid; } /* @@ -2883,7 +2876,6 @@ heap_delete(Relation relation, ItemPointer tid, lp = PageGetItemId(page, ItemPointerGetOffsetNumber(tid)); Assert(ItemIdIsNormal(lp)); - tp.t_tableOid = RelationGetRelid(relation); tp.t_data = (HeapTupleHeader) PageGetItem(page, lp); tp.t_len = ItemIdGetLength(lp); tp.t_self = *tid; @@ -3000,7 +2992,7 @@ l1: if (crosscheck != InvalidSnapshot && result == HeapTupleMayBeUpdated) { /* Perform additional check for transaction-snapshot mode RI updates */ - if (!HeapTupleSatisfies(&tp, crosscheck, buffer)) + if (!HeapTupleSatisfies(&tp, RelationGetRelid(relation), crosscheck, buffer)) result = HeapTupleUpdated; } @@ -3404,14 +3396,10 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, * Fill in enough data in oldtup for HeapDetermineModifiedColumns to work * properly. */ - oldtup.t_tableOid = RelationGetRelid(relation); oldtup.t_data = (HeapTupleHeader) PageGetItem(page, lp); oldtup.t_len = ItemIdGetLength(lp); oldtup.t_self = *otid; - /* the new tuple is ready, except for this: */ - newtup->t_tableOid = RelationGetRelid(relation); - /* Determine columns modified by the update. */ modified_attrs = HeapDetermineModifiedColumns(relation, interesting_attrs, &oldtup, newtup); @@ -3642,7 +3630,7 @@ l2: if (crosscheck != InvalidSnapshot && result == HeapTupleMayBeUpdated) { /* Perform additional check for transaction-snapshot mode RI updates */ - if (!HeapTupleSatisfies(&oldtup, crosscheck, buffer)) + if (!HeapTupleSatisfies(&oldtup, RelationGetRelid(relation), crosscheck, buffer)) result = HeapTupleUpdated; } @@ -4267,14 +4255,14 @@ ProjIndexIsUnchanged(Relation relation, HeapTuple oldtup, HeapTuple newtup) int i; ResetExprContext(econtext); - ExecStoreHeapTuple(oldtup, slot, false); + ExecStoreHeapTuple(oldtup, slot, RelationGetRelid(relation),false); FormIndexDatum(indexInfo, slot, estate, old_values, old_isnull); - ExecStoreHeapTuple(newtup, slot, false); + ExecStoreHeapTuple(newtup, slot, RelationGetRelid(relation), false); FormIndexDatum(indexInfo, slot, estate, @@ -4486,7 +4474,6 @@ heap_lock_tuple(Relation relation, ItemPointer tid, tuple->t_data = (HeapTupleHeader) PageGetItem(page, lp); tuple->t_len = ItemIdGetLength(lp); - tuple->t_tableOid = RelationGetRelid(relation); tuple->t_self = *tid; l3: @@ -6044,7 +6031,6 @@ heap_abort_speculative(Relation relation, HeapTuple tuple) lp = PageGetItemId(page, ItemPointerGetOffsetNumber(tid)); Assert(ItemIdIsNormal(lp)); - tp.t_tableOid = RelationGetRelid(relation); tp.t_data = (HeapTupleHeader) PageGetItem(page, lp); tp.t_len = ItemIdGetLength(lp); tp.t_self = *tid; @@ -7747,7 +7733,6 @@ log_heap_new_cid(Relation relation, HeapTuple tup) HeapTupleHeader hdr = tup->t_data; Assert(ItemPointerIsValid(&tup->t_self)); - Assert(tup->t_tableOid != InvalidOid); xlrec.top_xid = GetTopTransactionId(); xlrec.target_node = relation->rd_node; diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index 95513dfec8..9119bdf162 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -90,8 +90,6 @@ heapam_heap_insert(Relation relation, TupleTableSlot *slot, CommandId cid, /* Update the tuple with table oid */ slot->tts_tableOid = RelationGetRelid(relation); - if (slot->tts_tableOid != InvalidOid) - tuple->t_tableOid = slot->tts_tableOid; /* Perform the insertion, and copy the resulting ItemPointer */ heap_insert(relation, tuple, cid, options, bistate); @@ -110,8 +108,6 @@ heapam_heap_insert_speculative(Relation relation, TupleTableSlot *slot, CommandI /* Update the tuple with table oid */ slot->tts_tableOid = RelationGetRelid(relation); - if (slot->tts_tableOid != InvalidOid) - tuple->t_tableOid = slot->tts_tableOid; HeapTupleHeaderSetSpeculativeToken(tuple->t_data, specToken); @@ -386,10 +382,6 @@ heapam_heap_update(Relation relation, ItemPointer otid, TupleTableSlot *slot, HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree); HTSU_Result result; - /* Update the tuple with table oid */ - if (slot->tts_tableOid != InvalidOid) - tuple->t_tableOid = slot->tts_tableOid; - result = heap_update(relation, otid, tuple, cid, crosscheck, wait, hufd, lockmode); ItemPointerCopy(&tuple->t_self, &slot->tts_tid); @@ -450,7 +442,7 @@ heapam_satisfies(Relation rel, TupleTableSlot *slot, Snapshot snapshot) * Caller should be holding pin, but not lock. */ LockBuffer(bslot->buffer, BUFFER_LOCK_SHARE); - res = HeapTupleSatisfies(bslot->base.tuple, snapshot, bslot->buffer); + res = HeapTupleSatisfies(bslot->base.tuple, RelationGetRelid(rel), snapshot, bslot->buffer); LockBuffer(bslot->buffer, BUFFER_LOCK_UNLOCK); return res; @@ -984,7 +976,7 @@ IndexBuildHeapRangeScan(Relation heapRelation, MemoryContextReset(econtext->ecxt_per_tuple_memory); /* Set up for predicate or expression evaluation */ - ExecStoreHeapTuple(heapTuple, slot, false); + ExecStoreHeapTuple(heapTuple, slot, RelationGetRelid(sscan->rs_rd), false); /* * In a partial index, discard tuples that don't satisfy the @@ -1240,7 +1232,7 @@ validate_index_heapscan(Relation heapRelation, MemoryContextReset(econtext->ecxt_per_tuple_memory); /* Set up for predicate or expression evaluation */ - ExecStoreHeapTuple(heapTuple, slot, false); + ExecStoreHeapTuple(heapTuple, slot, RelationGetRelid(sscan->rs_rd), false); /* * In a partial index, discard tuples that don't satisfy the @@ -1393,9 +1385,11 @@ heapam_scan_bitmap_pagescan(TableScanDesc sscan, continue; loctup.t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); loctup.t_len = ItemIdGetLength(lp); - loctup.t_tableOid = scan->rs_scan.rs_rd->rd_id; ItemPointerSet(&loctup.t_self, page, offnum); - valid = HeapTupleSatisfies(&loctup, snapshot, buffer); + valid = HeapTupleSatisfies(&loctup, + RelationGetRelid(scan->rs_scan.rs_rd), + snapshot, + buffer); if (valid) { scan->rs_vistuples[ntup++] = offnum; @@ -1432,7 +1426,6 @@ heapam_scan_bitmap_pagescan_next(TableScanDesc sscan, TupleTableSlot *slot) scan->rs_ctup.t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); scan->rs_ctup.t_len = ItemIdGetLength(lp); - scan->rs_ctup.t_tableOid = scan->rs_scan.rs_rd->rd_id; ItemPointerSet(&scan->rs_ctup.t_self, scan->rs_cblock, targoffset); pgstat_count_heap_fetch(scan->rs_scan.rs_rd); @@ -1444,6 +1437,7 @@ heapam_scan_bitmap_pagescan_next(TableScanDesc sscan, TupleTableSlot *slot) ExecStoreBufferHeapTuple(&scan->rs_ctup, slot, scan->rs_cbuf); + slot->tts_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); scan->rs_cindex++; @@ -1490,7 +1484,9 @@ SampleHeapTupleVisible(HeapScanDesc scan, Buffer buffer, else { /* Otherwise, we have to check the tuple individually. */ - return HeapTupleSatisfies(tuple, scan->rs_scan.rs_snapshot, buffer); + return HeapTupleSatisfies(tuple, + RelationGetRelid(scan->rs_scan.rs_rd), + scan->rs_scan.rs_snapshot, buffer); } } @@ -1635,6 +1631,7 @@ heapam_scan_sample_next_tuple(TableScanDesc sscan, struct SampleScanState *scans continue; ExecStoreBufferHeapTuple(tuple, slot, scan->rs_cbuf); + slot->tts_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); /* Found visible tuple, return it. */ if (!pagemode) @@ -1720,7 +1717,6 @@ heapam_scan_analyze_next_tuple(TableScanDesc sscan, TransactionId OldestXmin, do ItemPointerSet(&targtuple->t_self, scan->rs_cblock, scan->rs_cindex); - targtuple->t_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); targtuple->t_data = (HeapTupleHeader) PageGetItem(targpage, itemid); targtuple->t_len = ItemIdGetLength(itemid); @@ -1792,6 +1788,7 @@ heapam_scan_analyze_next_tuple(TableScanDesc sscan, TransactionId OldestXmin, do if (sample_it) { ExecStoreBufferHeapTuple(targtuple, slot, scan->rs_cbuf); + slot->tts_tableOid = RelationGetRelid(scan->rs_scan.rs_rd); scan->rs_cindex++; /* note that we leave the buffer locked here! */ diff --git a/src/backend/access/heap/heapam_visibility.c b/src/backend/access/heap/heapam_visibility.c index 1ac1a20c1d..cd4d3af3c3 100644 --- a/src/backend/access/heap/heapam_visibility.c +++ b/src/backend/access/heap/heapam_visibility.c @@ -179,7 +179,6 @@ HeapTupleSatisfiesSelf(HeapTuple htup, Snapshot snapshot, Buffer buffer) HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); if (!HeapTupleHeaderXminCommitted(tuple)) { @@ -370,7 +369,6 @@ HeapTupleSatisfiesToast(HeapTuple htup, Snapshot snapshot, HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); if (!HeapTupleHeaderXminCommitted(tuple)) { @@ -464,7 +462,6 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid, HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); if (!HeapTupleHeaderXminCommitted(tuple)) { @@ -757,7 +754,6 @@ HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot, HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); snapshot->xmin = snapshot->xmax = InvalidTransactionId; snapshot->speculativeToken = 0; @@ -981,7 +977,6 @@ HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot, HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); if (!HeapTupleHeaderXminCommitted(tuple)) { @@ -1183,7 +1178,6 @@ HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin, HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); /* * Has inserting transaction committed? @@ -1611,7 +1605,6 @@ HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin) HeapTupleHeader tuple = htup->t_data; Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); /* * If the inserting transaction is marked invalid, then it aborted, and @@ -1675,7 +1668,7 @@ TransactionIdInArray(TransactionId xid, TransactionId *xip, Size num) * complicated than when dealing "only" with the present. */ static bool -HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, +HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Oid relid, Snapshot snapshot, Buffer buffer) { HeapTupleHeader tuple = htup->t_data; @@ -1683,7 +1676,6 @@ HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, TransactionId xmax = HeapTupleHeaderGetRawXmax(tuple); Assert(ItemPointerIsValid(&htup->t_self)); - Assert(htup->t_tableOid != InvalidOid); /* inserting transaction aborted */ if (HeapTupleHeaderXminInvalid(tuple)) @@ -1704,7 +1696,7 @@ HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, * values externally. */ resolved = ResolveCminCmaxDuringDecoding(HistoricSnapshotGetTupleCids(), snapshot, - htup, buffer, + htup, relid, buffer, &cmin, &cmax); if (!resolved) @@ -1775,7 +1767,7 @@ HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, /* Lookup actual cmin/cmax values */ resolved = ResolveCminCmaxDuringDecoding(HistoricSnapshotGetTupleCids(), snapshot, - htup, buffer, + htup, relid, buffer, &cmin, &cmax); if (!resolved) @@ -1813,8 +1805,10 @@ HeapTupleSatisfiesHistoricMVCC(HeapTuple htup, Snapshot snapshot, } bool -HeapTupleSatisfies(HeapTuple stup, Snapshot snapshot, Buffer buffer) +HeapTupleSatisfies(HeapTuple stup, Oid relid, Snapshot snapshot, Buffer buffer) { + Assert(relid != InvalidOid); + switch (snapshot->visibility_type) { case MVCC_VISIBILITY: @@ -1833,7 +1827,7 @@ HeapTupleSatisfies(HeapTuple stup, Snapshot snapshot, Buffer buffer) return HeapTupleSatisfiesDirty(stup, snapshot, buffer); break; case HISTORIC_MVCC_VISIBILITY: - return HeapTupleSatisfiesHistoricMVCC(stup, snapshot, buffer); + return HeapTupleSatisfiesHistoricMVCC(stup, relid, snapshot, buffer); break; case NON_VACUUMABLE_VISIBILTY: return HeapTupleSatisfiesNonVacuumable(stup, snapshot, buffer); diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index c2f5343dac..79964e157a 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -367,8 +367,6 @@ heap_prune_chain(Relation relation, Buffer buffer, OffsetNumber rootoffnum, i; HeapTupleData tup; - tup.t_tableOid = RelationGetRelid(relation); - rootlp = PageGetItemId(dp, rootoffnum); /* diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index 486cde4aff..5349dbf805 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -1023,7 +1023,6 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, result_tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + new_tuple_len); result_tuple->t_len = new_tuple_len; result_tuple->t_self = newtup->t_self; - result_tuple->t_tableOid = newtup->t_tableOid; new_data = (HeapTupleHeader) ((char *) result_tuple + HEAPTUPLESIZE); result_tuple->t_data = new_data; @@ -1124,7 +1123,6 @@ toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc) * a syscache entry. */ new_tuple->t_self = tup->t_self; - new_tuple->t_tableOid = tup->t_tableOid; new_tuple->t_data->t_choice = tup->t_data->t_choice; new_tuple->t_data->t_ctid = tup->t_data->t_ctid; @@ -1195,7 +1193,6 @@ toast_flatten_tuple_to_datum(HeapTupleHeader tup, /* Build a temporary HeapTuple control structure */ tmptup.t_len = tup_len; ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = tup; /* diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c index 429f9ad52a..87589a927e 100644 --- a/src/backend/access/heap/vacuumlazy.c +++ b/src/backend/access/heap/vacuumlazy.c @@ -1004,7 +1004,6 @@ lazy_scan_heap(Relation onerel, int options, LVRelStats *vacrelstats, tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid); tuple.t_len = ItemIdGetLength(itemid); - tuple.t_tableOid = RelationGetRelid(onerel); tupgone = false; @@ -2238,7 +2237,6 @@ heap_page_is_all_visible(Relation rel, Buffer buf, tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid); tuple.t_len = ItemIdGetLength(itemid); - tuple.t_tableOid = RelationGetRelid(rel); switch (HeapTupleSatisfiesVacuum(&tuple, OldestXmin, buf)) { diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index 5f033c5ee4..02afc191b6 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -462,7 +462,7 @@ systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup) Assert(BufferIsValid(hscan->xs_cbuf)); /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ LockBuffer(hscan->xs_cbuf, BUFFER_LOCK_SHARE); - result = HeapTupleSatisfies(tup, freshsnap, hscan->xs_cbuf); + result = HeapTupleSatisfies(tup, RelationGetRelid(sysscan->heap_rel), freshsnap, hscan->xs_cbuf); LockBuffer(hscan->xs_cbuf, BUFFER_LOCK_UNLOCK); } else @@ -474,7 +474,7 @@ systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup) Assert(BufferIsValid(scan->rs_cbuf)); /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE); - result = HeapTupleSatisfies(tup, freshsnap, scan->rs_cbuf); + result = HeapTupleSatisfies(tup, RelationGetRelid(sysscan->heap_rel), freshsnap, scan->rs_cbuf); LockBuffer(scan->rs_cbuf, BUFFER_LOCK_UNLOCK); } return result; diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index 52a2ccb40f..88b8df0b7a 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -97,7 +97,7 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple) /* Need a slot to hold the tuple being examined */ slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation), &TTSOpsHeapTuple); - ExecStoreHeapTuple(heapTuple, slot, false); + ExecStoreHeapTuple(heapTuple, slot, RelationGetRelid(heapRelation), false); /* * for each index, form and insert the index tuple diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 29e2377b52..b2697dae44 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -758,7 +758,7 @@ compute_index_stats(Relation onerel, double totalrows, ResetExprContext(econtext); /* Set up for predicate or expression evaluation */ - ExecStoreHeapTuple(heapTuple, slot, false); + ExecStoreHeapTuple(heapTuple, slot, RelationGetRelid(onerel), false); /* If index is partial, check predicate */ if (predicate != NULL) diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index ebece4d1d7..a9f7d55940 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -2360,10 +2360,9 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver rettupdata.t_len = HeapTupleHeaderGetDatumLength(td); ItemPointerSetInvalid(&(rettupdata.t_self)); - rettupdata.t_tableOid = InvalidOid; rettupdata.t_data = td; - slot = ExecStoreHeapTuple(&rettupdata, tstate->slot, false); + slot = ExecStoreHeapTuple(&rettupdata, tstate->slot, InvalidOid, false); tstate->dest->receiveSlot(slot, tstate->dest); end_tup_output(tstate); diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index f0ebe2d1c3..ba31f46019 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -355,7 +355,6 @@ AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId) { Form_pg_namespace nspForm; - Assert(tup->t_tableOid == NamespaceRelationId); Assert(RelationGetRelid(rel) == NamespaceRelationId); nspForm = (Form_pg_namespace) GETSTRUCT(tup); diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 6a00a96f59..313222008d 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -2573,7 +2573,7 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo, } if (newtuple != oldtuple) { - ExecForceStoreHeapTuple(newtuple, slot); + ExecForceStoreHeapTuple(newtuple, slot, RelationGetRelid(relinfo->ri_RelationDesc)); newtuple = ExecFetchSlotHeapTuple(slot, true, NULL); } } @@ -2653,7 +2653,8 @@ ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo, } if (oldtuple != newtuple) { - ExecForceStoreHeapTuple(newtuple, LocTriggerData.tg_trigslot); + ExecForceStoreHeapTuple(newtuple, LocTriggerData.tg_trigslot, + RelationGetRelid(relinfo->ri_RelationDesc)); newtuple = ExecFetchSlotHeapTuple(slot, true, NULL); } } @@ -2777,7 +2778,7 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate, else { trigtuple = fdw_trigtuple; - ExecForceStoreHeapTuple(trigtuple, slot); + ExecForceStoreHeapTuple(trigtuple, slot, RelationGetRelid(relinfo->ri_RelationDesc)); } LocTriggerData.type = T_TriggerData; @@ -2854,7 +2855,7 @@ ExecARDeleteTriggers(EState *estate, ResultRelInfo *relinfo, } else { - ExecForceStoreHeapTuple(fdw_trigtuple, slot); + ExecForceStoreHeapTuple(fdw_trigtuple, slot, RelationGetRelid(relinfo->ri_RelationDesc)); } AfterTriggerSaveEvent(estate, relinfo, TRIGGER_EVENT_DELETE, @@ -2884,7 +2885,7 @@ ExecIRDeleteTriggers(EState *estate, ResultRelInfo *relinfo, LocTriggerData.tg_oldtable = NULL; LocTriggerData.tg_newtable = NULL; - ExecForceStoreHeapTuple(trigtuple, slot); + ExecForceStoreHeapTuple(trigtuple, slot, RelationGetRelid(relinfo->ri_RelationDesc)); for (i = 0; i < trigdesc->numtriggers; i++) { @@ -3044,7 +3045,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate, } else { - ExecForceStoreHeapTuple(fdw_trigtuple, oldslot); + ExecForceStoreHeapTuple(fdw_trigtuple, oldslot, RelationGetRelid(relinfo->ri_RelationDesc)); trigtuple = fdw_trigtuple; } @@ -3090,7 +3091,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate, } if (newtuple != oldtuple) - ExecForceStoreHeapTuple(newtuple, newslot); + ExecForceStoreHeapTuple(newtuple, newslot, RelationGetRelid(relinfo->ri_RelationDesc)); } if (false && trigtuple != fdw_trigtuple && trigtuple != newtuple) heap_freetuple(trigtuple); @@ -3132,7 +3133,7 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, NULL, NULL); else if (fdw_trigtuple != NULL) - ExecForceStoreHeapTuple(fdw_trigtuple, oldslot); + ExecForceStoreHeapTuple(fdw_trigtuple, oldslot, RelationGetRelid(relinfo->ri_RelationDesc)); AfterTriggerSaveEvent(estate, relinfo, TRIGGER_EVENT_UPDATE, true, oldslot, newslot, recheckIndexes, @@ -3161,7 +3162,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo, LocTriggerData.tg_oldtable = NULL; LocTriggerData.tg_newtable = NULL; - ExecForceStoreHeapTuple(trigtuple, oldslot); + ExecForceStoreHeapTuple(trigtuple, oldslot, RelationGetRelid(relinfo->ri_RelationDesc)); for (i = 0; i < trigdesc->numtriggers; i++) { @@ -3193,7 +3194,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo, return false; /* "do nothing" */ if (oldtuple != newtuple) - ExecForceStoreHeapTuple(newtuple, newslot); + ExecForceStoreHeapTuple(newtuple, newslot, RelationGetRelid(relinfo->ri_RelationDesc)); } return true; diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 6cac1cf99c..b2a70bc07d 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -3004,7 +3004,6 @@ ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op, ExprContext *econte tuphdr = DatumGetHeapTupleHeader(tupDatum); tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr); ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = tuphdr; heap_deform_tuple(&tmptup, tupDesc, diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index d91a71a7c1..ac8e8dc8cd 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -383,7 +383,7 @@ tts_heap_copyslot(TupleTableSlot *dstslot, TupleTableSlot *srcslot) tuple = ExecCopySlotHeapTuple(srcslot); MemoryContextSwitchTo(oldcontext); - ExecStoreHeapTuple(tuple, dstslot, true); + ExecStoreHeapTuple(tuple, dstslot, srcslot->tts_tableOid, true); } static HeapTuple @@ -1126,6 +1126,7 @@ MakeTupleTableSlot(TupleDesc tupleDesc, slot->tts_tupleDescriptor = tupleDesc; slot->tts_mcxt = CurrentMemoryContext; slot->tts_nvalid = 0; + slot->tts_tableOid = InvalidOid; if (tupleDesc != NULL) { @@ -1388,6 +1389,7 @@ ExecSetSlotDescriptor(TupleTableSlot *slot, /* slot to change */ TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, + Oid relid, bool shouldFree) { /* @@ -1405,7 +1407,7 @@ ExecStoreHeapTuple(HeapTuple tuple, else elog(ERROR, "trying to store a heap tuple into wrong type of slot"); - slot->tts_tableOid = tuple->t_tableOid; + slot->tts_tableOid = relid; return slot; } @@ -1446,8 +1448,6 @@ ExecStoreBufferHeapTuple(HeapTuple tuple, elog(ERROR, "trying to store an on-disk heap tuple into wrong type of slot"); tts_buffer_heap_store_tuple(slot, tuple, buffer); - slot->tts_tableOid = tuple->t_tableOid; - return slot; } @@ -1482,11 +1482,12 @@ ExecStoreMinimalTuple(MinimalTuple mtup, */ void ExecForceStoreHeapTuple(HeapTuple tuple, - TupleTableSlot *slot) + TupleTableSlot *slot, + Oid relid) { if (TTS_IS_HEAPTUPLE(slot)) { - ExecStoreHeapTuple(tuple, slot, false); + ExecStoreHeapTuple(tuple, slot, relid, false); } else if (TTS_IS_BUFFERTUPLE(slot)) { @@ -1499,6 +1500,7 @@ ExecForceStoreHeapTuple(HeapTuple tuple, oldContext = MemoryContextSwitchTo(slot->tts_mcxt); bslot->base.tuple = heap_copytuple(tuple); MemoryContextSwitchTo(oldContext); + slot->tts_tableOid = relid; } else { @@ -1506,6 +1508,7 @@ ExecForceStoreHeapTuple(HeapTuple tuple, heap_deform_tuple(tuple, slot->tts_tupleDescriptor, slot->tts_values, slot->tts_isnull); ExecStoreVirtualTuple(slot); + slot->tts_tableOid = relid; } } @@ -1639,6 +1642,8 @@ ExecStoreAllNullTuple(TupleTableSlot *slot) HeapTuple ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree) { + HeapTuple htup; + /* * sanity checks */ @@ -1653,14 +1658,18 @@ ExecFetchSlotHeapTuple(TupleTableSlot *slot, bool materialize, bool *shouldFree) { if (shouldFree) *shouldFree = true; - return slot->tts_ops->copy_heap_tuple(slot); + htup = slot->tts_ops->copy_heap_tuple(slot); } else { if (shouldFree) *shouldFree = false; - return slot->tts_ops->get_heap_tuple(slot); + htup = slot->tts_ops->get_heap_tuple(slot); } + + htup->t_tableOid = slot->tts_tableOid; + + return htup; } /* -------------------------------- diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 4031642b80..db2020bd0d 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -1070,7 +1070,6 @@ GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull) */ tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple); ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = tuple; result = heap_getattr(&tmptup, @@ -1118,7 +1117,6 @@ GetAttributeByNum(HeapTupleHeader tuple, */ tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple); ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = tuple; result = heap_getattr(&tmptup, diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index daf56cd3d1..ced48bb791 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -1801,7 +1801,8 @@ agg_retrieve_direct(AggState *aggstate) * cleared from the slot. */ ExecForceStoreHeapTuple(aggstate->grp_firstTuple, - firstSlot); + firstSlot, + InvalidOid); aggstate->grp_firstTuple = NULL; /* don't keep two pointers */ /* set up for first advance_aggregates call */ diff --git a/src/backend/executor/nodeGather.c b/src/backend/executor/nodeGather.c index 1dd8bb3f3a..1d4d79a3ab 100644 --- a/src/backend/executor/nodeGather.c +++ b/src/backend/executor/nodeGather.c @@ -280,6 +280,7 @@ gather_getnext(GatherState *gatherstate) { ExecStoreHeapTuple(tup, /* tuple to store */ fslot, /* slot to store the tuple */ + InvalidOid, true); /* pfree tuple when done with it */ return fslot; } diff --git a/src/backend/executor/nodeGatherMerge.c b/src/backend/executor/nodeGatherMerge.c index 54ef0ca7b7..73625965b2 100644 --- a/src/backend/executor/nodeGatherMerge.c +++ b/src/backend/executor/nodeGatherMerge.c @@ -703,6 +703,7 @@ gather_merge_readnext(GatherMergeState *gm_state, int reader, bool nowait) ExecStoreHeapTuple(tup, /* tuple to store */ gm_state->gm_slots[reader], /* slot in which to store * the tuple */ + InvalidOid, true); /* pfree tuple when done with it */ return true; diff --git a/src/backend/executor/nodeIndexonlyscan.c b/src/backend/executor/nodeIndexonlyscan.c index c39c4f453d..3c51c4f635 100644 --- a/src/backend/executor/nodeIndexonlyscan.c +++ b/src/backend/executor/nodeIndexonlyscan.c @@ -203,8 +203,8 @@ IndexOnlyNext(IndexOnlyScanState *node) */ Assert(slot->tts_tupleDescriptor->natts == scandesc->xs_hitupdesc->natts); - ExecForceStoreHeapTuple(scandesc->xs_hitup, slot); - slot->tts_tableOid = RelationGetRelid(scandesc->heapRelation); + ExecForceStoreHeapTuple(scandesc->xs_hitup, slot, + RelationGetRelid(scandesc->heapRelation)); } else if (scandesc->xs_itup) StoreIndexTuple(slot, scandesc->xs_itup, scandesc->xs_itupdesc); diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index b38dadaa9a..28b3bdb4d4 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -247,8 +247,7 @@ IndexNextWithReorder(IndexScanState *node) tuple = reorderqueue_pop(node); /* Pass 'true', as the tuple in the queue is a palloc'd copy */ - slot->tts_tableOid = RelationGetRelid(scandesc->heapRelation); - ExecStoreHeapTuple(tuple, slot, true); + ExecStoreHeapTuple(tuple, slot, RelationGetRelid(scandesc->heapRelation), true); return slot; } } diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index d1ac9fc2e9..8aa7501830 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -842,7 +842,7 @@ ldelete:; slot = ExecTriggerGetReturnSlot(estate, resultRelationDesc); if (oldtuple != NULL) { - ExecForceStoreHeapTuple(oldtuple, slot); + ExecForceStoreHeapTuple(oldtuple, slot, RelationGetRelid(resultRelationDesc)); } else { @@ -2035,10 +2035,6 @@ ExecModifyTable(PlanState *pstate) oldtupdata.t_len = HeapTupleHeaderGetDatumLength(oldtupdata.t_data); ItemPointerSetInvalid(&(oldtupdata.t_self)); - /* Historically, view triggers see invalid t_tableOid. */ - oldtupdata.t_tableOid = - (relkind == RELKIND_VIEW) ? InvalidOid : - RelationGetRelid(resultRelInfo->ri_RelationDesc); oldtuple = &oldtupdata; } diff --git a/src/backend/executor/nodeSetOp.c b/src/backend/executor/nodeSetOp.c index 48b7aa9b8b..4f7da00d82 100644 --- a/src/backend/executor/nodeSetOp.c +++ b/src/backend/executor/nodeSetOp.c @@ -269,6 +269,7 @@ setop_retrieve_direct(SetOpState *setopstate) */ ExecStoreHeapTuple(setopstate->grp_firstTuple, resultTupleSlot, + InvalidOid, true); setopstate->grp_firstTuple = NULL; /* don't keep two pointers */ diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 34664e76d1..d9398ed527 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -870,7 +870,6 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, */ mtuple->t_data->t_ctid = tuple->t_data->t_ctid; mtuple->t_self = tuple->t_self; - mtuple->t_tableOid = tuple->t_tableOid; } else { diff --git a/src/backend/executor/tqueue.c b/src/backend/executor/tqueue.c index e2b596cf74..d3ef18e264 100644 --- a/src/backend/executor/tqueue.c +++ b/src/backend/executor/tqueue.c @@ -206,7 +206,6 @@ TupleQueueReaderNext(TupleQueueReader *reader, bool nowait, bool *done) * (which had better be sufficiently aligned). */ ItemPointerSetInvalid(&htup.t_self); - htup.t_tableOid = InvalidOid; htup.t_len = nbytes; htup.t_data = data; diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c index e3b05657f8..a3430e1336 100644 --- a/src/backend/replication/logical/decode.c +++ b/src/backend/replication/logical/decode.c @@ -940,12 +940,6 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf) /* not a disk based tuple */ ItemPointerSetInvalid(&tuple->tuple.t_self); - /* - * We can only figure this out after reassembling the - * transactions. - */ - tuple->tuple.t_tableOid = InvalidOid; - tuple->tuple.t_len = datalen + SizeofHeapTupleHeader; memset(header, 0, SizeofHeapTupleHeader); @@ -1033,9 +1027,6 @@ DecodeXLogTuple(char *data, Size len, ReorderBufferTupleBuf *tuple) /* not a disk based tuple */ ItemPointerSetInvalid(&tuple->tuple.t_self); - /* we can only figure this out after reassembling the transactions */ - tuple->tuple.t_tableOid = InvalidOid; - /* data is not stored aligned, copy to aligned storage */ memcpy((char *) &xlhdr, data, diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 23466bade2..60ee12b91a 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -3482,7 +3482,7 @@ UpdateLogicalMappings(HTAB *tuplecid_data, Oid relid, Snapshot snapshot) bool ResolveCminCmaxDuringDecoding(HTAB *tuplecid_data, Snapshot snapshot, - HeapTuple htup, Buffer buffer, + HeapTuple htup, Oid relid, Buffer buffer, CommandId *cmin, CommandId *cmax) { ReorderBufferTupleCidKey key; @@ -3524,7 +3524,7 @@ restart: */ if (ent == NULL && !updated_mapping) { - UpdateLogicalMappings(tuplecid_data, htup->t_tableOid, snapshot); + UpdateLogicalMappings(tuplecid_data, relid, snapshot); /* now check but don't update for a mapping again */ updated_mapping = true; goto restart; diff --git a/src/backend/utils/adt/expandedrecord.c b/src/backend/utils/adt/expandedrecord.c index 5561b741e9..fbf26b0891 100644 --- a/src/backend/utils/adt/expandedrecord.c +++ b/src/backend/utils/adt/expandedrecord.c @@ -610,7 +610,6 @@ make_expanded_record_from_datum(Datum recorddatum, MemoryContext parentcontext) tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr); ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = tuphdr; oldcxt = MemoryContextSwitchTo(objcxt); diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index fc1581c92b..5fe0659dcf 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -3147,7 +3147,6 @@ populate_record(TupleDesc tupdesc, /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(defaultval); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = defaultval; /* Break down the tuple into fields */ @@ -3546,7 +3545,6 @@ populate_recordset_record(PopulateRecordsetState *state, JsObject *obj) /* ok, save into tuplestore */ tuple.t_len = HeapTupleHeaderGetDatumLength(tuphead); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = tuphead; tuplestore_puttuple(state->tuple_store, &tuple); diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c index 5f729342f8..060ee6c6ca 100644 --- a/src/backend/utils/adt/rowtypes.c +++ b/src/backend/utils/adt/rowtypes.c @@ -324,7 +324,6 @@ record_out(PG_FUNCTION_ARGS) /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(rec); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = rec; /* @@ -671,7 +670,6 @@ record_send(PG_FUNCTION_ARGS) /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(rec); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = rec; /* @@ -821,11 +819,9 @@ record_cmp(FunctionCallInfo fcinfo) /* Build temporary HeapTuple control structures */ tuple1.t_len = HeapTupleHeaderGetDatumLength(record1); ItemPointerSetInvalid(&(tuple1.t_self)); - tuple1.t_tableOid = InvalidOid; tuple1.t_data = record1; tuple2.t_len = HeapTupleHeaderGetDatumLength(record2); ItemPointerSetInvalid(&(tuple2.t_self)); - tuple2.t_tableOid = InvalidOid; tuple2.t_data = record2; /* @@ -1063,11 +1059,9 @@ record_eq(PG_FUNCTION_ARGS) /* Build temporary HeapTuple control structures */ tuple1.t_len = HeapTupleHeaderGetDatumLength(record1); ItemPointerSetInvalid(&(tuple1.t_self)); - tuple1.t_tableOid = InvalidOid; tuple1.t_data = record1; tuple2.t_len = HeapTupleHeaderGetDatumLength(record2); ItemPointerSetInvalid(&(tuple2.t_self)); - tuple2.t_tableOid = InvalidOid; tuple2.t_data = record2; /* @@ -1326,11 +1320,9 @@ record_image_cmp(FunctionCallInfo fcinfo) /* Build temporary HeapTuple control structures */ tuple1.t_len = HeapTupleHeaderGetDatumLength(record1); ItemPointerSetInvalid(&(tuple1.t_self)); - tuple1.t_tableOid = InvalidOid; tuple1.t_data = record1; tuple2.t_len = HeapTupleHeaderGetDatumLength(record2); ItemPointerSetInvalid(&(tuple2.t_self)); - tuple2.t_tableOid = InvalidOid; tuple2.t_data = record2; /* @@ -1570,11 +1562,9 @@ record_image_eq(PG_FUNCTION_ARGS) /* Build temporary HeapTuple control structures */ tuple1.t_len = HeapTupleHeaderGetDatumLength(record1); ItemPointerSetInvalid(&(tuple1.t_self)); - tuple1.t_tableOid = InvalidOid; tuple1.t_data = record1; tuple2.t_len = HeapTupleHeaderGetDatumLength(record2); ItemPointerSetInvalid(&(tuple2.t_self)); - tuple2.t_tableOid = InvalidOid; tuple2.t_data = record2; /* diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index b31fd5acea..7bf2f4617f 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -1846,7 +1846,6 @@ CatalogCacheCreateEntry(CatCache *cache, HeapTuple ntp, Datum *arguments, MAXIMUM_ALIGNOF + dtp->t_len); ct->tuple.t_len = dtp->t_len; ct->tuple.t_self = dtp->t_self; - ct->tuple.t_tableOid = dtp->t_tableOid; ct->tuple.t_data = (HeapTupleHeader) MAXALIGN(((char *) ct) + sizeof(CatCTup)); /* copy tuple contents */ diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 7d2b6facf2..3bd8cde14b 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -3792,11 +3792,11 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b, ecxt_scantuple = GetPerTupleExprContext(state->estate)->ecxt_scantuple; - ExecStoreHeapTuple(ltup, ecxt_scantuple, false); + ExecStoreHeapTuple(ltup, ecxt_scantuple, InvalidOid, false); FormIndexDatum(state->indexInfo, ecxt_scantuple, state->estate, l_index_values, l_index_isnull); - ExecStoreHeapTuple(rtup, ecxt_scantuple, false); + ExecStoreHeapTuple(rtup, ecxt_scantuple, InvalidOid, false); FormIndexDatum(state->indexInfo, ecxt_scantuple, state->estate, r_index_values, r_index_isnull); @@ -3926,8 +3926,7 @@ readtup_cluster(Tuplesortstate *state, SortTuple *stup, tuple->t_len = t_len; LogicalTapeReadExact(state->tapeset, tapenum, &tuple->t_self, sizeof(ItemPointerData)); - /* We don't currently bother to reconstruct t_tableOid */ - tuple->t_tableOid = InvalidOid; + /* Read in the tuple body */ LogicalTapeReadExact(state->tapeset, tapenum, tuple->t_data, tuple->t_len); diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index a309db1a1c..8dc1880925 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -218,7 +218,7 @@ extern void heap_vacuum_rel(Relation onerel, int options, struct VacuumParams *params, BufferAccessStrategy bstrategy); /* in heap/heapam_visibility.c */ -extern bool HeapTupleSatisfies(HeapTuple stup, Snapshot snapshot, Buffer buffer); +extern bool HeapTupleSatisfies(HeapTuple stup, Oid relid, Snapshot snapshot, Buffer buffer); extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple stup, CommandId curcid, Buffer buffer); extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin, diff --git a/src/include/executor/tuptable.h b/src/include/executor/tuptable.h index c87689b3dd..b1d69ab5ea 100644 --- a/src/include/executor/tuptable.h +++ b/src/include/executor/tuptable.h @@ -306,9 +306,8 @@ extern TupleTableSlot *MakeSingleTupleTableSlot(TupleDesc tupdesc, extern void ExecDropSingleTupleTableSlot(TupleTableSlot *slot); extern void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc); extern TupleTableSlot *ExecStoreHeapTuple(HeapTuple tuple, - TupleTableSlot *slot, - bool shouldFree); -extern void ExecForceStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot); + TupleTableSlot *slot, Oid relid, bool shouldFree); +extern void ExecForceStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, Oid relid); /* FIXME: Remove */ extern void ExecForceStoreHeapTupleDatum(Datum data, TupleTableSlot *slot); extern TupleTableSlot *ExecStoreBufferHeapTuple(HeapTuple tuple, diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index 1fe9cc6402..ccd81dff39 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -39,6 +39,7 @@ struct HTAB; extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data, Snapshot snapshot, HeapTuple htup, + Oid relid, Buffer buffer, CommandId *cmin, CommandId *cmax); diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 1e0617322b..efce063ecd 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -7234,7 +7234,6 @@ deconstruct_composite_datum(Datum value, HeapTupleData *tmptup) /* Build a temporary HeapTuple control structure */ tmptup->t_len = HeapTupleHeaderGetDatumLength(td); ItemPointerSetInvalid(&(tmptup->t_self)); - tmptup->t_tableOid = InvalidOid; tmptup->t_data = td; /* Extract rowtype info and find a tupdesc */ @@ -7403,7 +7402,6 @@ exec_move_row_from_datum(PLpgSQL_execstate *estate, /* Build a temporary HeapTuple control structure */ tmptup.t_len = HeapTupleHeaderGetDatumLength(td); ItemPointerSetInvalid(&(tmptup.t_self)); - tmptup.t_tableOid = InvalidOid; tmptup.t_data = td; /* Extract rowtype info */ diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index a2e57768d4..76dff2a51d 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -524,7 +524,6 @@ make_tuple_indirect(PG_FUNCTION_ARGS) /* Build a temporary HeapTuple control structure */ tuple.t_len = HeapTupleHeaderGetDatumLength(rec); ItemPointerSetInvalid(&(tuple.t_self)); - tuple.t_tableOid = InvalidOid; tuple.t_data = rec; values = (Datum *) palloc(ncolumns * sizeof(Datum)); -- 2.18.0.windows.1