pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.55k stars 237 forks source link

Add `mod tuple;` #1464

Open workingjubilee opened 8 months ago

workingjubilee commented 8 months ago

Postgres has the following types:

All 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 and HTuple 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.

workingjubilee commented 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.

eeeebbbbrrrr commented 8 months ago

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.

workingjubilee commented 6 months ago

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.