Skip to content

Commit 6f22a82

Browse files
committed
Add assertions for all the required index AM callbacks
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
1 parent db6461b commit 6f22a82

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/access/index/amapi.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ GetIndexAmRoutine(Oid amhandler)
4242
elog(ERROR, "index access method handler function %u did not return an IndexAmRoutine struct",
4343
amhandler);
4444

45+
/* Assert that all required callbacks are present. */
46+
Assert(routine->ambuild != NULL);
47+
Assert(routine->ambuildempty != NULL);
48+
Assert(routine->aminsert != NULL);
49+
Assert(routine->ambulkdelete != NULL);
50+
Assert(routine->amvacuumcleanup != NULL);
51+
Assert(routine->amcostestimate != NULL);
52+
Assert(routine->amoptions != NULL);
53+
Assert(routine->amvalidate != NULL);
54+
Assert(routine->ambeginscan != NULL);
55+
Assert(routine->amrescan != NULL);
56+
Assert(routine->amendscan != NULL);
57+
4558
return routine;
4659
}
4760

0 commit comments

Comments
 (0)