1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Invent "amadjustmembers" AM method for validating opclass members.

This allows AM-specific knowledge to be applied during creation of
pg_amop and pg_amproc entries.  Specifically, the AM knows better than
core code which entries to consider as required or optional.  Giving
the latter entries the appropriate sort of dependency allows them to
be dropped without taking out the whole opclass or opfamily; which
is something we'd like to have to correct obsolescent entries in
extensions.

This callback also opens the door to performing AM-specific validity
checks during opclass creation, rather than hoping than an opclass
developer will remember to test with "amvalidate".  For the most part
I've not actually added any such checks yet; that can happen in a
follow-on patch.  (Note that we shouldn't remove any tests from
"amvalidate", as those are still needed to cross-check manually
constructed entries in the initdb data.  So adding tests to
"amadjustmembers" will be somewhat duplicative, but it seems like
a good idea anyway.)

Patch by me, reviewed by Alexander Korotkov, Hamid Akhtar, and
Anastasia Lubennikova.

Discussion: https://postgr.es/m/4578.1565195302@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2020-08-01 17:12:47 -04:00
parent e2b37d9e7c
commit 9f9682783b
24 changed files with 646 additions and 112 deletions

View File

@@ -1,7 +1,8 @@
/*-------------------------------------------------------------------------
*
* amvalidate.c
* Support routines for index access methods' amvalidate functions.
* Support routines for index access methods' amvalidate and
* amadjustmembers functions.
*
* Copyright (c) 2016-2020, PostgreSQL Global Development Group
*
@@ -222,21 +223,28 @@ check_amop_signature(Oid opno, Oid restype, Oid lefttype, Oid righttype)
}
/*
* Is the datatype a legitimate input type for the btree opfamily?
* Get the OID of the opclass belonging to an opfamily and accepting
* the specified type as input type. Returns InvalidOid if no such opclass.
*
* If there is more than one such opclass, you get a random one of them.
* Since that shouldn't happen, we don't waste cycles checking.
*
* We could look up the AM's OID from the opfamily, but all existing callers
* know that or can get it without an extra lookup, so we make them pass it.
*/
bool
opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
Oid
opclass_for_family_datatype(Oid amoid, Oid opfamilyoid, Oid datatypeoid)
{
bool result = false;
Oid result = InvalidOid;
CatCList *opclist;
int i;
/*
* We search through all btree opclasses to see if one matches. This is a
* bit inefficient but there is no better index available. It also saves
* making an explicit check that the opfamily belongs to btree.
* We search through all the AM's opclasses to see if one matches. This
* is a bit inefficient but there is no better index available. It also
* saves making an explicit check that the opfamily belongs to the AM.
*/
opclist = SearchSysCacheList1(CLAAMNAMENSP, ObjectIdGetDatum(BTREE_AM_OID));
opclist = SearchSysCacheList1(CLAAMNAMENSP, ObjectIdGetDatum(amoid));
for (i = 0; i < opclist->n_members; i++)
{
@@ -246,7 +254,7 @@ opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
if (classform->opcfamily == opfamilyoid &&
classform->opcintype == datatypeoid)
{
result = true;
result = classform->oid;
break;
}
}
@@ -255,3 +263,14 @@ opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
return result;
}
/*
* Is the datatype a legitimate input type for the btree opfamily?
*/
bool
opfamily_can_sort_type(Oid opfamilyoid, Oid datatypeoid)
{
return OidIsValid(opclass_for_family_datatype(BTREE_AM_OID,
opfamilyoid,
datatypeoid));
}