Skip to content

Commit aa97890

Browse files
committed
Don't search for volatile expr in find_em_expr_usable_for_sorting_rel
While prepare_sort_from_pathkeys has to be concerned about matching up a volatile expression to the proper tlist entry, we don't need to do that in find_em_expr_usable_for_sorting_rel becausee such a sort will have to be postponed anyway. Author: James Coleman Reviewed-by: Tomas Vondra Backpatch-through: 13 Discussion: https://postgr.es/m/CAAaqYe8cK3g5CfLC4w7bs%3DhC0mSksZC%3DH5M8LSchj5e5OxpTAg%40mail.gmail.com
1 parent d016763 commit aa97890

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/backend/optimizer/path/equivclass.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,6 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
813813
{
814814
EquivalenceMember *em = lfirst(lc_em);
815815
Expr *em_expr = em->em_expr;
816-
PathTarget *target = rel->reltarget;
817-
ListCell *lc_target_expr;
818816

819817
/*
820818
* We shouldn't be trying to sort by an equivalence class that
@@ -848,30 +846,14 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
848846
* As long as the expression isn't volatile then
849847
* prepare_sort_from_pathkeys is able to generate a new target entry,
850848
* so there's no need to verify that one already exists.
849+
*
850+
* While prepare_sort_from_pathkeys has to be concerned about matching
851+
* up a volatile expression to the proper tlist entry, it doesn't seem
852+
* valuable here to expend the work trying to find a match in the
853+
* target's exprs since such a sort will have to be postponed anyway.
851854
*/
852855
if (!ec->ec_has_volatile)
853856
return em->em_expr;
854-
855-
/*
856-
* If, however, it's volatile, we have to verify that the
857-
* equivalence member's expr is already generated in the
858-
* relation's target (we do strip relabels first from both
859-
* expressions, which is cheap and might allow us to match
860-
* more expressions).
861-
*/
862-
while (em_expr && IsA(em_expr, RelabelType))
863-
em_expr = ((RelabelType *) em_expr)->arg;
864-
865-
foreach(lc_target_expr, target->exprs)
866-
{
867-
Expr *target_expr = lfirst(lc_target_expr);
868-
869-
while (target_expr && IsA(target_expr, RelabelType))
870-
target_expr = ((RelabelType *) target_expr)->arg;
871-
872-
if (equal(target_expr, em_expr))
873-
return em->em_expr;
874-
}
875857
}
876858

877859
/* We didn't find any suitable equivalence class expression */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy