postgresql-11.1\src\backend\access\common\heaptuple.c里的slot_getsomeattrs函数

This function forces the entries of the slot’s Datum/isnull

arrays to be valid at least up through the attnum’th entry

就是根据slot这个指针指向的东西,然后把号码小于等于attnum的列都扔到tts_value数组里面呗

void
slot_getsomeattrs(TupleTableSlot *slot, int attnum)
{
	HeapTuple	tuple;
	int			attno;

	/* Quick out if we have 'em all already */
	if (slot->tts_nvalid >= attnum)
		return;

	/* Check for caller error */
	if (attnum <= 0 || attnum > slot->tts_tupleDescriptor->natts)
		elog(ERROR, "invalid attribute number %d", attnum);

	/*
	 * otherwise we had better have a physical tuple (tts_nvalid should equal
	 * natts in all virtual-tuple cases)
	 */
	tuple = slot->tts_tuple;
	if (tuple == NULL)			/* internal error */
		elog(ERROR, "cannot extract attribute from empty tuple slot");

	/*
	 * load up any slots available from physical tuple
	 */
	attno = HeapTupleHeaderGetNatts(tuple->t_data);
	attno = Min(attno, attnum);

	slot_deform_tuple(slot, attno);

	attno = slot->tts_nvalid;

	/*
	 * If tuple doesn't have all the atts indicated by attnum, read the rest
	 * as NULLs or missing values
	 */
	if (attno < attnum)
		slot_getmissingattrs(slot, attno, attnum);

	slot->tts_nvalid = attnum;
}

猜你喜欢

转载自blog.csdn.net/zhoutianzi12/article/details/91828978