Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Q4T-0001nZ-EG for pgsql-performance@arkaria.postgresql.org; Mon, 26 Mar 2018 11:13:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0Q4S-0005QT-0R for pgsql-performance@arkaria.postgresql.org; Mon, 26 Mar 2018 11:13:48 +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.89) (envelope-from ) id 1f0Q4R-0005QK-PO for pgsql-performance@lists.postgresql.org; Mon, 26 Mar 2018 11:13:47 +0000 Received: from uucp.dinoex.sub.de ([2001:1440:5001:1::2]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Q4P-00036Y-9N for pgsql-performance@lists.postgresql.org; Mon, 26 Mar 2018 11:13:47 +0000 Received: from uucp.dinoex.sub.de (uucp.dinoex.sub.de [194.45.71.2]) by uucp.dinoex.sub.de (8.15.2/8.15.2) with ESMTPS id w2QBD6e6067223 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Mar 2018 13:13:06 +0200 (CEST) (envelope-from pmc@citylink.dinoex.sub.org) Received: from citylink.dinoex.sub.org (uucp@localhost) by uucp.dinoex.sub.de (8.15.2/8.15.2/Submit) with UUCP id w2QBD6Uj067222; Mon, 26 Mar 2018 13:13:06 +0200 (CEST) (envelope-from pmc@citylink.dinoex.sub.org) Received: from gate.oper.dinoex.org (gate-e [192.168.98.2]) by citylink.dinoex.sub.de (8.15.2/8.15.2) with ESMTP id w2QAb7No032985; Mon, 26 Mar 2018 12:37:07 +0200 (CEST) (envelope-from peter@gate.oper.dinoex.org) Received: from gate.oper.dinoex.org (gate-e [192.168.98.2]) by gate.oper.dinoex.org (8.15.2/8.15.2) with ESMTP id w2QAaD8Q032900; Mon, 26 Mar 2018 12:36:14 +0200 (CEST) (envelope-from peter@gate.oper.dinoex.org) Received: (from peter@localhost) by gate.oper.dinoex.org (8.15.2/8.15.2/Submit) id w2QAaDO1032899; Mon, 26 Mar 2018 12:36:13 +0200 (CEST) (envelope-from peter) Date: Mon, 26 Mar 2018 12:36:13 +0200 From: Peter To: Laurenz Albe Cc: pgsql-performance@lists.postgresql.org, Tom Lane Subject: Re: Should from_collapse be switched off? (queries 10 times faster) Message-ID: <20180326103612.GA16180@gate.oper.dinoex.org> References: <20180323100308.GA1188@gate.oper.dinoex.org> <1521805295.2471.40.camel@cybertec.at> <18405.1521814459@sss.pgh.pa.us> <20180323173658.GA58069@gate.oper.dinoex.org> <1521954728.2350.24.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1521954728.2350.24.camel@cybertec.at> User-Agent: Mutt/1.8.3 (2017-05-23) X-Milter: Spamilter (Reciever: uucp.dinoex.sub.de; Sender-ip: 194.45.71.2; Sender-helo: uucp.dinoex.sub.de;) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (uucp.dinoex.sub.de [194.45.71.2]); Mon, 26 Mar 2018 13:13:08 +0200 (CEST) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz, thank You very much for Your comments! On Sun, Mar 25, 2018 at 07:12:08AM +0200, Laurenz Albe wrote: ! Your reported execution times don't match the time reported in the ! EXPLAIN output... Should these match? It seems the EXPLAIN (ANALYZE, BUFFERS) does additional things, not just execute the query. ! The cause of the long execution time is clear: ! ! The row count of the join between "places" (WHERE platz = 'WAEHR'), ! "wpnames" and "places AS places_1" is underestimated by a factor of 10 ! (1 row instead of 10). ! ! The nested loop join that is chosen as a consequence is now executed ! 10 times instead of the estimated 1 time, which is where almost all the ! execution time is spent. I've seen this, but do not fully understand it yet. ! Setting "enable_nestloop = off" is as coarse as forcing "from_collapse = 1" ! and will negatively impact other queries - if it helps at all. Since this query is already put into a function, I found I can easily set from_collapse=1 only for this function, by means of "ALTER FUNCTION ... SET ...", so it does only influence this query. It seems this is the most straight-forward solution here. rgds, P.