Datum as struct
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-07-31T14:02:35Z
Lists: pgsql-hackers
Attachments
- v1-0001-Fix-mixups-of-FooGetDatum-vs.-DatumGetFoo.patch (text/plain) patch v1-0001
- v1-0002-Remove-useless-superfluous-Datum-conversions.patch (text/plain) patch v1-0002
- v1-0003-Add-missing-Datum-conversions.patch (text/plain) patch v1-0003
- v1-0004-Fix-varatt-versus-Datum-type-confusions.patch (text/plain) patch v1-0004
- v1-0005-Fix-various-hash-function-uses.patch (text/plain) patch v1-0005
- v1-0006-WIP-Datum-as-struct.patch (text/plain) patch v1-0006
Another draft patch set that I had lying around that was mentioned in [0]. The idea is to change Datum to a struct so that you can no longer rely on it being implicitly convertable to other C types, which enforces use of proper DatumGet*() and *GetDatum() functions, which might ultimately help with portability and robustness and the like. (An alternative idea is to make Datum a union so that you don't need so many casts to begin with. But this has a lot of the same issues, so it can be considered implicitly here.) The first three patches clean up the use of the conversion functions. Some are missing, some are superfluous, some are used the wrong way around (!!). The fourth patch tidies up the use of varatt.h macros. These should arguably not be used on Datum values but instead be converted with DatumGetPointer(). This is very similar to the patch that I also included in the thread "Convert varatt.h macros to static inline functions" that I just posted. The fifth patch cleans up some untidy use of hash functions with the wrong argument type. The last patch is the actual conversion. As you can see there, and as was also mentioned in [0], it's quite a bit of churn. I'm not seriously proposing it at this point, but maybe it can serve as a guide for refactoring some of the interfaces to make the impact smaller, or something like that. But I think the patches 0001 through 0005 are useful now. I tested this against the original patch in [0]. It fixes some of the issues discussed there but not all of them. [0]: https://www.postgresql.org/message-id/flat/1749799.1752797397%40sss.pgh.pa.us
Commits
-
Use consistent type for pgaio_io_get_id() result
- b942360f82a0 18.0 landed
- 47932f3cdc4c 19 (unreleased) landed
-
Mop-up for Datum conversion cleanups.
- 665c3dbba497 19 (unreleased) landed
-
Add missing Datum conversions
- ff89e182d420 19 (unreleased) landed
-
Remove useless/superfluous Datum conversions
- dcfc0f891273 19 (unreleased) landed
-
Fix incorrect lack of Datum conversion in _int_matchsel()
- 387883f68c85 13.22 landed
- 64dec8060c84 14.19 landed
- f0d55b68ef92 15.14 landed
- a3906b44c5b9 16.10 landed
- 276cdd4cc378 17.6 landed
- 992a18f5161c 18.0 landed
- fd2ab03fea23 19 (unreleased) landed
-
Improve tests of date_trunc() with infinity and unsupported units
- 67ffe1987d0a 18.0 landed
- 572c0f1b0e2a 19 (unreleased) landed
-
Fix incorrect Datum conversion in timestamptz_trunc_internal()
- 074db8604ad1 18.0 landed
- 2242b26ce472 19 (unreleased) landed
-
Fix various hash function uses
- 2ad6e80de9a6 19 (unreleased) landed
-
Fix mixups of FooGetDatum() vs. DatumGetFoo()
- 1469e312977c 19 (unreleased) landed