Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZUWaq-0005Ij-Ma for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 09:02:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZUWaq-0004oi-7W for pgsql-performance@arkaria.postgresql.org; Wed, 26 Aug 2015 09:02:04 +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 1ZUWZD-0002vN-Ny for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 09:00:23 +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 1ZUWZB-0003oy-8r for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 09:00:22 +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 t7Q90JT2015589 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 26 Aug 2015 11:00:19 +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 t7Q90G7f014345 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 26 Aug 2015 09:00:19 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=1440579619; bh=nOQAAoe5kYS6XnP64ItYfuq9FtlCrFN+kOpePyblCCE=; h=Date:From:To:Subject:In-Reply-To:References; b=m1mlTpqynKQsX+MuzNLqqnoS1qseYZXquFefCl3M53z+iA93jiR3UEEbq4t0kJI1g tF+Xl3+CztzdJMmptwZHRNJKbdxT3ev1vccKT3VK5iP1FzKjcgkVPfPMCpKPjHMrW8 1pJdeB+rvemcvC3CItnC7MdvE/n83b4YP2e6DdD4= 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)) for pgsql-performance@postgresql.org; Wed, 26 Aug 2015 11:00:15 +0200 Date: Wed, 26 Aug 2015 11:00:38 +0200 (CEST) From: Henrik Thostrup Jensen X-X-Sender: htj@pyrite To: 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: 0aP9l0jnF - 3f04de5675a3 - 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, Henrik Thostrup Jensen wrote: >> Can you try 9.5 to see if they help? > > I'll try installing it and report back. I upgraded to 9.5 (easier than expected) and ran vacuum analyze. The query planner now chooses index scan for outer and inner join. This seems to cut off roughly a second or so (31s -> 30s, and 17s->16s for when using distint on initial route set). Query: EXPLAIN (ANALYZE, BUFFERS) SELECT rv.route, rv.asn, rv.source FROM (SELECT DISTINCT route FROM routes_view WHERE asn = %s) r INNER JOIN routes_view rv ON (r.route && rv.route) ORDER BY rv.route; Explain analyze: http://explain.depesz.com/s/L7kZ 9.5 also seems to fix the case with using CTE/WITH was actually slower. The fastest I can currently do is this, which finds the minimal set of covering routes before joining: SET enable_bitmapscan = false; EXPLAIN ANALYZE WITH distinct_routes AS (SELECT DISTINCT route FROM routes_view WHERE asn = %s), minimal_routes AS (SELECT route FROM distinct_routes EXCEPT SELECT r1.route FROM distinct_routes r1 INNER JOIN distinct_routes r2 ON (r1.route << r2.route)) SELECT rv.route, rv.asn, rv.source FROM routes_view rv JOIN minimal_routes ON (rv.route <<= minimal_routes.route); Explain analyze: http://explain.depesz.com/s/Plx4 The query planner chooses bitmap Index Scan for this query, which adds around .5 second the query time, so it isn't that bad of a decision. Unfortunately it still takes 15 seconds for my test case (a big network, but still a factor 10 from the biggest). Are the coverage operatons just that expensive? 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