Re: Get the planner used by a query? - Mailing list pgsql-performance

From David Rowley
Subject Re: Get the planner used by a query?
Date
Msg-id CAKJS1f8zmVedgD+uXTCm-urZASNStkb4uHq0eYD86EfKHka_qA@mail.gmail.com
Whole thread Raw
In response to Get the planner used by a query?  (Behrang Saeedzadeh <behrangsa@gmail.com>)
List pgsql-performance
On Wed, 9 Oct 2019 at 19:21, Behrang Saeedzadeh <behrangsa@gmail.com> wrote:
>
> Is there a way to display the planner algorithm used by a query, either in EXPLAIN or in a different way?

There's not really any simple way to know. If the number of relations
in the join search meets or exceeds geqo_threshold then it'll use the
genetic query optimizer. However, knowing exactly how many relations
are in the join search is not often simple since certain types of
subqueries can be pulled up into the main query and that can increase
the number of relations in the search.

If you don't mind writing C code, then you could write an extension
that hooks into join_search_hook and somehow outputs this information
to you before going on to call the geqo if the "enable_geqo &&
levels_needed >= geqo_threshold" condition is met.  Besides that, I
don't really know if there's any way.  You could try editing the
geqo_seed and seeing if the plan changes, but if it does not, then
that does not mean the geqo was not used, so doing it that way could
be quite error-prone.  You'd only be able to tell the geqo was being
used if you could confirm that changing geqo_seed did change the plan.
(And you could be certain the plan did not change for some other
reason like an auto-analyze).



--
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services



pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query slows when used with view
Next
From: Jeff Janes
Date:
Subject: Re: Modification of data in base folder and very large tables