diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-01-17 19:36:59 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-01-17 19:36:59 -0500 |
commit | 65c5fcd353a859da9e61bfb2b92a99f12937de3b (patch) | |
tree | 3d75be487f88d11a27fb0b96809e492838666d72 /src/backend/commands/opclasscmds.c | |
parent | 8d290c8ec6c182a4df1d089c21fe84c7912f01fe (diff) | |
download | postgresql-65c5fcd353a859da9e61bfb2b92a99f12937de3b.tar.gz postgresql-65c5fcd353a859da9e61bfb2b92a99f12937de3b.zip |
Restructure index access method API to hide most of it at the C level.
This patch reduces pg_am to just two columns, a name and a handler
function. All the data formerly obtained from pg_am is now provided
in a C struct returned by the handler function. This is similar to
the designs we've adopted for FDWs and tablesample methods. There
are multiple advantages. For one, the index AM's support functions
are now simple C functions, making them faster to call and much less
error-prone, since the C compiler can now check function signatures.
For another, this will make it far more practical to define index access
methods in installable extensions.
A disadvantage is that SQL-level code can no longer see attributes
of index AMs; in particular, some of the crosschecks in the opr_sanity
regression test are no longer possible from SQL. We've addressed that
by adding a facility for the index AM to perform such checks instead.
(Much more could be done in that line, but for now we're content if the
amvalidate functions more or less replace what opr_sanity used to do.)
We might also want to expose some sort of reporting functionality, but
this patch doesn't do that.
Alexander Korotkov, reviewed by Petr JelĂnek, and rather heavily
editorialized on by me.
Diffstat (limited to 'src/backend/commands/opclasscmds.c')
-rw-r--r-- | src/backend/commands/opclasscmds.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index a0ca2114d1b..8a661968cd9 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -26,6 +26,7 @@ #include "catalog/indexing.h" #include "catalog/objectaccess.h" #include "catalog/opfam_internal.h" +#include "catalog/pg_am.h" #include "catalog/pg_amop.h" #include "catalog/pg_amproc.h" #include "catalog/pg_namespace.h" @@ -334,7 +335,7 @@ DefineOpClass(CreateOpClassStmt *stmt) ListCell *l; Relation rel; HeapTuple tup; - Form_pg_am pg_am; + IndexAmRoutine *amroutine; Datum values[Natts_pg_opclass]; bool nulls[Natts_pg_opclass]; AclResult aclresult; @@ -361,18 +362,18 @@ DefineOpClass(CreateOpClassStmt *stmt) stmt->amname))); amoid = HeapTupleGetOid(tup); - pg_am = (Form_pg_am) GETSTRUCT(tup); - maxOpNumber = pg_am->amstrategies; + amroutine = GetIndexAmRoutineByAmId(amoid); + ReleaseSysCache(tup); + + maxOpNumber = amroutine->amstrategies; /* if amstrategies is zero, just enforce that op numbers fit in int16 */ if (maxOpNumber <= 0) maxOpNumber = SHRT_MAX; - maxProcNumber = pg_am->amsupport; - amstorage = pg_am->amstorage; + maxProcNumber = amroutine->amsupport; + amstorage = amroutine->amstorage; /* XXX Should we make any privilege check against the AM? */ - ReleaseSysCache(tup); - /* * The question of appropriate permissions for CREATE OPERATOR CLASS is * interesting. Creating an opclass is tantamount to granting public @@ -776,7 +777,7 @@ AlterOpFamily(AlterOpFamilyStmt *stmt) int maxOpNumber, /* amstrategies value */ maxProcNumber; /* amsupport value */ HeapTuple tup; - Form_pg_am pg_am; + IndexAmRoutine *amroutine; /* Get necessary info about access method */ tup = SearchSysCache1(AMNAME, CStringGetDatum(stmt->amname)); @@ -787,17 +788,17 @@ AlterOpFamily(AlterOpFamilyStmt *stmt) stmt->amname))); amoid = HeapTupleGetOid(tup); - pg_am = (Form_pg_am) GETSTRUCT(tup); - maxOpNumber = pg_am->amstrategies; + amroutine = GetIndexAmRoutineByAmId(amoid); + ReleaseSysCache(tup); + + maxOpNumber = amroutine->amstrategies; /* if amstrategies is zero, just enforce that op numbers fit in int16 */ if (maxOpNumber <= 0) maxOpNumber = SHRT_MAX; - maxProcNumber = pg_am->amsupport; + maxProcNumber = amroutine->amsupport; /* XXX Should we make any privilege check against the AM? */ - ReleaseSysCache(tup); - /* Look up the opfamily */ opfamilyoid = get_opfamily_oid(amoid, stmt->opfamilyname, false); @@ -1099,21 +1100,13 @@ assignOperTypes(OpFamilyMember *member, Oid amoid, Oid typeoid) * the family has been created but not yet populated with the required * operators.) */ - HeapTuple amtup; - Form_pg_am pg_am; + IndexAmRoutine *amroutine = GetIndexAmRoutineByAmId(amoid); - amtup = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid)); - if (amtup == NULL) - elog(ERROR, "cache lookup failed for access method %u", amoid); - pg_am = (Form_pg_am) GETSTRUCT(amtup); - - if (!pg_am->amcanorderbyop) + if (!amroutine->amcanorderbyop) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("access method \"%s\" does not support ordering operators", - NameStr(pg_am->amname)))); - - ReleaseSysCache(amtup); + get_am_name(amoid)))); } else { |