Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZUVau-0002Zy-PU for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 07:58:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZUVau-0001BG-Bn for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 07:58:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZUVat-0001At-I2 for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 07:58:03 +0000 Received: from e-mailfilter02.sunet.se ([2001:6b0:8:2::202]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZUVap-00019Q-SO for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 07:58:02 +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 t7Q7vs0w018161 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Aug 2015 09:57:54 +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 t7Q7voVI007748 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Aug 2015 07:57:53 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=1440575873; bh=041jxk9zCxhM2VVQKjQlhQgWAgDF/v318kvm18iA4kE=; h=Date:From:To:Subject:In-Reply-To:References; b=I13SCimNYwk3EtUjadvzFli7cbycKETIE9/XZbvPKlRlVSi7908YT+Mjj9G3RD4kc l6kvTYyG24uZerCFgUcfzpCDw6JjBcuXTAPKMTtInz29hw/0Wdohwy7BuP+9gaiQH4 Sui3zfasbj8U2/OBxQIywq8aS2b3vP6mCUAa9cc0= 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 09:57:48 +0200 Date: Wed, 26 Aug 2015 09:58:10 +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; charset=US-ASCII; format=flowed 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: 0aP9jVSBX - 16c3db748917 - 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 Hi, thanks for the reply. On Tue, 25 Aug 2015, Emre Hasegeli wrote: >> I'm trying to get a query to run fast enough for interactive use. I've gotten >> some speed-up, but still not there. It is for a tool called IRRExplorer >> (http://irrexplorer.nlnog.net/) that correlates IP routes between Internet >> Route Registries and real-world routing information. >> We landed on PostgreSQL largely due to indexing of the cidr type with >> gist indexing. > > It is nice to hear about someone making use of the feature. Thanks to whoever made it. It is probably a niche-feature though. >> SELECT rv.route, rv.asn, rv.source >> FROM routes_view rv >> LEFT OUTER JOIN routes_view r ON (rv.route && r.route) >> WHERE rv.route && r.route AND r.asn = %s > > Why don't you just use INNER JOIN like this: > > SELECT rv.route, rv.asn, rv.source > FROM routes_view rv > JOIN routes_view r ON rv.route && r.route > WHERE r.asn = %s I probably have a habit of thinking in outer joins. The inner join turns out to slightly slower though (but faster in planning), but it looks like it depends on a dice roll by the planner (it does bitmap heap scan on inner, and index scan on left outer). >> I am not terribly good at reading the output, but it seem most of the time is >> actually spend on the bitmap scan for the gist index. It there another type of >> indexing that would behave better here? > > An index to the "asn" column would probably help to the outer side, "select route from routes where asn = %s" takes .15-.2 seconds on my laptop, so it isn't where the time is spend here. > but more time seems to be consumed on the inner side. Plain index > scan would probably be faster for it. You can test it by setting > enable_bitmapscan to false. This actually makes it go slower for inner join (31s -> 56s). Left outer join is around the same. > The problem about bitmap index scan is selectivity estimation. The > planner estimates a lot more rows would match the condition, so it > chooses bitmap index scan. Selectivity estimation functions for inet > on PostgreSQL 9.4 just return some constants, so it is expected. We > developed better ones for 9.5. PostgreSQL 9.5 also supports index > only scans with GiST which can be even better than plain index scan. OK, that is interesting. > Can you try 9.5 to see if they help? I'll try installing it and report back. 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