Re: speeding up planning with partitions
Tom Lane <tgl@sss.pgh.pa.us>
Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> writes:
> Here are some comments on v38.
Thanks for looking it over! I'll just reply to points worth discussing:
> - Assert(rte->rtekind == RTE_RELATION ||
> - rte->rtekind == RTE_SUBQUERY);
> - add_appendrel_other_rels(root, rel, rti);
> + if (rte->rtekind == RTE_RELATION)
> + expand_inherited_rtentry(root, rel, rte, rti);
> + else
> + expand_appendrel_subquery(root, rel, rte, rti);
> Wouldn't it be a good idea to keep the Assert?
There's an Assert in expand_appendrel_subquery that what it got is an
RTE_SUBQUERY, so I thought the one at the call site was redundant.
I suppose another way to do this would be like
if (rte->rtekind == RTE_RELATION)
expand_inherited_rtentry(root, rel, rte, rti);
else if (rte->rtekind == RTE_SUBQUERY)
expand_appendrel_subquery(root, rel, rte, rti);
else
Assert(false);
Not sure if that's better or not. Or we could go back to the
design of just having one function and letting it dispatch the
case it doesn't want to the other function --- though I think
I'd make expand_inherited_rtentry be the primary function,
rather than the other way around as you had it in v37.
> + forboth(lc, old_child_rtis, lc2, new_child_rtis)
> + {
> + int old_child_rti = lfirst_int(lc);
> + int new_child_rti = lfirst_int(lc2);
> +
> + if (old_child_rti == new_child_rti)
> + continue; /* nothing to do */
> +
> + Assert(old_child_rti > new_child_rti);
> +
> + ChangeVarNodes((Node *) child_appinfos,
> + old_child_rti, new_child_rti, 0);
> + }
> This seems necessary? RTEs of children of the target table should be in
> the same position in the final_rtable as they are in the select_rtable.
Well, that's what I'm not very convinced of. I have observed that
the regression tests don't reach this ChangeVarNodes call, but
I think that might just be lack of test cases rather than a proof
that it's impossible. The question is whether it'd ever be possible
for the update/delete target to not be the first "inh" table that
gets expanded. Since that expansion is done in RTE order, it
reduces to "is the target always before any other RTE entries
that could need inheritance expansion?" Certainly that would typically
be true, but I don't feel very comfortable about assuming that it
must be true, when you start thinking about things like updatable
views, rules, WITH queries, and so on.
It might be worth trying to devise a test case that does reach this
code. If we could convince ourselves that it's really impossible,
I'd be willing to drop it in favor of putting a test-and-elog check
in the earlier loop that the RTI pairs are all equal. But I'm not
willing to do it without more investigation.
> + /* XXX wrong? */
> + parentrte->inh = false;
> About the XXX: I think resetting inh flag is unnecessary, so we should
> just remove the line.
Possibly. I hadn't had time to follow up the XXX annotation.
> If we do that, we can also get rid of the following
> code in set_rel_size():
> else if (rte->relkind == RELKIND_PARTITIONED_TABLE)
> {
> /*
> * A partitioned table without any partitions is marked as
> * a dummy rel.
> */
> set_dummy_rel_pathlist(rel);
> }
Not following? Surely we need to mark the childless parent as dummy at
some point, and that seems like as good a place as any.
> Finally, it's not in the patch, but how about visiting
> get_relation_constraints() for revising this block of code:
That seems like probably an independent patch --- do you want to write it?
regards, tom lane
Commits
-
Clean up handling of constraint_exclusion and enable_partition_pruning.
- e03ff739695c 12.0 landed
- 11ea45ffec9a 11.3 landed
-
Add test case exercising formerly-unreached code in inheritance_planner.
- 8fba397f0ca7 12.0 landed
-
Speed up planning when partitions can be pruned at plan time.
- 428b260f87e8 12.0 landed
-
Avoid crash in partitionwise join planning under GEQO.
- 7ad6498fd5a6 12.0 landed
- d70c147fa217 11.3 landed
-
Avoid passing query tlist around separately from root->processed_tlist.
- 333ed246c6f3 12.0 landed
-
Build "other rels" of appendrel baserels in a separate step.
- 53bcf5e3dbea 12.0 landed
-
Get rid of duplicate child RTE for a partitioned table.
- e8d5dd6be79e 12.0 landed
-
Rearrange make_partitionedrel_pruneinfo to avoid work when we can't prune.
- 734308a22072 12.0 landed
-
Don't copy PartitionBoundInfo in set_relation_partition_info.
- c8151e642368 12.0 landed
-
Move building of child base quals out into a new function
- 80579f9bb171 12.0 landed
-
Reorganize planner code moved in b60c39759908
- d723f56872a9 12.0 landed
-
Move inheritance expansion code into its own file
- b60c39759908 12.0 landed
-
Fix inherited UPDATE/DELETE with UNION ALL subqueries.
- c03ad5602f52 9.4.0 cited
-
Rearrange planner to save the whole PlannerInfo (subroot) for a subquery.
- b3aaf9081a1a 9.2.0 cited