Add assertions for all the required index AM callbacks master github/master
authorMichael Paquier <michael@paquier.xyz>
Sun, 27 Jul 2025 08:48:47 +0000 (17:48 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 27 Jul 2025 08:48:47 +0000 (17:48 +0900)
Similar checks are done for the mandatory table AM callbacks.  A portion
of the index AM callbacks are optional and can be NULL; the rest is
mandatory and is documented as such in the documentation and in amapi.h.

These checks are useful to detect quickly if all the mandatory callbacks
are defined when implementing a new index access method, as the
assertions are run when loading the AM.

Author: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/ME0P300MB0445795D31CEAB92C58B41FDB651A@ME0P300MB0445.AUSP300.PROD.OUTLOOK.COM

src/backend/access/index/amapi.c

index f0f4f974bcedb73aae994f0df7db15c87c2b5587..60684c53422794ad288871f225d2945c1cb2ecd2 100644 (file)
@@ -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;
 }