Re: Access to postgresql query optimizer output - Mailing list pgsql-general

From Tom Lane
Subject Re: Access to postgresql query optimizer output
Date
Msg-id 19681.1351528148@sss.pgh.pa.us
Whole thread Raw
In response to Re: Access to postgresql query optimizer output  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-general
Jeff Janes <jeff.janes@gmail.com> writes:
> On Mon, Oct 29, 2012 at 1:07 AM, Seref Arikan
> <serefarikan@kurumsalteknoloji.com> wrote:
>> I keep seeing statements like "Postgresql optimizer rewrites this query
>> as...." What I'm curious about is, is there a way to obtain SQL form of the
>> re-written queries somewhere in the chain of query evaluation? It does not
>> make a lot sense to generate sql again, but it would help a lot to see  the
>> queries in their  rewritten form.

> The re-writing does not occur at the level of SQL, but rather at the
> level of an internal representation "parse tree".

> You can see these representations using these configuration settings;

> debug_print_parse = on
> debug_print_rewritten = on

> I'm not aware of anything that turns those back into SQL.

It's not entirely clear whether the question is about the rule rewriter
or the planner.  The rule rewriter really is effectively a
source-to-source transformation; its output parse trees still correspond
1-to-1 to SQL and could be turned back into something meaningful by
feeding them to ruleutils.c.  There's no built-in support for that,
though, and it's not clear to me that it would be very interesting in
practice.

I suspect that the OP is more interested in actions taken by the
planner; but those are not expressed as parsetree transformations.
There are all sorts of practical obstacles to getting a useful view of
intermediate steps in the planning process, for instance that most
alternatives are rejected without ever forming any complete
representation of them.

            regards, tom lane


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why BgWriterDelay is fixed?
Next
From: Peter Geoghegan
Date:
Subject: Re: Access to postgresql query optimizer output