Re: Common Table Expressions (WITH RECURSIVE) patch - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Common Table Expressions (WITH RECURSIVE) patch
Date
Msg-id 25923.1222174541@sss.pgh.pa.us
Whole thread Raw
In response to Re: Common Table Expressions (WITH RECURSIVE) patch  (Tatsuo Ishii <ishii@postgresql.org>)
Responses Re: Common Table Expressions (WITH RECURSIVE) patch  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-hackers
Jeff Davis <pgsql@j-davis.com> writes:
> Here is a patch that is an initial attempt to reorganize the parse tree
> representation.

Oh dear, we seem to have spent yesterday doing the same work :-(

I'll go over this and try to merge it with my own WIP.

> * There are a couple of other rough points in places where it's hard to
> traverse up the parse tree or query tree.

Yeah, I'd been running into that issue too.  Adding an explicit pointer
to the CTE into the RTE doesn't work because it renders the parse tree
un-copiable (at least without something a lot more sophisticated than
copyObject; and saving/loading rule parsetrees would be tough too).

What I've got at the moment is that creation of an RTE_CTE RTE copies
the CTE's lists of output column types/typmods into the RTE.  This
eliminates the need for expandRTE and a couple of other places to be
able to find the CTE; everything they need is in the RTE.  So far as I
can see, everyplace else that might need to find the CTE from the RTE
is in places that either have a ParseState available, or have some
comparable structure that could provide a way to search upwards for
CTEs (eg, in ruleutils the "deparse context" will need to track
uplevel CTE lists as well as rtables).

It is a bit tedious though.  Can anyone think of another way that would
still preserve the notion of multiple RTEs being links to the same CTE
rather than independent subqueries?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: WIP patch: Collation support
Next
From: Gregory Stark
Date:
Subject: Re: Common Table Expressions (WITH RECURSIVE) patch