Harden tableam against nonexistant / wrong kind of AMs.
Andres Freund <andres@anarazel.de>
Harden tableam against nonexistant / wrong kind of AMs. Previously it was allowed to set default_table_access_method to an empty string. That makes sense for default_tablespace, where that was copied from, as it signals falling back to the database's default tablespace. As there is no equivalent for table AMs, forbid that. Also make sure to throw a usable error when creating a table using an index AM, by using get_am_type_oid() to implement get_table_am_oid() instead of a separate copy. Previously we'd error out only later, in GetTableAmRoutine(). Thirdly remove GetTableAmRoutineByAmId() - it was only used in an earlier version of 8586bf7ed8. Add tests for the above (some for index AMs as well).
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/table/tableamapi.c | modified | +16 −94 |
| src/backend/commands/amcmds.c | modified | +10 −0 |
| src/backend/commands/tablecmds.c | modified | +2 −15 |
| src/include/access/tableam.h | modified | +0 −1 |
| src/include/commands/defrem.h | modified | +1 −0 |
| src/test/regress/expected/create_am.out | modified | +33 −0 |
| src/test/regress/expected/type_sanity.out | modified | +18 −0 |
| src/test/regress/sql/create_am.sql | modified | +27 −0 |
| src/test/regress/sql/type_sanity.sql | modified | +12 −0 |