Fix KNN GiST ordering type

Started by Alexander Korotkovalmost 10 years ago2 messages
#1Alexander Korotkov
a.korotkov@postgrespro.ru
1 attachment(s)

Hi!

KNN GiST detects which type it should return by returning type of ordering
operator.
But it appears that type of sk_func is detected after it was replaced with
distance function. That is wrong: distance function should always return
float8.
I think it is just a typo.
Should be backpatched to 9.5.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

fix-knn-gist-ordering-type.patchapplication/octet-stream; name=fix-knn-gist-ordering-type.patchDownload
diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
new file mode 100644
index 31758a1..f388ea3
*** a/src/backend/access/gist/gistscan.c
--- b/src/backend/access/gist/gistscan.c
*************** gistrescan(IndexScanDesc scan, ScanKey k
*** 284,291 ****
  					 GIST_DISTANCE_PROC, skey->sk_attno,
  					 RelationGetRelationName(scan->indexRelation));
  
- 			fmgr_info_copy(&(skey->sk_func), finfo, so->giststate->scanCxt);
- 
  			/*
  			 * Look up the datatype returned by the original ordering
  			 * operator. GiST always uses a float8 for the distance function,
--- 284,289 ----
*************** gistrescan(IndexScanDesc scan, ScanKey k
*** 300,305 ****
--- 298,305 ----
  			 */
  			so->orderByTypes[i] = get_func_rettype(skey->sk_func.fn_oid);
  
+ 			fmgr_info_copy(&(skey->sk_func), finfo, so->giststate->scanCxt);
+ 
  			/* Restore prior fn_extra pointers, if not first time */
  			if (!first_time)
  				skey->sk_func.fn_extra = fn_extras[i];
#2Alexander Korotkov
a.korotkov@postgrespro.ru
In reply to: Alexander Korotkov (#1)
Re: Fix KNN GiST ordering type

On Mon, Feb 1, 2016 at 7:31 PM, Alexander Korotkov <
a.korotkov@postgrespro.ru> wrote:

KNN GiST detects which type it should return by returning type of ordering
operator.
But it appears that type of sk_func is detected after it was replaced with
distance function. That is wrong: distance function should always return
float8.
I think it is just a typo.

I found this was introduced by this commit.
http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=821b821a2421beaa58225ff000833df69fb962c5;hp=284bef297733e553c73f1c858e0ce1532f754d18

However, commit message doesn't say anything special about this change.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company