Refactor attribute map in Arrow slot

Refactor the function to get the attribute offset map in
ArrowTupleTableSlot so that it has an inlined fast path and a slow
path that initializes the map during the first call. After
initalization, the fast path simply returns the map.
This commit is contained in:
Erik Nordström 2024-08-27 12:12:43 +02:00 committed by Mats Kindahl
parent 09e5aee285
commit 3e0daf6ad4
2 changed files with 9 additions and 5 deletions

View File

@ -36,15 +36,14 @@ tsl_is_compressed_tid(PG_FUNCTION_ARGS)
* relation compared to the regular one. * relation compared to the regular one.
*/ */
const int16 * const int16 *
arrow_slot_get_attribute_offset_map(TupleTableSlot *slot) arrow_slot_get_attribute_offset_map_slow(TupleTableSlot *slot)
{ {
ArrowTupleTableSlot *aslot = (ArrowTupleTableSlot *) slot; ArrowTupleTableSlot *aslot = (ArrowTupleTableSlot *) slot;
const TupleDesc tupdesc = slot->tts_tupleDescriptor; const TupleDesc tupdesc = slot->tts_tupleDescriptor;
Oid relid = Oid relid =
OidIsValid(slot->tts_tableOid) ? slot->tts_tableOid : TupleDescAttr(tupdesc, 0)->attrelid; OidIsValid(slot->tts_tableOid) ? slot->tts_tableOid : TupleDescAttr(tupdesc, 0)->attrelid;
if (aslot->attrs_offset_map) Assert(aslot->attrs_offset_map == NULL);
return aslot->attrs_offset_map;
Ensure(OidIsValid(relid), "invalid relation for ArrowTupleTableSlot"); Ensure(OidIsValid(relid), "invalid relation for ArrowTupleTableSlot");

View File

@ -82,7 +82,13 @@ typedef struct ArrowTupleTableSlot
extern const TupleTableSlotOps TTSOpsArrowTuple; extern const TupleTableSlotOps TTSOpsArrowTuple;
extern const int16 *arrow_slot_get_attribute_offset_map(TupleTableSlot *slot); extern const int16 *arrow_slot_get_attribute_offset_map_slow(TupleTableSlot *slot);
#define arrow_slot_get_attribute_offset_map(slot) \
((ArrowTupleTableSlot *) slot)->attrs_offset_map ? \
((ArrowTupleTableSlot *) slot)->attrs_offset_map : \
arrow_slot_get_attribute_offset_map_slow(slot)
extern TupleTableSlot *ExecStoreArrowTuple(TupleTableSlot *slot, uint16 tuple_index); extern TupleTableSlot *ExecStoreArrowTuple(TupleTableSlot *slot, uint16 tuple_index);
#define TTS_IS_ARROWTUPLE(slot) ((slot)->tts_ops == &TTSOpsArrowTuple) #define TTS_IS_ARROWTUPLE(slot) ((slot)->tts_ops == &TTSOpsArrowTuple)
@ -321,7 +327,6 @@ ExecDecrArrowTuple(TupleTableSlot *slot, uint16 decrement)
#define ExecStoreNextArrowTuple(slot) ExecIncrArrowTuple(slot, 1) #define ExecStoreNextArrowTuple(slot) ExecIncrArrowTuple(slot, 1)
#define ExecStorePreviousArrowTuple(slot) ExecDecrArrowTuple(slot, 1) #define ExecStorePreviousArrowTuple(slot) ExecDecrArrowTuple(slot, 1)
extern const int16 *arrow_slot_get_attribute_offset_map(TupleTableSlot *slot);
extern bool is_compressed_col(const TupleDesc tupdesc, AttrNumber attno); extern bool is_compressed_col(const TupleDesc tupdesc, AttrNumber attno);
extern const ArrowArray *arrow_slot_get_array(TupleTableSlot *slot, AttrNumber attno); extern const ArrowArray *arrow_slot_get_array(TupleTableSlot *slot, AttrNumber attno);
extern void arrow_slot_set_referenced_attrs(TupleTableSlot *slot, Bitmapset *attrs); extern void arrow_slot_set_referenced_attrs(TupleTableSlot *slot, Bitmapset *attrs);