Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A03436326A5 for ; Wed, 30 Dec 2009 02:55:39 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 81825-01 for ; Wed, 30 Dec 2009 06:55:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.155]) by mail.postgresql.org (Postfix) with ESMTP id C6A09632662 for ; Wed, 30 Dec 2009 02:55:28 -0400 (AST) Received: by fg-out-1718.google.com with SMTP id 22so4766666fge.1 for ; Tue, 29 Dec 2009 22:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=UyiiUq9Iu3BnDhpjb3F/I+YRFJ2pmMPJoY+BtFLoel4=; b=i3xmjfpsRtAElzQF9hcdvr9kA9AF4eApNPZxbnwhzTU/6X8qTjQw1eCKxrHWF6o1Sh kaKL2r7IYgWRRLrSE9L25cFwuO7FEWaoa6gonOkpK3vpsvFt30kepbK37nGbyprNhVlL szWk2inObrgItS1inCF/WbweRUJD+NRSsFLKo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=L5sGoz2EF4sSqNxDUveOY3VPGBu2izKMxXZbVkxdZI2d8GtvkhWlAIRUn2EkdiNzBp WBTiw2ixVdpUZ4NrGTwn1J672sRBLVcfhFEI4/bvIritdDmhCSnQoHoK28pMWy5+2F6L lnVILnnV2WUtcaTuQRZOhOoHli8kk5LHZMzw4= MIME-Version: 1.0 Received: by 10.239.185.6 with SMTP id a6mr1968957hbh.31.1262156126470; Tue, 29 Dec 2009 22:55:26 -0800 (PST) In-Reply-To: <4B0EAE0D.606@sigaev.ru> References: <4B0AC9E1.5050509@sigaev.ru> <4B0EAE0D.606@sigaev.ru> Date: Wed, 30 Dec 2009 01:55:26 -0500 Message-ID: <603c8f070912292255u30e1983bi22ed5778bd2ce890@mail.gmail.com> Subject: Re: KNNGiST for knn-search (WIP) From: Robert Haas To: Teodor Sigaev Cc: Pgsql Hackers Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/2324 X-Sequence-Number: 153027 2009/11/26 Teodor Sigaev : > Hi! > > Contrib module is reworked as a patch for current GiST. Now GiST supports > KNN-search, the query looks like > SELECT * FROM point_tbl ORDER BY f1 <-> '0,1'; > or > SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 > <-> '0,1'; > Plans are: > EXPLAIN (COSTS OFF) > SELECT * FROM point_tbl ORDER BY f1 <-> '0,1'; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 QUERY PLAN > ----------------------------------------- > =A0Index Scan using gpointind on point_tbl > =A0 Index Cond: (f1 <-> '(0,1)'::point) > EXPLAIN (COSTS OFF) > SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 > <-> '0,1'; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0QUERY = PLAN > -------------------------------------------------------------------------= ----- > =A0Index Scan using gpointind on point_tbl > =A0 Index Cond: ((f1 <@ '(10,10),(-10,-10)'::box) AND (f1 <-> '(0,1)'::po= int)) > > > pg_am now has new column amcanorderbyop (can order by operation), indexes > with this flag enabled can be used to speedup operations, which returns > non-boolean value, currently type of returned value should have default > btree operator class =A0to perform sort. > > Planner (find_usable_indexes function, actually) could push pathkey > expression into restriction clauses of index. I'm not fully satisfied wit= h > this piece of code, but, may be, someone has a better idea. I though abou= t > adding separate indexorderquals in IndexPath structure... > > Both GiST's get methods are optimized and there is no overhead, since > gistrescan method can choose what traversal algorithm to use using > information about types of values returned by operations. If at least one= of > them returns non-boolean result, then KNN-search will be performed. > > The only change in interface of supporting functions is: consistentFn > function could return float8 non-negative value and it's mandatory to > perform KNN-search. Old-style consistent functions are supported. > > Patch contains (it still requires rbtree-0.5 and point_ops-0.4 patches): > - GiST changes > - changes in point_ops to support knn-search > - contrib/pg_trgm now has new operation <-> returns distance between text= s. > This operation is supported in KNN-search > - contrib/btree_gist provides <-> and its support for GiST for types int2= , > int4, int8, float4, float8, money, oid, interval, time, date, timestamp a= nd > timestamptz > > TODO: > - selectivity of ordering operation should be 1.0 > - current patch remove support of =A0IndexScanDesc->kill_prior_tuple, it'= s > needed to restore support if it will not create too big overhead > - documentation Based on the feedback provided on this patch so far, it looks like some changes are probably needed, but it's not entirely clear whether the feedback provided is sufficient to provide guidance on what changes should be made. It does also need to be updated to CVS HEAD, as it no longer applies cleanly. I tend to feel that we should probably target this for 8.6 rather than 8.5. We are down to the last CommitFest, and while we don't have a nailed-down criterion for what is "too big" for the last CommitFest of a given release cycle, this is definitely a big, invasive patch. This patch weights in at over 2400 adds/removes, and it's not boilerplate stuff like updates to pg_proc entries, but real, significant changes. I'm worried that applying something like this late in the release cycle is just not a good idea, especially given the fact that it probably still needs significant revising. However, I'm fairly conservative by nature, so perhaps someone else will have a different opinion, or maybe there is a way to restructure it so that the needed changes are less invasive. ...Robert