Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id C509E2E0048 for ; Mon, 7 Apr 2008 13:41:34 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 17469-01 for ; Mon, 7 Apr 2008 13:41:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ulysses.lattica.com (lattica.com [204.14.19.114]) by developer.postgresql.org (Postfix) with ESMTP id A5CA12E003C for ; Mon, 7 Apr 2008 13:41:27 -0300 (ADT) Received: from localhost (ulysses.lattica.com [127.0.0.1]) by ulysses.lattica.com (Postfix) with ESMTP id E4BB97383D4; Mon, 7 Apr 2008 12:41:26 -0400 (EDT) X-Virus-Scanned: amavisd-new at lattica.com Received: from ulysses.lattica.com ([127.0.0.1]) by localhost (ulysses.lattica.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eC17clhtx94g; Mon, 7 Apr 2008 12:41:26 -0400 (EDT) Received: from [192.168.3.11] (CPE00a0cc63452d-CM0011aec8bfb4.cpe.net.cable.rogers.com [99.229.154.251]) by ulysses.lattica.com (Postfix) with ESMTP id D50BF7383A9; Mon, 7 Apr 2008 12:41:25 -0400 (EDT) Subject: Re: Severe performance problems for simple query From: Dimi Paun To: Heikki Linnakangas Cc: Matthew , pgsql-performance In-Reply-To: <47FA4C96.3090808@enterprisedb.com> References: <1207581719.5399.119.camel@dimi.lattica.com> <47FA4C96.3090808@enterprisedb.com> Content-Type: text/plain Organization: Lattica, Inc. Date: Mon, 07 Apr 2008 12:41:25 -0400 Message-Id: <1207586485.5399.140.camel@dimi.lattica.com> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-3.fc8) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/61 X-Sequence-Number: 29554 On Mon, 2008-04-07 at 17:32 +0100, Heikki Linnakangas wrote: > If I understood the original post correctly, the ipFrom and ipTo > columns actually split a single linear ip address space into > non-overlapping chunks. Something like this: > > ipFrom ipTo > 1 10 > 10 20 > 20 50 > 50 60 > ... > Indeed. > In that case, a regular index on (ipFrom, ipTo) should work just fine, > and that's what he's got. Actually, an index on just ipFrom would > probably work just as well. No, it doesn't: perpedes_db=# CREATE INDEX temp1 ON static.ipligenceipaddress (ipFrom); CREATE INDEX perpedes_db=# explain ANALYZE select * from static.ipligenceipaddress where ipfrom <= 2130706433 and 2130706433 <= ipto limit 1; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.07 rows=1 width=145) (actual time=1519.526..1519.527 rows=1 loops=1) -> Index Scan using temp1 on ipligenceipaddress (cost=0.00..84796.50 rows=1209308 width=145) (actual time=1519.524..1519.524 rows=1 loops=1) Index Cond: (ipfrom <= 2130706433) Filter: (2130706433 <= ipto) Total runtime: 1519.562 ms (5 rows) This is huge, I'd say... > The problem is that the planner doesn't know about that special > relationship between ipFrom and ipTo. Perhaps it could be hinted by > explicitly specifying "AND ipTo > ipFrom" in the query? Unfortunately, it still does a seq scan: perpedes_db=# SET enable_seqscan = on; SET perpedes_db=# explain ANALYZE select * from static.ipligenceipaddress where ipfrom <= 2130706433 and 2130706433 <= ipto AND ipTo > ipFrom limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.00..0.35 rows=1 width=145) (actual time=1245.293..1245.294 rows=1 loops=1) -> Seq Scan on ipligenceipaddress (cost=0.00..142343.80 rows=403103 width=145) (actual time=1245.290..1245.290 rows=1 loops=1) Filter: ((ipfrom <= 2130706433) AND (2130706433 <= ipto) AND (ipto > ipfrom)) Total runtime: 1245.335 ms (4 rows) > I don't know why the single index lookup took > 300ms, though. That > does seem high to me. That is my feeling. I would have expected order of magnitude faster execution times, the DB runs on fairly decent hardware... -- Dimi Paun Lattica, Inc.