Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 34FBA86A54A for ; Wed, 18 Jan 2012 08:08:16 -0400 (AST) Received: from exprod7og104.obsmtp.com ([64.18.2.161]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RnUJH-0008DZ-3H for pgsql-bugs@postgresql.org; Wed, 18 Jan 2012 12:08:15 +0000 Received: from mail-ey0-f169.google.com ([209.85.215.169]) (using TLSv1) by exprod7ob104.postini.com ([64.18.6.12]) with SMTP ID DSNKTxa2HSgcd/hdwr4k0CCaUibfSfjUM00S@postini.com; Wed, 18 Jan 2012 04:08:10 PST Received: by eaan1 with SMTP id n1so1693409eaa.28 for ; Wed, 18 Jan 2012 04:07:56 -0800 (PST) Received: by 10.213.20.219 with SMTP id g27mr5284194ebb.19.1326888476224; Wed, 18 Jan 2012 04:07:56 -0800 (PST) Received: from [192.168.1.101] (dsl-hkibrasgw2-ff6cc300-200.dhcp.inet.fi. [88.195.108.200]) by mx.google.com with ESMTPS id 28sm33765970eed.0.2012.01.18.04.07.54 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Jan 2012 04:07:55 -0800 (PST) Message-ID: <4F16B616.50709@enterprisedb.com> Date: Wed, 18 Jan 2012 14:07:50 +0200 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20120104 Icedove/8.0 MIME-Version: 1.0 To: yamt@mwd.biglobe.ne.jp CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6399: knngist sometimes returns tuples in incorrect order References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201201/128 X-Sequence-Number: 32195 On 16.01.2012 11:32, yamt@mwd.biglobe.ne.jp wrote: > The following bug has been logged on the website: > > Bug reference: 6399 > Logged by: YAMAMOTO Takashi > Email address: yamt@mwd.biglobe.ne.jp > PostgreSQL version: Unsupported/Unknown > Operating system: NetBSD > Description: > > 9.2devel > (01d83ffdcae92f75dbfd41de0b4213d241edd394) > > knngist seems to assume that any distances can be represented with float8. > at least distances between int8 values can not. Yeah. That seems like a bad assumption. It might theoretically be possible to somehow map all int8s to float8s, but e.g numerics will not be. > the following example uses btree_gist extension. > results should be the same regardless of the existance of the index. > > create temp table t (a int8); > insert into t values (9223372036854775806),(9223372036854775807); > select *,0<->a as dist from t order by dist; > create index on t using gist (a); > set enable_seqscan=off; > select *,0<->a as dist from t order by dist; > > > CREATE TABLE > INSERT 0 2 > a | dist > ---------------------+--------------------- > 9223372036854775806 | 9223372036854775806 > 9223372036854775807 | 9223372036854775807 > (2 rows) > > CREATE INDEX > SET > a | dist > ---------------------+--------------------- > 9223372036854775807 | 9223372036854775807 > 9223372036854775806 | 9223372036854775806 > (2 rows) Yep, that's wrong. Both rows have the same float8 distance value, and get outputted in wrong order. For 9.2, I think we should change gist so that the user-defined distance function can return any scalar data type, not just float8 (as long as it has b-tree comparison operators). For 9.1, I'm afraid it's too late to do that. Or is it? The other option is to hack gist to re-check tuples with equal distance values. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com