Re: Datum as struct
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-07-31T17:17:54Z
Lists: pgsql-hackers
Peter Eisentraut <peter@eisentraut.org> writes: > 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. I looked through this. I think 0001-0003 are unconditionally improvements and you should just commit them. Many of the pointer-related changes are identical to ones that I had arrived at while working on cleaning up the gcc warnings from my 8-byte-Datum patch, so this would create merge conflicts with that patch, and getting these changes in would make that one shorter. I do have one review comment on 0003: in brin_minmax_multi_distance_numeric, you wrote - PG_RETURN_FLOAT8(DirectFunctionCall1(numeric_float8, d)); + PG_RETURN_FLOAT8(DatumGetFloat8(DirectFunctionCall1(numeric_float8, d))); Another way to do that could be PG_RETURN_DATUM(DirectFunctionCall1(numeric_float8, d)); I'm not sure we should expect the compiler to be able to elide the conversions to float8 and back, so I prefer the second way. Also I see a "// XXX" in pg_get_aios, which I guess is a note to confirm the data type to use for ioh_id? My only reservation about 0004 is whether we want to do it like this, or with the separate "_D" functions that I proposed in the other thread. Right now the vote seems to be 2 to 1 for adding DatumGetPointer calls, so unless there are more votes you should go ahead with 0004 as well. No objection to 0005 either. I agree that 0006 is not something we want to commit. Aside from all the replacements for "(Datum) 0" --- which'd be fine I guess if there weren't so darn many --- it seems to me that bits like this are punching too many holes in the abstraction: - if (PointerGetDatum(key) != entry->key) + if (PointerGetDatum(key).value != entry->key.value) It'd probably be an improvement to code that like if ((Pointer) key != DatumGetPointer(entry->key)) which matches the way we do things in many other places. But in general any direct reference to .value outside the DatumGetFoo/FooGetDatum functions seems like an abstraction fail. However, the sheer number of quasi-cosmetic issues you found this way gives me pause. If we don't have something like 0006 available for test purposes, more bugs of the same ilk are surely going to creep in. regards, tom lane
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