Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id E57B49FB49E for ; Fri, 16 Feb 2007 14:31:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 13176-08 for ; Fri, 16 Feb 2007 14:31:45 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.234]) by postgresql.org (Postfix) with ESMTP id 59D2F9FB430 for ; Fri, 16 Feb 2007 14:31:46 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id i7so1557609wra for ; Fri, 16 Feb 2007 10:31:45 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZnfUAecfwZk9YJKkUyv2WWVCY+dETuZCrpWDSteFRS9O8cuRKLWquwm+K0wyUvQ6EbCWZtqx+W05K5ACHDpKz736+7LBnetztx3/9nFamWpta8HaGgqO+SSVCXeIKpIlHUagksLPl8viV9XlscIdh6x42iyctaQBlI6Uvqw5za8= Received: by 10.90.81.14 with SMTP id e14mr4632133agb.1171650705704; Fri, 16 Feb 2007 10:31:45 -0800 (PST) Received: by 10.90.113.7 with HTTP; Fri, 16 Feb 2007 10:31:45 -0800 (PST) Message-ID: <1d4e0c10702161031q6f0b937cr67ce374560a74aa3@mail.gmail.com> Date: Fri, 16 Feb 2007 19:31:45 +0100 From: "Guillaume Smet" To: "Paul Ramsey" Subject: Re: Proximity query with GIST and row estimation Cc: "Pg Performance list" In-Reply-To: <1d4e0c10702150813p19df3108sf2a7c82c38360a0a@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1d4e0c10702130909g3be0a10fpf2594574c84866c9@mail.gmail.com> <0BD9E842-2DA7-4F90-A732-AFD60C1F50C7@refractions.net> <1d4e0c10702150813p19df3108sf2a7c82c38360a0a@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/187 X-Sequence-Number: 23241 On 2/15/07, Guillaume Smet wrote: > The use of PostGIS is slower than the previous cube/earthdistance > approach (on a similar query and plan). For the record, here are new information about my proximity query work. Thanks to Tom Lane, I found the reason of the performance drop. The problem is that the gist index for operator && is lossy (declared as RECHECK in the op class). AFAICS, for the && operator it's done to prevent problems when SRIDs are not compatible: it forces the execution of the filter and so even with a "should be non lossy" bitmap index scan, it throws an error as if we use a seqscan (Paul, correct me if I'm wrong) because it forces the execution of the filter. As I'm sure I won't have this problem (I will write a wrapper stored procedure so that the end users won't see the SRID used), I created a different opclass without the RECHECK clause: CREATE OPERATOR CLASS gist_geometry_ops_norecheck FOR TYPE geometry USING gist AS OPERATOR 3 &&, FUNCTION 1 LWGEOM_gist_consistent (internal, geometry, int4), FUNCTION 2 LWGEOM_gist_union (bytea, internal), FUNCTION 3 LWGEOM_gist_compress (internal), FUNCTION 4 LWGEOM_gist_decompress (internal), FUNCTION 5 LWGEOM_gist_penalty (internal, internal, internal), FUNCTION 6 LWGEOM_gist_picksplit (internal, internal), FUNCTION 7 LWGEOM_gist_same (box2d, box2d, internal); UPDATE pg_opclass SET opckeytype = (SELECT oid FROM pg_type WHERE typname = 'box2d' AND typnamespace = (SELECT oid FROM pg_namespace WHERE nspname=current_schema())) WHERE opcname = 'gist_geometry_ops_norecheck' AND opcnamespace = (SELECT oid from pg_namespace WHERE nspname=current_schema()); As I use only the && operator, I put only this one. And I recreated my index using: CREATE INDEX idx_lieu_earthpoint ON lieu USING gist(earthpoint gist_geometry_ops_norecheck); In the case presented before, the bitmap index scan is then non lossy and I have similar performances than with earthdistance method. -- Guillaume