firtst release
Revision | 96588f8576a77b1a0d512f576bb31cada6e9184a (tree) |
---|---|
Time | 2019-10-29 18:47:17 |
Author | Kyotaro Horiguchi <horikyota.ntt@gmai...> |
Commiter | Kyotaro Horiguchi |
Follow the change in PG12.
Commit 428b260f87 breaks the prior assumptions by adding one more
planning cycle for updates on partitioned tables. Follow the change.
@@ -3732,32 +3732,50 @@ setup_hint_enforcement(PlannerInfo *root, RelOptInfo *rel, | ||
3732 | 3732 | return 0; |
3733 | 3733 | } |
3734 | 3734 | |
3735 | - /* Forget about the parent of another subquery */ | |
3736 | - if (root != current_hint_state->current_root) | |
3737 | - current_hint_state->parent_relid = 0; | |
3738 | - | |
3739 | - /* Find the parent for this relation other than the registered parent */ | |
3740 | - foreach (l, root->append_rel_list) | |
3735 | + /* | |
3736 | + * Forget about the parent of another subquery, but don't forget if the | |
3737 | + * inhTargetkind of the root is not INHKIND_NONE, which signals the root | |
3738 | + * contains only appendrel members. See inheritance_planner for details. | |
3739 | + * | |
3740 | + * (PG12.0) 428b260f87 added one more planning cycle for updates on | |
3741 | + * partitioned tables and hints set up in the cycle are overriden by the | |
3742 | + * second cycle. Since I didn't find no apparent distinction between the | |
3743 | + * PlannerRoot of the cycle and that of ordinary CMD_SELECT, pg_hint_plan | |
3744 | + * accepts both cycles and the later one wins. In the second cycle root | |
3745 | + * doesn't have inheritance information at all so use the parent_relid set | |
3746 | + * in the first cycle. | |
3747 | + */ | |
3748 | + if (root->inhTargetKind == INHKIND_NONE) | |
3741 | 3749 | { |
3742 | - AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l); | |
3750 | + if (root != current_hint_state->current_root) | |
3751 | + current_hint_state->parent_relid = 0; | |
3743 | 3752 | |
3744 | - if (appinfo->child_relid == rel->relid) | |
3753 | + /* Find the parent for this relation other than the registered parent */ | |
3754 | + foreach (l, root->append_rel_list) | |
3745 | 3755 | { |
3746 | - if (current_hint_state->parent_relid != appinfo->parent_relid) | |
3756 | + AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l); | |
3757 | + | |
3758 | + if (appinfo->child_relid == rel->relid) | |
3747 | 3759 | { |
3748 | - new_parent_relid = appinfo->parent_relid; | |
3749 | - current_hint_state->current_root = root; | |
3760 | + if (current_hint_state->parent_relid != appinfo->parent_relid) | |
3761 | + { | |
3762 | + new_parent_relid = appinfo->parent_relid; | |
3763 | + current_hint_state->current_root = root; | |
3764 | + } | |
3765 | + break; | |
3750 | 3766 | } |
3751 | - break; | |
3752 | 3767 | } |
3753 | - } | |
3754 | 3768 | |
3755 | - if (!l) | |
3756 | - { | |
3757 | - /* This relation doesn't have a parent. Cancel current_hint_state. */ | |
3758 | - current_hint_state->parent_relid = 0; | |
3759 | - current_hint_state->parent_scan_hint = NULL; | |
3760 | - current_hint_state->parent_parallel_hint = NULL; | |
3769 | + if (!l) | |
3770 | + { | |
3771 | + /* | |
3772 | + * This relation doesn't have a parent. Cancel | |
3773 | + * current_hint_state. | |
3774 | + */ | |
3775 | + current_hint_state->parent_relid = 0; | |
3776 | + current_hint_state->parent_scan_hint = NULL; | |
3777 | + current_hint_state->parent_parallel_hint = NULL; | |
3778 | + } | |
3761 | 3779 | } |
3762 | 3780 | |
3763 | 3781 | if (new_parent_relid > 0) |