GP/PG从MinimalTuple转换TupleTableSlot需要理解的数据结构

2022-06-21 15:53:35 浏览数 (1)

比如在排序中,待排序的结构SortTuple中存储的是MinimalTupleData,里面包含有排序需要的值等信息。排好序后,需要将MinimalTupleData再此转换成TupleTableSlot。

转换由函数tts_minimal_store_tuple完成,可以看到MinimalTupleData并没有解析,而是直接放到了MinimalTupleTableSlot的HeapTuple中。

代码语言:javascript复制
tts_minimal_store_tuple(TupleTableSlot *slot, MinimalTuple mtup, bool shouldFree)
{
  MinimalTupleTableSlot *mslot = (MinimalTupleTableSlot *) slot;
  tts_minimal_clear(slot);
  slot->tts_flags &= ~TTS_FLAG_EMPTY;
  slot->tts_nvalid = 0;
  mslot->off = 0;

  mslot->mintuple = mtup;
  Assert(mslot->tuple == &mslot->minhdr);
  mslot->minhdr.t_len = mtup->t_len   MINIMAL_TUPLE_OFFSET;
  mslot->minhdr.t_data = (HeapTupleHeader) ((char *) mtup - MINIMAL_TUPLE_OFFSET);
  /* no need to set t_self or t_tableOid since we won't allow access */

  if (shouldFree)
    slot->tts_flags |= TTS_FLAG_SHOULDFREE;
  else
    Assert(!TTS_SHOULDFREE(slot));
}

访问行记录值是,需要再将从MinimalTupleData中将列值读取出来,放到TupleTableSlot的tts_values和tts_isnull数组中。这个过程由函数tts_minimal_getsomeattrs完成:

代码语言:javascript复制
static void
tts_minimal_getsomeattrs(TupleTableSlot *slot, int natts)
{
  MinimalTupleTableSlot *mslot = (MinimalTupleTableSlot *) slot;
  slot_deform_heap_tuple(slot, mslot->tuple, &mslot->off, natts);
}

重点在slot_deform_heap_tuple函数。

0 人点赞