Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZVKIl-0005P8-78 for pgsql-performance@arkaria.postgresql.org; Fri, 28 Aug 2015 14:06:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZVKIk-0007Wo-KZ for pgsql-performance@arkaria.postgresql.org; Fri, 28 Aug 2015 14:06:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZVKH7-0005Zy-3F for pgsql-performance@postgresql.org; Fri, 28 Aug 2015 14:05:01 +0000 Received: from e-mailfilter02.sunet.se ([2001:6b0:8:2::202]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZVKH4-0006Cr-3x for pgsql-performance@postgresql.org; Fri, 28 Aug 2015 14:05:00 +0000 Received: from smtp1.nordu.net (smtp1.nordu.net [IPv6:2001:948:4:6::32]) by e-mailfilter02.sunet.se (8.14.4/8.14.4/Debian-4) with ESMTP id t7SE4rQt022062 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 28 Aug 2015 16:04:53 +0200 Received: from kerio.nordu.net (kerio.nordu.net [109.105.110.42]) by smtp1.nordu.net (8.14.7/8.14.7) with ESMTP id t7SE4lYZ028651 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Aug 2015 14:04:50 GMT VBR-Info: md=nordu.net; mc=all; mv=swamid.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nordu.net; s=default; t=1440770693; bh=zX+baxnZA4D95ABvKLVdsZ/3jpFAEJDm6uxyoqg6X3M=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=D2KmoXAJAbzOtYEY1kKnN3+juoXtXbRwHGTjeRk/yMsKoGZJZ42pE8+Bdunf7SQxI +HwYoyaZBgT8chTS4PkVTKudz2UOIbTaeD6w5SejFIc2Rttsxyj2h8JqZVzJYIbCL5 hnS12eFUNn9qmlbQm08zGlqGlmmNv2/tDlRvKG60= X-Footer: bm9yZHUubmV0 Received: from pyrite ([130.225.198.224]) (authenticated user htj@nordu.net) by kerio.nordu.net (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)); Fri, 28 Aug 2015 16:04:46 +0200 Date: Fri, 28 Aug 2015 16:05:14 +0200 (CEST) From: Henrik Thostrup Jensen X-X-Sender: htj@pyrite To: Emre Hasegeli cc: pgsql-performance , Jeff Janes , Tom Lane , Andreas Karlsson Subject: Re: Gist indexing performance with cidr types In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Scanned-By: CanIt (www . roaringpenguin . com) X-Scanned-By: MIMEDefang 2.74 on 109.105.111.32 X-Spam-Score: undef - 109.105.110.42 is whitelisted. X-p0f-Info: os=unknown unknown, link=Ethernet or modem X-CanIt-Geo: ip=109.105.110.42; country=SE; latitude=59.3294; longitude=18.0686; http://maps.google.com/maps?q=59.3294,18.0686&z=6 X-CanItPRO-Stream: outbound-nordu-net:outbound (inherits from outbound-nordu-net:default, nordu-net:default, base:default) X-Canit-Stats-ID: 0aPae4RXS - 3404e47b585e - 20150828 X-CanIt-Archive-Cluster: PfMRe/vJWMiXwM2YIH5BVExnUnw Received-SPF: neutral (e-mailfilter02.sunet.se: 109.105.110.42 is neither permitted nor denied by domain htj@nordu.net) receiver=e-mailfilter02.sunet.se; client-ip=109.105.110.42; envelope-from=; helo=smtp1.nordu.net; identity=mailfrom X-Pg-Spam-Score: -4.3 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi On Thu, 27 Aug 2015, Emre Hasegeli wrote: > I think the slowdown is not related with the key your searched for, > but the organisation of the index. We have a simple structure for > the index keys. Basically, common bits of the child nodes are stored > on the parent node. It leads to not efficient indexes, where there > are too much values with the same prefix. I couldn't quite understand > why it performs so bad, though. I can see the issue. Unfortunately IP space tends to be fragmented in some ranges, and very sparse in other. It is unfortunate that something to index IP prefixes doesn't handle BGP and IRR data very well (the only largish "real" datasets with IP prefixes I can think of). > You might have better luck with ip4r extension [1] or creating an index > using the range types like this: [snip] Using the range type index: Nested Loop (cost=0.42..603902.92 rows=8396377 width=26) (actual time=0.514..662.500 rows=8047 loops=1) -> Seq Scan on hmm (cost=0.00..11.32 rows=732 width=7) (actual time=0.015..0.119 rows=732 loops=1) -> Index Scan using routes_cidr_to_range_idx on routes (cost=0.42..595.58 rows=22941 width=19) (actual time=0.262..0.903 rows=11 loops=732) Index Cond: (inetrange(set_masklen((route)::inet, 0), set_masklen(broadcast((route)::inet), 0)) && inetrange(set_masklen((hmm.route)::inet, 0), set_masklen(broadcast((hmm.route)::inet), 0))) Planning time: 0.211 ms Execution time: 662.769 ms (6 rows) Boom. This is actually usefull. It does take 70 seconds for the biggst network though. The index is also rather large: public | routes_cidr_to_range_idx | index | htj | routes | 158 MB | Table is 119MB data. The gist index was 99 MB. Best regards, Henrik Henrik Thostrup Jensen Software Developer, NORDUnet -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance