Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ucaMC-00EXbh-RS for pgsql-performance@arkaria.postgresql.org; Fri, 18 Jul 2025 01:57:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ucaM8-006mCC-TG for pgsql-performance@arkaria.postgresql.org; Fri, 18 Jul 2025 01:57:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ucaM8-006mC4-IQ for pgsql-performance@lists.postgresql.org; Fri, 18 Jul 2025 01:57:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ucaM7-007rHC-1V for pgsql-performance@lists.postgresql.org; Fri, 18 Jul 2025 01:57:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56I1vjc81761502; Thu, 17 Jul 2025 21:57:45 -0400 From: Tom Lane To: Jerry Brenner cc: pgsql-performance@lists.postgresql.org Subject: Re: Is there a way to identify a plan generated by GECO? In-reply-to: References: Comments: In-reply-to Jerry Brenner message dated "Thu, 17 Jul 2025 18:09:50 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1761500.1752803865.1@sss.pgh.pa.us> Date: Thu, 17 Jul 2025 21:57:45 -0400 Message-ID: <1761501.1752803865@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jerry Brenner writes: > We are on Postgres 15.5 (Aurora) and capturing query plans via > auto_explain. We are seeing a large number of query plans for 2 queries > that have 12 tables. Every fast (or "fast enough") plan has a left deep > tree and every slow plan has a bushy tree. Is there a way to determine if > a plan was generated by GECO? > We have from_collapse_limit, join_collapse_limit and geqo_threshold all set > to 12. If there are 12 tables used in the query, then setting the collapse limits to 12 would allow the join search to be collapsed into a single problem, and then it would *always* go to GEQO because we invoke GEQO if the join problem involves >= geqo_threshold tables. You might want to rethink having those settings equal to each other. > I've manually explained plans and haven't seen the problem, My guess is that GEQO usually finds one of the better plans, but when its randomized search is particularly unlucky it fails to. Try bumping geqo_threshold to more than 12, and note whether that results in unacceptable planning time for these queries. If not, leave it at the higher value. regards, tom lane