mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -24,6 +24,7 @@
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "foreign/fdwapi.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#ifdef OPTIMIZER_DEBUG
|
||||
@ -352,8 +353,8 @@ set_rel_size(PlannerInfo *root, RelOptInfo *rel,
|
||||
else if (rte->relkind == RELKIND_PARTITIONED_TABLE)
|
||||
{
|
||||
/*
|
||||
* A partitioned table without leaf partitions is marked
|
||||
* as a dummy rel.
|
||||
* A partitioned table without any partitions is marked as
|
||||
* a dummy rel.
|
||||
*/
|
||||
set_dummy_rel_pathlist(rel);
|
||||
}
|
||||
@ -867,6 +868,9 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
|
||||
int nattrs;
|
||||
ListCell *l;
|
||||
|
||||
/* Guard against stack overflow due to overly deep inheritance tree. */
|
||||
check_stack_depth();
|
||||
|
||||
Assert(IS_SIMPLE_REL(rel));
|
||||
|
||||
/*
|
||||
@ -1290,25 +1294,23 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
|
||||
bool build_partitioned_rels = false;
|
||||
|
||||
/*
|
||||
* A plain relation will already have a PartitionedChildRelInfo if it is
|
||||
* partitioned. For a subquery RTE, no PartitionedChildRelInfo exists; we
|
||||
* collect all partitioned_rels associated with any child. (This assumes
|
||||
* that we don't need to look through multiple levels of subquery RTEs; if
|
||||
* we ever do, we could create a PartitionedChildRelInfo with the
|
||||
* accumulated list of partitioned_rels which would then be found when
|
||||
* populated our parent rel with paths. For the present, that appears to
|
||||
* be unnecessary.)
|
||||
* A root partition will already have a PartitionedChildRelInfo, and a
|
||||
* non-root partitioned table doesn't need one, because its Append paths
|
||||
* will get flattened into the parent anyway. For a subquery RTE, no
|
||||
* PartitionedChildRelInfo exists; we collect all partitioned_rels
|
||||
* associated with any child. (This assumes that we don't need to look
|
||||
* through multiple levels of subquery RTEs; if we ever do, we could
|
||||
* create a PartitionedChildRelInfo with the accumulated list of
|
||||
* partitioned_rels which would then be found when populated our parent
|
||||
* rel with paths. For the present, that appears to be unnecessary.)
|
||||
*/
|
||||
rte = planner_rt_fetch(rel->relid, root);
|
||||
switch (rte->rtekind)
|
||||
{
|
||||
case RTE_RELATION:
|
||||
if (rte->relkind == RELKIND_PARTITIONED_TABLE)
|
||||
{
|
||||
partitioned_rels =
|
||||
get_partitioned_child_rels(root, rel->relid);
|
||||
Assert(list_length(partitioned_rels) >= 1);
|
||||
}
|
||||
break;
|
||||
case RTE_SUBQUERY:
|
||||
build_partitioned_rels = true;
|
||||
|
Reference in New Issue
Block a user