Hi all, I was looking through some of the implementation details of the heap/tuples, specifically src/include/access/htup_details.h - and I came across the big macro fastgetattr, and had a question about it. I've included the code here for clarity and convenience:
#define fastgetattr(tup, attnum, tupleDesc, isnull) \ ( \ AssertMacro((attnum) > 0), \ (*(isnull) = false), \ HeapTupleNoNulls(tup) ? \ ( \ (tupleDesc)->attrs[(attnum)-1]->attcacheoff >= 0 ? \ ( \ fetchatt((tupleDesc)->attrs[(attnum)-1], \ (char *) (tup)->t_data + (tup)->t_data->t_hoff + \ (tupleDesc)->attrs[(attnum)-1]->attcacheoff) \ ) \ : \ nocachegetattr((tup), (attnum), (tupleDesc)) \ ) \ : \ ( \ att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \ ( \ (*(isnull) = true), \ (Datum)NULL \ ) \ : \ ( \ nocachegetattr((tup), (attnum), (tupleDesc)) \ ) \ ) \ ) My question is this: HeapTupleNoNulls() is run first to see if there are any columns that can be NULL. It looks like the fetchatt() that uses the cache in the tupleDesc can only be used if there are no NULLable columns in the table. Is my understanding correct? Does this mean that there is significant performance gain by never allowing any column to be null in your table? Thanks! Ryan