Open workingjubilee opened 8 months ago
This would also make it notably easier to add safe IndexAmRoutine helpers, which is a very common request. No promises about TableAmRoutine: that one is way more... freeform? in design.
I'm all for anything that makes working with the various tuple types easier and more obvious. I don't have any specific input on what you've laid out here, other than we'll need to make sure that all the various Postgres-internal functions that operate on tuples are properly exposed on the types as well.
And we'll always need the ability to go back to the original pointer.
An absolutely wild thing Postgres does is apparently just yielding MinimalTuple
sometimes when you expect a HeapTupleHeader
, because if you offset MinimalTuple
by the appropriate negative, you can access the HeapTupleHeaderData
fields, which are the same fields as in MinimalTupleData
.
Utterly cursed.
We must never allow ourselves to take a reference to HeapTupleHeaderData
.
Postgres has the following types:
struct HeapTupleData
, which includes a*mut HeapTupleHeaderData
which is eitherstruct MinimalTupleData
, which is astruct HeapTupleHeaderData
without either of thosestruct IndexTupleData
, which is a tuple but mostly of particular relevance to index access method extensionsAll of these work with certain macros in tupmacs.h and
struct TupleDescData
is relevant to all of them, because they all use a certain method of attribute retrieval. Code inside pgrx can and should describe a unifying abstraction that addresses all of these cases. The number of assumptions we can actually make are minimal, but we can describe bounds checks, null-value checking, and attr retrieval in a generic way.Aside: "HeapTuple" is a wild misnomer, as it can and does point to on-disk tuples, and some of the tuples you encounter during index handling are going to be HeapTuples instead of IndexTuples. It is tempting to name the types pgrx defines as
ITuple
andHTuple
for this reason.These notes fell mostly out of researching our PgHeapTuple implementation and how Postgres implements composite data types, which are a specific case of HTuple.