|
10 | 10 | * Portions Copyright (c) 1994, Regents of the University of California |
11 | 11 | * |
12 | 12 | * IDENTIFICATION |
13 | | - * $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.9 2008/01/09 20:42:27 tgl Exp $ |
| 13 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.10 2008/03/31 16:59:26 tgl Exp $ |
14 | 14 | * |
15 | 15 | *------------------------------------------------------------------------- |
16 | 16 | */ |
@@ -1638,6 +1638,44 @@ add_child_rel_equivalences(PlannerInfo *root, |
1638 | 1638 | } |
1639 | 1639 |
|
1640 | 1640 |
|
| 1641 | +/* |
| 1642 | + * mutate_eclass_expressions |
| 1643 | + * Apply an expression tree mutator to all expressions stored in |
| 1644 | + * equivalence classes. |
| 1645 | + * |
| 1646 | + * This is a bit of a hack ... it's currently needed only by planagg.c, |
| 1647 | + * which needs to do a global search-and-replace of MIN/MAX Aggrefs |
| 1648 | + * after eclasses are already set up. Without changing the eclasses too, |
| 1649 | + * subsequent matching of ORDER BY clauses would fail. |
| 1650 | + * |
| 1651 | + * Note that we assume the mutation won't affect relation membership or any |
| 1652 | + * other properties we keep track of (which is a bit bogus, but by the time |
| 1653 | + * planagg.c runs, it no longer matters). Also we must be called in the |
| 1654 | + * main planner memory context. |
| 1655 | + */ |
| 1656 | +void |
| 1657 | +mutate_eclass_expressions(PlannerInfo *root, |
| 1658 | + Node *(*mutator) (), |
| 1659 | + void *context) |
| 1660 | +{ |
| 1661 | + ListCell *lc1; |
| 1662 | + |
| 1663 | + foreach(lc1, root->eq_classes) |
| 1664 | + { |
| 1665 | + EquivalenceClass *cur_ec = (EquivalenceClass *) lfirst(lc1); |
| 1666 | + ListCell *lc2; |
| 1667 | + |
| 1668 | + foreach(lc2, cur_ec->ec_members) |
| 1669 | + { |
| 1670 | + EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2); |
| 1671 | + |
| 1672 | + cur_em->em_expr = (Expr *) |
| 1673 | + mutator((Node *) cur_em->em_expr, context); |
| 1674 | + } |
| 1675 | + } |
| 1676 | +} |
| 1677 | + |
| 1678 | + |
1641 | 1679 | /* |
1642 | 1680 | * find_eclass_clauses_for_index_join |
1643 | 1681 | * Create joinclauses usable for a nestloop-with-inner-indexscan |
|
0 commit comments