mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
Expand partitioned table RTEs level by level, without flattening.
Flattening the partitioning hierarchy at this stage makes various desirable optimizations difficult. The original use case for this patch was partition-wise join, which wants to match up the partitions in one partitioning hierarchy with those in another such hierarchy. However, it now seems that it will also be useful in making partition pruning work using the PartitionDesc rather than constraint exclusion, because with a flattened expansion, we have no easy way to figure out which PartitionDescs apply to which leaf tables in a multi-level partition hierarchy. As it turns out, we end up creating both rte->inh and !rte->inh RTEs for each intermediate partitioned table, just as we previously did for the root table. This seems unnecessary since the partitioned tables have no storage and are not scanned. We might want to go back and rejigger things so that no partitioned tables (including the parent) need !rte->inh RTEs, but that seems to require some adjustments not related to the core purpose of this patch. Ashutosh Bapat, reviewed by me and by Amit Langote. Some final adjustments by me. Discussion: http://postgr.es/m/CAFjFpRd=1venqLL7oGU=C1dEkuvk2DJgvF+7uKbnPHaum1mvHQ@mail.gmail.com
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/pg_type.h"
|
||||
#include "catalog/pg_class.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/cost.h"
|
||||
@ -629,11 +630,28 @@ create_lateral_join_info(PlannerInfo *root)
|
||||
for (rti = 1; rti < root->simple_rel_array_size; rti++)
|
||||
{
|
||||
RelOptInfo *brel = root->simple_rel_array[rti];
|
||||
RangeTblEntry *brte = root->simple_rte_array[rti];
|
||||
|
||||
if (brel == NULL || brel->reloptkind != RELOPT_BASEREL)
|
||||
if (brel == NULL)
|
||||
continue;
|
||||
|
||||
if (root->simple_rte_array[rti]->inh)
|
||||
/*
|
||||
* In the case of table inheritance, the parent RTE is directly linked
|
||||
* to every child table via an AppendRelInfo. In the case of table
|
||||
* partitioning, the inheritance hierarchy is expanded one level at a
|
||||
* time rather than flattened. Therefore, an other member rel that is
|
||||
* a partitioned table may have children of its own, and must
|
||||
* therefore be marked with the appropriate lateral info so that those
|
||||
* children eventually get marked also.
|
||||
*/
|
||||
Assert(IS_SIMPLE_REL(brel));
|
||||
Assert(brte);
|
||||
if (brel->reloptkind == RELOPT_OTHER_MEMBER_REL &&
|
||||
(brte->rtekind != RTE_RELATION ||
|
||||
brte->relkind != RELKIND_PARTITIONED_TABLE))
|
||||
continue;
|
||||
|
||||
if (brte->inh)
|
||||
{
|
||||
foreach(lc, root->append_rel_list)
|
||||
{
|
||||
|
Reference in New Issue
Block a user