Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXUfQ-0005QG-SP for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jan 2018 16:16:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXUfP-0001Ro-7e for pgsql-performance@arkaria.postgresql.org; Fri, 05 Jan 2018 16:16:23 +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_2) (envelope-from ) id 1eXUfO-0001Rb-Pe for pgsql-performance@lists.postgresql.org; Fri, 05 Jan 2018 16:16:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eXUfL-00029M-5P for pgsql-performance@postgresql.org; Fri, 05 Jan 2018 16:16:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w05GGHLq029567; Fri, 5 Jan 2018 11:16:17 -0500 From: Tom Lane To: =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= cc: pgsql-performance@postgresql.org Subject: Re: GEQO and join_collapse_limit correlation In-reply-to: References: Comments: In-reply-to =?UTF-8?Q?Juan_Jos=C3=A9_Santamar=C3=ADa_Flecha?= message dated "Fri, 05 Jan 2018 15:30:25 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29565.1515168977.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 05 Jan 2018 11:16:17 -0500 Message-ID: <29566.1515168977@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?UTF-8?Q?Juan_Jos=3DC3=3DA9_Santamar=3DC3=3DADa_Flecha?=3D writes: > We recently had an issue in production. We have queries that are > procedurally generated by an Object/Relational Mapping framework. Some o= f > these queries are huge, involving over 120 tables. Yeah, you're going to have problems with that :-( > After some testing in order to lower the planning time we ended bringing > down the GEQO values, and we have the best results with: > from_collapse_limit =3D 150 > join_collapse_limit =3D 150 > geqo_threshold =3D 2 > geqo_effort=3D 2 Hmm. The trouble with this approach is that you're relying on GEQO to find a good plan, and that's only probabilistic --- especially so when you're reducing geqo_effort, meaning it doesn't try as many possibilities as it otherwise might. Basically, therefore, the fear is that every so often you'll get a bad plan. If the queries are fairly stylized, you might be able to get good = results by exploiting rather than bypassing join_collapse_limit: determine what a good join order is, and then write the FROM clause as an explicit JOIN nest in that order, and then *reduce* not raise join_collapse_limit to force the planner to follow the syntactic join order. In this way you'd get rid of most of the run-time join order search effort. Don't know how cooperative your ORM would be with such an approach though. regards, tom lane