Re: Convert query plan to sql query - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Convert query plan to sql query
Date
Msg-id 21193.1415465017@sss.pgh.pa.us
Whole thread Raw
In response to Re: Convert query plan to sql query  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Convert query plan to sql query  (mariem <mariem.benfadhel@gmail.com>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Sat, Nov 8, 2014 at 1:09 AM, mariem <mariem.benfadhel@gmail.com> wrote:
>> I'm aware of ruleutils.c which I think is a good tool but I don't think it's
>> appropriate as it takes the parse tree as input.

> "Parse", "Rewrite", and "Plan" are distinct stages.  ruleutils.c takes
> the tree that results from rewriting, before planning has been done.
> So I'm not sure it's quite accurate to say that it takes the "parse
> tree" - rewrite rules will already have been applied.

More specifically: rewrite is a parsetree-to-parsetree transformation;
it does not change the representational rules at all.  It's true that
the "typical" use of ruleutils is on parser output (ie stored views)
but it will work fine on rewriter output.

If what you're wishing for is that you could also capture the effects
of planner steps that are in the nature of source-to-source
transformations, I think that's going to be harder because no great
effort has been made to keep those at arm's length from steps that
don't have results describable as pure SQL.  However, you could probably
get pretty far if you applied ruleutils.c to the modified parse tree
after the constant-folding and join tree simplification phases.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: row_to_json bug with index only scans: empty keys!
Next
From: Tom Lane
Date:
Subject: Re: Add CREATE support to event triggers