Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZUYsy-0004EG-0B for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 11:28:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZUYsx-0000lk-E8 for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 11:28:55 +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 1ZUYsv-0000lX-R7 for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 11:28:53 +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 1ZUYso-0006gw-F5 for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 11:28:52 +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 t7QBSiEH010445 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Aug 2015 13:28:44 +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 t7QBSdfT021884 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Aug 2015 11:28:42 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=1440588523; bh=o0EV9e58Lmy3oBHt0njzMCQXVtb3wd7zRQBNjkNe0h4=; h=Date:From:To:Subject:In-Reply-To:References; b=qAFfNUnhTbQnjK7EjMFadrCiAUAXfQNPBF7mPW1aW9tjkU1+JTOR0RU8uTljtfril 1nyko2WQeQ1PoyZ9o1ECRsqg7Yb036qe+jh3/oQRBf7eE3oJ7abWJ77U9qGwRUyl/r aGnEwJ6NA5DsSeRctc8FDsBwr2aAfVLMo9AMEFro= 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)); Wed, 26 Aug 2015 13:28:39 +0200 Date: Wed, 26 Aug 2015 13:29:01 +0200 (CEST) From: Henrik Thostrup Jensen X-X-Sender: htj@pyrite To: Emre Hasegeli , pgsql-performance 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: 0aP9nsIH7 - 3f570cfa2016 - 20150826 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 On Wed, 26 Aug 2015, Emre Hasegeli wrote: >> Are the coverage operatons just that expensive? > > They shouldn't be. A similar query like yours works in 0.5 second on my laptop: [snip] I get the same from your testcase. > Maybe, something we haven't expected about your dataset causes a > performance regression on the index. Did you see anything relevant on > the server logs on index creation time? I tried dropping and re-creating the index. The only log entry was for the drop statement. The distribution of the data is not uniform like the data set you produce. Though I find it hard to believe that it would affect this as much. select masklen(route), count(*) from routes group by masklen(route); masklen | count ---------+--------- 8 | 47 9 | 30 10 | 84 11 | 225 12 | 580 13 | 1163 14 | 2401 15 | 4530 16 | 32253 17 | 20350 18 | 35583 19 | 76307 20 | 111913 21 | 132807 22 | 229578 23 | 286986 24 | 1149793 Rest is rather small, though with bumps at /32 and /48 (typical IPv6 prefix length). Real-world address space is very fragmented, where as some is unused. Then there is the mixed IPv6 and IPv4 data that might factor in. I tried the approach from your benchmark, to try make a more isolated test case: irrexplorer=> SELECT DISTINCT route INTO hmm FROM routes_view WHERE asn = 2914; SELECT 732 irrexplorer=> explain analyze select routes.route from routes join hmm on routes.route && hmm.route; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.41..511914.27 rows=2558 width=7) (actual time=8.096..17209.778 rows=8127 loops=1) -> Seq Scan on hmm (cost=0.00..11.32 rows=732 width=7) (actual time=0.010..0.609 rows=732 loops=1) -> Index Only Scan using route_gist on routes (cost=0.41..470.32 rows=22900 width=7) (actual time=4.823..23.502 rows=11 loops=732) Index Cond: (route && (hmm.route)::inet) Heap Fetches: 0 Planning time: 0.971 ms Execution time: 17210.627 ms (7 rows) The only difference in the query plan is that the above used an index only, where as your test case used index scan (it did this for me as well). I tried without index only scan: irrexplorer=> set enable_indexonlyscan =false; SET QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=0.41..571654.27 rows=2558 width=7) (actual time=6.406..15899.791 rows=8127 loops=1) -> Seq Scan on hmm (cost=0.00..11.32 rows=732 width=7) (actual time=0.011..0.615 rows=732 loops=1) -> Index Scan using route_gist on routes (cost=0.41..551.93 rows=22900 width=7) (actual time=4.490..21.712 rows=11 loops=732) Index Cond: ((route)::inet && (hmm.route)::inet) Planning time: 0.505 ms Execution time: 15900.669 ms (6 rows) Slight faster, but nothing significant. Something seems wonky. Best regards, Henrik -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance