[HACKERS] Does having a NULL column automatically exclude the table from thetupleDesc cache? - Mailing list pgsql-hackers

From Ryan Murphy
Subject [HACKERS] Does having a NULL column automatically exclude the table from thetupleDesc cache?
Date
Msg-id CAHeEsBcw6JcGzh6zKqcVJCi-UUAV815AvZr=3tx_kMYNr+s+HA@mail.gmail.com
Whole thread Raw
Responses Re: [HACKERS] Does having a NULL column automatically exclude the table from the tupleDesc cache?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Parallel bitmap heap scan
Next
From: Peter Eisentraut
Date:
Subject: [HACKERS] error handling in RegisterBackgroundWorker