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 1ezNq1-0001k8-5G for pgsql-performance@arkaria.postgresql.org; Fri, 23 Mar 2018 14:38:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ezNpz-00056K-Th for pgsql-performance@arkaria.postgresql.org; Fri, 23 Mar 2018 14:38:35 +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 1ezNpz-00056A-M2 for pgsql-performance@lists.postgresql.org; Fri, 23 Mar 2018 14:38:35 +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 1ezNpw-0000x1-B2 for pgsql-performance@lists.postgresql.org; Fri, 23 Mar 2018 14:38:35 +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 w2NEc0eg006698 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 23 Mar 2018 15:38:00 +0100 (CET) (envelope-from pmc@citylink.dinoex.sub.org) X-MDaemon-Deliver-To: Received: from citylink.dinoex.sub.org (uucp@localhost) by uucp.dinoex.sub.de (8.15.2/8.15.2/Submit) with UUCP id w2NEc0YY006697 for pgsql-performance@lists.postgresql.org; Fri, 23 Mar 2018 15:38:00 +0100 (CET) (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 w2NEXJDO035751 for ; Fri, 23 Mar 2018 15:33:19 +0100 (CET) (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 w2NEUqg1035497 for ; Fri, 23 Mar 2018 15:30:52 +0100 (CET) (envelope-from peter@gate.oper.dinoex.org) Received: (from peter@localhost) by gate.oper.dinoex.org (8.15.2/8.15.2/Submit) id w2NEUqjw035496 for pgsql-performance@lists.postgresql.org; Fri, 23 Mar 2018 15:30:52 +0100 (CET) (envelope-from peter) Date: Fri, 23 Mar 2018 15:30:52 +0100 From: Peter To: pgsql-performance@lists.postgresql.org Subject: Re: Should from_collapse be switched off? (queries 10 times faster) Message-ID: <20180323143052.GA30371@gate.oper.dinoex.org> References: <20180323100308.GA1188@gate.oper.dinoex.org> <1521805295.2471.40.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1521805295.2471.40.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]); Fri, 23 Mar 2018 15:38:02 +0100 (CET) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Mar 23, 2018 at 12:41:35PM +0100, Laurenz Albe wrote: ! https://www.postgresql.org/docs/current/static/explicit-joins.html ! states towards the end of the page that the search tree grows ! exponentially with the number of relations, and from_collapse_limit ! can be set to control that. Yes, I read that page. ! > In my case, planning uses 1 or 2% of the cycles needed for ! > execution; that seems alright to me. ! > And, as said above, I cannot see why my queries might be an ! > atypical case (I don't think they are). ! > ! > If somebody would like to get a hands-on look onto the actual ! > case, I'd be happy to put it online. ! ! It seems like you are barking up the wrong tree. ! ! Your query does not take long because of the many relations in the ! FROM list, but because the optimizer makes a wrong choice. Exactly! And I am working hard in order to understand WHY this happens. ! The correct solution is *not* to set from_collapse_limit = 1, but ! to find and fix the problem that causes the optimizer to make a ! wrong choice. ! ! If you send the query and the output of ! EXPLAIN (ANALYZE, BUFFERS) SELECT ... ! we have a chance of telling you what's wrong. Your viewpoint would be preferrable, only I am lacking any idea on where there could be such a problem that would make up a root cause. I will gladly follow Your suggestion; data is underway. P.