|
16 | 16 | *
|
17 | 17 | *
|
18 | 18 | * IDENTIFICATION
|
19 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.57 2008/10/21 20:42:53 tgl Exp $ |
| 19 | + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.58 2008/10/22 20:17:52 tgl Exp $ |
20 | 20 | *
|
21 | 21 | *-------------------------------------------------------------------------
|
22 | 22 | */
|
@@ -565,7 +565,6 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
|
565 | 565 | subroot->cte_plan_ids=NIL;
|
566 | 566 | subroot->eq_classes=NIL;
|
567 | 567 | subroot->append_rel_list=NIL;
|
568 |
| -subroot->placeholder_list=NIL; |
569 | 568 | subroot->hasRecursion= false;
|
570 | 569 | subroot->wt_param_id=-1;
|
571 | 570 | subroot->non_recursive_plan=NULL;
|
@@ -627,20 +626,18 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
|
627 | 626 | /*
|
628 | 627 | * Adjust level-0 varnos in subquery so that we can append its rangetable
|
629 | 628 | * to upper query's. We have to fix the subquery's append_rel_list
|
630 |
| - *and placeholder_listas well. |
| 629 | + * as well. |
631 | 630 | */
|
632 | 631 | rtoffset=list_length(parse->rtable);
|
633 | 632 | OffsetVarNodes((Node*)subquery,rtoffset,0);
|
634 | 633 | OffsetVarNodes((Node*)subroot->append_rel_list,rtoffset,0);
|
635 |
| -OffsetVarNodes((Node*)subroot->placeholder_list,rtoffset,0); |
636 | 634 |
|
637 | 635 | /*
|
638 | 636 | * Upper-level vars in subquery are now one level closer to their parent
|
639 | 637 | * than before.
|
640 | 638 | */
|
641 | 639 | IncrementVarSublevelsUp((Node*)subquery,-1,1);
|
642 | 640 | IncrementVarSublevelsUp((Node*)subroot->append_rel_list,-1,1);
|
643 |
| -IncrementVarSublevelsUp((Node*)subroot->placeholder_list,-1,1); |
644 | 641 |
|
645 | 642 | /*
|
646 | 643 | * The subquery's targetlist items are now in the appropriate form to
|
@@ -706,48 +703,42 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
|
706 | 703 | parse->rowMarks=list_concat(parse->rowMarks,subquery->rowMarks);
|
707 | 704 |
|
708 | 705 | /*
|
709 |
| - * We also have to fix the relid sets of any FlattenedSubLink, |
710 |
| - * PlaceHolderVar, and PlaceHolderInfo nodes in the parent query. |
711 |
| - * (This could perhaps be done by ResolveNew, but it would clutter that |
712 |
| - * routine's API unreasonably.) Note in particular that any placeholder |
713 |
| - * nodes just created by insert_targetlist_placeholders() wiil be adjusted. |
| 706 | + * We also have to fix the relid sets of any FlattenedSubLink and |
| 707 | + * PlaceHolderVar nodes in the parent query. (This could perhaps be done |
| 708 | + * by ResolveNew, but it would clutter that routine's API unreasonably.) |
| 709 | + * Note in particular that any PlaceHolderVar nodes just created by |
| 710 | + * insert_targetlist_placeholders() will be adjusted, so having created |
| 711 | + * them with the subquery's varno is correct. |
714 | 712 | *
|
715 | 713 | * Likewise, relids appearing in AppendRelInfo nodes have to be fixed (but
|
716 | 714 | * we took care of their translated_vars lists above).We already checked
|
717 | 715 | * that this won't require introducing multiple subrelids into the
|
718 | 716 | * single-slot AppendRelInfo structs.
|
719 | 717 | */
|
720 |
| -if (parse->hasSubLinks||root->placeholder_list||root->append_rel_list) |
| 718 | +if (parse->hasSubLinks||root->glob->lastPHId!=0|| |
| 719 | +root->append_rel_list) |
721 | 720 | {
|
722 | 721 | Relidssubrelids;
|
723 | 722 |
|
724 | 723 | subrelids=get_relids_in_jointree((Node*)subquery->jointree, false);
|
725 |
| -substitute_multiple_relids((Node*)parse, |
726 |
| -varno,subrelids); |
727 |
| -substitute_multiple_relids((Node*)root->placeholder_list, |
728 |
| -varno,subrelids); |
729 |
| -fix_append_rel_relids(root->append_rel_list, |
730 |
| -varno,subrelids); |
| 724 | +substitute_multiple_relids((Node*)parse,varno,subrelids); |
| 725 | +fix_append_rel_relids(root->append_rel_list,varno,subrelids); |
731 | 726 | }
|
732 | 727 |
|
733 | 728 | /*
|
734 |
| - * And now add subquery's AppendRelInfos and PlaceHolderInfos to our lists. |
735 |
| - * Note that any placeholders pulled up from the subquery will appear |
736 |
| - * after any we just created; this preserves the property that placeholders |
737 |
| - * can only refer to other placeholders that appear later in the list |
738 |
| - * (needed by fix_placeholder_eval_levels). |
| 729 | + * And now add subquery's AppendRelInfos to our list. |
739 | 730 | */
|
740 | 731 | root->append_rel_list=list_concat(root->append_rel_list,
|
741 | 732 | subroot->append_rel_list);
|
742 |
| -root->placeholder_list=list_concat(root->placeholder_list, |
743 |
| -subroot->placeholder_list); |
744 | 733 |
|
745 | 734 | /*
|
746 | 735 | * We don't have to do the equivalent bookkeeping for outer-join info,
|
747 |
| - * because that hasn't been set up yet. |
| 736 | + * because that hasn't been set up yet. placeholder_list likewise. |
748 | 737 | */
|
749 | 738 | Assert(root->join_info_list==NIL);
|
750 | 739 | Assert(subroot->join_info_list==NIL);
|
| 740 | +Assert(root->placeholder_list==NIL); |
| 741 | +Assert(subroot->placeholder_list==NIL); |
751 | 742 |
|
752 | 743 | /*
|
753 | 744 | * Miscellaneous housekeeping.
|
@@ -1606,10 +1597,10 @@ reduce_outer_joins_pass2(Node *jtnode,
|
1606 | 1597 | * substitute_multiple_relids - adjust node relid sets after pulling up
|
1607 | 1598 | * a subquery
|
1608 | 1599 | *
|
1609 |
| - * Find any FlattenedSubLink, PlaceHolderVar,orPlaceHolderInfo nodes in the |
1610 |
| - *given tree thatreference the pulled-up relid, and change them to reference |
1611 |
| - *the replacementrelid(s). We do not need to recurse into subqueries, since |
1612 |
| - *no subquery ofthe current top query could (yet) contain such a reference. |
| 1600 | + * Find any FlattenedSubLinkorPlaceHolderVar nodes in the given tree that |
| 1601 | + * reference the pulled-up relid, and change them to reference the replacement |
| 1602 | + * relid(s). We do not need to recurse into subqueries, since no subquery of |
| 1603 | + * the current top query could (yet) contain such a reference. |
1613 | 1604 | *
|
1614 | 1605 | * NOTE: although this has the form of a walker, we cheat and modify the
|
1615 | 1606 | * nodes in-place. This should be OK since the tree was copied by ResolveNew
|
@@ -1662,26 +1653,11 @@ substitute_multiple_relids_walker(Node *node,
|
1662 | 1653 | }
|
1663 | 1654 | /* fall through to examine children */
|
1664 | 1655 | }
|
1665 |
| -if (IsA(node,PlaceHolderInfo)) |
1666 |
| -{ |
1667 |
| -PlaceHolderInfo*phinfo= (PlaceHolderInfo*)node; |
| 1656 | +/* Shouldn't need to handle planner auxiliary nodes here */ |
| 1657 | +Assert(!IsA(node,SpecialJoinInfo)); |
| 1658 | +Assert(!IsA(node,AppendRelInfo)); |
| 1659 | +Assert(!IsA(node,PlaceHolderInfo)); |
1668 | 1660 |
|
1669 |
| -if (bms_is_member(context->varno,phinfo->ph_eval_at)) |
1670 |
| -{ |
1671 |
| -phinfo->ph_eval_at=bms_union(phinfo->ph_eval_at, |
1672 |
| -context->subrelids); |
1673 |
| -phinfo->ph_eval_at=bms_del_member(phinfo->ph_eval_at, |
1674 |
| -context->varno); |
1675 |
| -} |
1676 |
| -if (bms_is_member(context->varno,phinfo->ph_needed)) |
1677 |
| -{ |
1678 |
| -phinfo->ph_needed=bms_union(phinfo->ph_needed, |
1679 |
| -context->subrelids); |
1680 |
| -phinfo->ph_needed=bms_del_member(phinfo->ph_needed, |
1681 |
| -context->varno); |
1682 |
| -} |
1683 |
| -/* fall through to examine children */ |
1684 |
| -} |
1685 | 1661 | returnexpression_tree_walker(node,substitute_multiple_relids_walker,
|
1686 | 1662 | (void*)context);
|
1687 | 1663 | }
|
|