Skip to content

Commit f25d07d

Browse files
committed
Fix lossy KNN GiST when ordering operator returns non-float8 value.
KNN GiST with recheck flag should return to executor the same type as ordering operator, GiST detects this type by looking to return type of function which implements ordering operator. But occasionally detecting code works after replacing ordering operator function to distance support function. Distance support function always returns float8, so, detecting code get float8 instead of actual return type of ordering operator. Built-in opclasses don't have ordering operator which doesn't return non-float8 value, so, tests are impossible here, at least now. Backpatch to 9.5 where lozzy KNN was introduced. Author: Alexander Korotkov Report by: Artur Zakirov
1 parent 7191ce8 commit f25d07d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/backend/access/gist/gistscan.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys,
229229
{
230230
ScanKey skey = scan->keyData + i;
231231

232+
/*
233+
* Copy consistent support function to ScanKey structure
234+
* instead of function implementing filtering operator.
235+
*/
232236
fmgr_info_copy(&(skey->sk_func),
233237
&(so->giststate->consistentFn[skey->sk_attno - 1]),
234238
so->giststate->scanCxt);
@@ -284,8 +288,6 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys,
284288
GIST_DISTANCE_PROC, skey->sk_attno,
285289
RelationGetRelationName(scan->indexRelation));
286290

287-
fmgr_info_copy(&(skey->sk_func), finfo, so->giststate->scanCxt);
288-
289291
/*
290292
* Look up the datatype returned by the original ordering
291293
* operator. GiST always uses a float8 for the distance function,
@@ -300,6 +302,12 @@ gistrescan(IndexScanDesc scan, ScanKey key, int nkeys,
300302
*/
301303
so->orderByTypes[i] = get_func_rettype(skey->sk_func.fn_oid);
302304

305+
/*
306+
* Copy distance support function to ScanKey structure
307+
* instead of function implementing ordering operator.
308+
*/
309+
fmgr_info_copy(&(skey->sk_func), finfo, so->giststate->scanCxt);
310+
303311
/* Restore prior fn_extra pointers, if not first time */
304312
if (!first_time)
305313
skey->sk_func.fn_extra = fn_extras[i];

0 commit comments

Comments
 (0)