mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Add support for nearest-neighbor (KNN) searches to SP-GiST
Currently, KNN searches were supported only by GiST. SP-GiST also capable to support them. This commit implements that support. SP-GiST scan stack is replaced with queue, which serves as stack if no ordering is specified. KNN support is provided for three SP-GIST opclasses: quad_point_ops, kd_point_ops and poly_ops (catversion is bumped). Some common parts between GiST and SP-GiST KNNs are extracted into separate functions. Discussion: https://postgr.es/m/570825e8-47d0-4732-2bf6-88d67d2d51c8%40postgrespro.ru Author: Nikita Glukhov, Alexander Korotkov based on GSoC work by Vlad Sterzhanov Review: Andrey Borodin, Alexander Korotkov
This commit is contained in:
68
src/backend/utils/cache/lsyscache.c
vendored
68
src/backend/utils/cache/lsyscache.c
vendored
@ -1067,6 +1067,32 @@ get_opclass_input_type(Oid opclass)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_opclass_family_and_input_type
|
||||
*
|
||||
* Returns the OID of the operator family the opclass belongs to,
|
||||
* the OID of the datatype the opclass indexes
|
||||
*/
|
||||
bool
|
||||
get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
|
||||
{
|
||||
HeapTuple tp;
|
||||
Form_pg_opclass cla_tup;
|
||||
|
||||
tp = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
return false;
|
||||
|
||||
cla_tup = (Form_pg_opclass) GETSTRUCT(tp);
|
||||
|
||||
*opfamily = cla_tup->opcfamily;
|
||||
*opcintype = cla_tup->opcintype;
|
||||
|
||||
ReleaseSysCache(tp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ---------- OPERATOR CACHE ---------- */
|
||||
|
||||
/*
|
||||
@ -3106,3 +3132,45 @@ get_range_subtype(Oid rangeOid)
|
||||
else
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/* ---------- PG_INDEX CACHE ---------- */
|
||||
|
||||
/*
|
||||
* get_index_column_opclass
|
||||
*
|
||||
* Given the index OID and column number,
|
||||
* return opclass of the index column
|
||||
* or InvalidOid if the index was not found.
|
||||
*/
|
||||
Oid
|
||||
get_index_column_opclass(Oid index_oid, int attno)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
Form_pg_index rd_index PG_USED_FOR_ASSERTS_ONLY;
|
||||
Datum datum;
|
||||
bool isnull;
|
||||
oidvector *indclass;
|
||||
Oid opclass;
|
||||
|
||||
/* First we need to know the column's opclass. */
|
||||
|
||||
tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(index_oid));
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return InvalidOid;
|
||||
|
||||
rd_index = (Form_pg_index) GETSTRUCT(tuple);
|
||||
|
||||
/* caller is supposed to guarantee this */
|
||||
Assert(attno > 0 && attno <= rd_index->indnatts);
|
||||
|
||||
datum = SysCacheGetAttr(INDEXRELID, tuple,
|
||||
Anum_pg_index_indclass, &isnull);
|
||||
Assert(!isnull);
|
||||
|
||||
indclass = ((oidvector *) DatumGetPointer(datum));
|
||||
opclass = indclass->values[attno - 1];
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
|
||||
return opclass;
|
||||
}
|
||||
|
Reference in New Issue
Block a user