Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvKAI-0001E2-6o for pgsql-general@arkaria.postgresql.org; Sun, 29 May 2022 14:45:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nvKAG-0000V4-HL for pgsql-general@arkaria.postgresql.org; Sun, 29 May 2022 14:45:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvKAG-0000Un-6r for pgsql-general@lists.postgresql.org; Sun, 29 May 2022 14:45:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nvKAA-0002n7-UE for pgsql-general@postgresql.org; Sun, 29 May 2022 14:45:07 +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 24TEixku3452885; Sun, 29 May 2022 10:44:59 -0400 From: Tom Lane To: Danny Shemesh cc: pgsql-general@postgresql.org Subject: Re: Showing alternative query planner plans with explain ? In-reply-to: References: Comments: In-reply-to Danny Shemesh message dated "Sun, 29 May 2022 14:49:48 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3452883.1653835499.1@sss.pgh.pa.us> Date: Sun, 29 May 2022 10:44:59 -0400 Message-ID: <3452884.1653835499@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Danny Shemesh writes: > A tool I seem to be missing, and I wondered if such exists, is to have the > planner output alternative plans for a given query, i.e. to say, give me > the x top plans sorted by cost - I believe this would help shed some light > on the internal state machine and subsequent tinkering less > trial-and-error-ish. This does not exist, because the planner only carries one plan to completion, for reasons of speed and memory consumption. I have seen people hack things to print out info about paths (plan fragments) as they are considered, but I consider that approach pretty useless: the output is voluminous, not very readable, and mostly not interesting. You can get some of the effect by successively disabling the believed-cheapest plan choice with the "enable_xxx" parameters and seeing what the next choice is. Fooling around with the cost parameters can also provide useful insight. If the concern you have is about join order and not the details of the individual join types, another trick is to set join_collapse_limit to 1 and then write the FROM clause as a manually-parenthesized JOIN nest. That setting will force the planner to join in exactly the syntactic join order. regards, tom lane