From: Tom Lane <tgl@sss.pgh.pa.us>
To: Danny Shemesh <dany74q@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Showing alternative query planner plans with explain ?
Date: Sun, 29 May 2022 10:44:59 -0400
Message-ID: <3452884.1653835499@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFZC=QpMZutOUnJATYzLiuvM9CAk7UPpWmnZX6uGXxgHYSE6nw@mail.gmail.com>
References: <CAFZC=QpMZutOUnJATYzLiuvM9CAk7UPpWmnZX6uGXxgHYSE6nw@mail.gmail.com>
Danny Shemesh <dany74q@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, dany74q@gmail.com
Subject: Re: Showing alternative query planner plans with explain ?
In-Reply-To: <3452884.1653835499@sss.pgh.pa.us>
References: <CAFZC=QpMZutOUnJATYzLiuvM9CAk7UPpWmnZX6uGXxgHYSE6nw@mail.gmail.com> <3452884.1653835499@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox