diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/index/genam.c | 1 | ||||
-rw-r--r-- | src/backend/access/nbtree/nbtree.c | 5 | ||||
-rw-r--r-- | src/backend/executor/nodeIndexonlyscan.c | 16 |
3 files changed, 13 insertions, 9 deletions
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index 236e48912bb..1732ef7bfe5 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -112,6 +112,7 @@ RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys) scan->opaque = NULL; scan->xs_itup = NULL; + scan->xs_itupdesc = NULL; ItemPointerSetInvalid(&scan->xs_ctup.t_self); scan->xs_ctup.t_data = NULL; diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 60b7f599a74..f3a1d256a05 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -433,12 +433,15 @@ btbeginscan(PG_FUNCTION_ARGS) /* * We don't know yet whether the scan will be index-only, so we do not - * allocate the tuple workspace arrays until btrescan. + * allocate the tuple workspace arrays until btrescan. However, we set up + * scan->xs_itupdesc whether we'll need it or not, since that's so cheap. */ so->currTuples = so->markTuples = NULL; so->currPos.nextTupleOffset = 0; so->markPos.nextTupleOffset = 0; + scan->xs_itupdesc = RelationGetDescr(rel); + scan->opaque = so; PG_RETURN_POINTER(scan); diff --git a/src/backend/executor/nodeIndexonlyscan.c b/src/backend/executor/nodeIndexonlyscan.c index e3742cf71d0..a07686d4638 100644 --- a/src/backend/executor/nodeIndexonlyscan.c +++ b/src/backend/executor/nodeIndexonlyscan.c @@ -36,7 +36,7 @@ static TupleTableSlot *IndexOnlyNext(IndexOnlyScanState *node); static void StoreIndexTuple(TupleTableSlot *slot, IndexTuple itup, - Relation indexRel); + TupleDesc itupdesc); /* ---------------------------------------------------------------- @@ -114,7 +114,7 @@ IndexOnlyNext(IndexOnlyScanState *node) /* * Fill the scan tuple slot with data from the index. */ - StoreIndexTuple(slot, scandesc->xs_itup, scandesc->indexRelation); + StoreIndexTuple(slot, scandesc->xs_itup, scandesc->xs_itupdesc); /* * If the index was lossy, we have to recheck the index quals. @@ -151,25 +151,25 @@ IndexOnlyNext(IndexOnlyScanState *node) * right now we don't need it elsewhere. */ static void -StoreIndexTuple(TupleTableSlot *slot, IndexTuple itup, Relation indexRel) +StoreIndexTuple(TupleTableSlot *slot, IndexTuple itup, TupleDesc itupdesc) { - TupleDesc indexDesc = RelationGetDescr(indexRel); - int nindexatts = indexDesc->natts; + int nindexatts = itupdesc->natts; Datum *values = slot->tts_values; bool *isnull = slot->tts_isnull; int i; /* - * Note: we must use the index relation's tupdesc in index_getattr, not + * Note: we must use the tupdesc supplied by the AM in index_getattr, not * the slot's tupdesc, in case the latter has different datatypes (this * happens for btree name_ops in particular). They'd better have the same - * number of columns though. + * number of columns though, as well as being datatype-compatible which + * is something we can't so easily check. */ Assert(slot->tts_tupleDescriptor->natts == nindexatts); ExecClearTuple(slot); for (i = 0; i < nindexatts; i++) - values[i] = index_getattr(itup, i + 1, indexDesc, &isnull[i]); + values[i] = index_getattr(itup, i + 1, itupdesc, &isnull[i]); ExecStoreVirtualTuple(slot); } |