Re: RangeTblEntry.inh vs. RTE_SUBQUERY

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: RangeTblEntry.inh vs. RTE_SUBQUERY
Date: 2024-02-23 14:52:20
Message-ID: CAEZATCXZP9dd4oym=nLzkHswjfBcY6-Xe4RH+v+YLC0jiKR30Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 23 Feb 2024 at 14:35, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>
> Various code comments say that the RangeTblEntry field inh may only be
> set for entries of kind RTE_RELATION.
>
> The function pull_up_simple_union_all() in prepjointree.c sets ->inh to
> true for RTE_SUBQUERY entries:
>
> /*
> * Mark the parent as an append relation.
> */
> rte->inh = true;
>
> Whatever this is doing appears to be some undocumented magic.

Yes, it's explained a bit more clearly/accurately in expand_inherited_rtentry():

/*
* expand_inherited_rtentry
* Expand a rangetable entry that has the "inh" bit set.
*
* "inh" is only allowed in two cases: RELATION and SUBQUERY RTEs.
*
* "inh" on a plain RELATION RTE means that it is a partitioned table or the
* parent of a traditional-inheritance set. In this case we must add entries
* for all the interesting child tables to the query's rangetable, and build
* additional planner data structures for them, including RelOptInfos,
* AppendRelInfos, and possibly PlanRowMarks.
*
* Note that the original RTE is considered to represent the whole inheritance
* set. In the case of traditional inheritance, the first of the generated
* RTEs is an RTE for the same table, but with inh = false, to represent the
* parent table in its role as a simple member of the inheritance set. For
* partitioning, we don't need a second RTE because the partitioned table
* itself has no data and need not be scanned.
*
* "inh" on a SUBQUERY RTE means that it's the parent of a UNION ALL group,
* which is treated as an appendrel similarly to inheritance cases; however,
* we already made RTEs and AppendRelInfos for the subqueries. We only need
* to build RelOptInfos for them, which is done by expand_appendrel_subquery.
*/

> Is this something we should explain the RangeTblEntry comments?
>

+1

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message a.imamov 2024-02-23 15:03:41 Re: Potential issue in ecpg-informix decimal converting functions
Previous Message wenhui qiu 2024-02-23 14:40:22 Re: Thoughts about NUM_BUFFER_PARTITIONS