On Tue, 22 Jul 2025 at 14:36, Michael Paquier <mich...@paquier.xyz> wrote: > On Thu, Jul 17, 2025 at 01:34:42PM +0800, Japin Li wrote: >> On Wed, 16 Jul 2025 at 10:08, Peter Smith <smithpb2...@gmail.com> wrote: >>> What's going on there? Is it just an accidentally missing "/* can be >>> NULL */" comment? >> >> It appears commit c1ec02be1d79 is missing the comment. > > Agreed. That's user-visible, so backpatched down to v17. > >> How about asserting the existence of all required callbacks, similar to >> GetTableAmRoutine()? > > Hmm, we could do something like that to enforce a stronger policy, > yes. At least that seems sensible to me to be able to detect faster a > problem rather than waiting for the backend to report the issue with a > crash when testing a dedicated code path where one of these callbacks > is run. As a HEAD-only thing, of course. > > I was reading the page, and some of the functions in the docs are > documented as optional with the matching NULL description. It is > the case of aminsertcleanup as well, one paragraph above with the > part about "may define".
PFA to assert all required IndexAM callbacks are present. -- Regards, Japin Li
>From 77763b1dea3a7f2b447ae7fac56e563e8082056b Mon Sep 17 00:00:00 2001 From: Japin Li <japi...@hotmail.com> Date: Wed, 23 Jul 2025 12:02:03 +0800 Subject: [PATCH] Assert required index access method callbacks --- src/backend/access/index/amapi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/backend/access/index/amapi.c b/src/backend/access/index/amapi.c index f0f4f974bce..60684c53422 100644 --- a/src/backend/access/index/amapi.c +++ b/src/backend/access/index/amapi.c @@ -42,6 +42,19 @@ GetIndexAmRoutine(Oid amhandler) elog(ERROR, "index access method handler function %u did not return an IndexAmRoutine struct", amhandler); + /* Assert that all required callbacks are present. */ + Assert(routine->ambuild != NULL); + Assert(routine->ambuildempty != NULL); + Assert(routine->aminsert != NULL); + Assert(routine->ambulkdelete != NULL); + Assert(routine->amvacuumcleanup != NULL); + Assert(routine->amcostestimate != NULL); + Assert(routine->amoptions != NULL); + Assert(routine->amvalidate != NULL); + Assert(routine->ambeginscan != NULL); + Assert(routine->amrescan != NULL); + Assert(routine->amendscan != NULL); + return routine; } -- 2.43.0