mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +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:
@@ -187,6 +187,7 @@ spgvalidate(Oid opclassoid)
|
||||
{
|
||||
HeapTuple oprtup = &oprlist->members[i]->tuple;
|
||||
Form_pg_amop oprform = (Form_pg_amop) GETSTRUCT(oprtup);
|
||||
Oid op_rettype;
|
||||
|
||||
/* TODO: Check that only allowed strategy numbers exist */
|
||||
if (oprform->amopstrategy < 1 || oprform->amopstrategy > 63)
|
||||
@@ -200,20 +201,26 @@ spgvalidate(Oid opclassoid)
|
||||
result = false;
|
||||
}
|
||||
|
||||
/* spgist doesn't support ORDER BY operators */
|
||||
if (oprform->amoppurpose != AMOP_SEARCH ||
|
||||
OidIsValid(oprform->amopsortfamily))
|
||||
/* spgist supports ORDER BY operators */
|
||||
if (oprform->amoppurpose != AMOP_SEARCH)
|
||||
{
|
||||
ereport(INFO,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("operator family \"%s\" of access method %s contains invalid ORDER BY specification for operator %s",
|
||||
opfamilyname, "spgist",
|
||||
format_operator(oprform->amopopr))));
|
||||
result = false;
|
||||
/* ... and operator result must match the claimed btree opfamily */
|
||||
op_rettype = get_op_rettype(oprform->amopopr);
|
||||
if (!opfamily_can_sort_type(oprform->amopsortfamily, op_rettype))
|
||||
{
|
||||
ereport(INFO,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("operator family \"%s\" of access method %s contains invalid ORDER BY specification for operator %s",
|
||||
opfamilyname, "spgist",
|
||||
format_operator(oprform->amopopr))));
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
op_rettype = BOOLOID;
|
||||
|
||||
/* Check operator signature --- same for all spgist strategies */
|
||||
if (!check_amop_signature(oprform->amopopr, BOOLOID,
|
||||
if (!check_amop_signature(oprform->amopopr, op_rettype,
|
||||
oprform->amoplefttype,
|
||||
oprform->amoprighttype))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user