X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 905E232A572 for ; Tue, 12 Oct 2004 05:09:04 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72106-07 for ; Tue, 12 Oct 2004 04:08:55 +0000 (GMT) Received: from mail63.csoft.net (leary3.csoft.net [63.111.22.74]) by svr1.postgresql.org (Postfix) with SMTP id 747B2329ECA for ; Tue, 12 Oct 2004 05:08:53 +0100 (BST) Received: (qmail 19966 invoked by uid 1112); 11 Oct 2004 21:17:24 -0000 Date: Mon, 11 Oct 2004 16:17:24 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Gabriele Bartolini Cc: pgsql-performance@postgresql.org Subject: Re: Normal case or bad query plan? In-Reply-To: <6.1.2.0.2.20041011224414.01fadec0@box.tin.it> Message-ID: References: <6.1.2.0.2.20041011224414.01fadec0@box.tin.it> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=DATE_IN_PAST_06_12 X-Spam-Level: X-Archive-Number: 200410/152 X-Sequence-Number: 8628 On Mon, 11 Oct 2004, Gabriele Bartolini wrote: > --------------------------------------------------------------------------------------------------------------------- > Seq Scan on ip2location (cost=0.00..30490.65 rows=124781 width=8) > (actual time=5338.120..40237.283 rows=1 loops=1) > Filter: ((1040878301::bigint >= ip_address_from) AND > (1040878301::bigint <= ip_address_to)) > Total runtime: 40237.424 ms > I believe the problem is that pg's lack of cross-column statistics is producing the poor number of rows estimate. The number of rows mataching just the first 1040878301::bigint >= ip_address_from condition is 122774 which is roughtly 10% of the table. I imagine the query planner believes that the other condition alone will match the other 90% of the table. The problem is that it doesn't know that these two ranges' intersection is actually tiny. The planner assumes a complete or nearly complete overlap so it thinks it will need to fetch 10% of the rows from both the index and the heap and chooses a seqscan. Kris Jurka