Improve find_em_expr_usable_for_sorting_rel comment
authorTomas Vondra <[email protected]>
Tue, 22 Dec 2020 01:00:39 +0000 (02:00 +0100)
committerTomas Vondra <[email protected]>
Tue, 22 Dec 2020 01:00:51 +0000 (02:00 +0100)
Clarify the relationship between find_em_expr_usable_for_sorting_rel and
prepare_sort_from_pathkeys, i.e. what restrictions need to be shared
between those two places.

Author: James Coleman
Reviewed-by: Tomas Vondra
Backpatch-through: 13
Discussion: https://postgr.es/m/CAAaqYe8cK3g5CfLC4w7bs%3DhC0mSksZC%3DH5M8LSchj5e5OxpTAg%40mail.gmail.com

src/backend/optimizer/path/equivclass.c
src/backend/optimizer/plan/createplan.c

index 600fa1263a7f2884859d3ea82d3ded302daa30c3..c33af06ec0ed65c6be06f2c4f96e67f90c1ac904 100644 (file)
@@ -798,9 +798,11 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
 }
 
 /*
- * Find an equivalence class member expression that can be safely used by a
- * sort node on top of the provided relation. The rules here must match those
- * applied in prepare_sort_from_pathkeys.
+ * Find an equivalence class member expression that can be safely used to build
+ * a sort node using the provided relation. The rules are a subset of those
+ * applied in prepare_sort_from_pathkeys since that function deals with sorts
+ * that must be delayed until the last stages of query execution, while here
+ * we only care about proactive sorts.
  */
 Expr *
 find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
index 5ecf9f40658a47a43c3e546df066ce235be8596a..f7a8dae3c6483c1b50c37b4603ad78de5f1fd912 100644 (file)
@@ -5850,6 +5850,9 @@ make_incrementalsort(Plan *lefttree, int numCols, int nPresortedCols,
  *
  * Returns the node which is to be the input to the Sort (either lefttree,
  * or a Result stacked atop lefttree).
+ *
+ * Note: Restrictions on what expressions are safely sortable may also need to
+ * be added to find_em_expr_usable_for_sorting_rel.
  */
 static Plan *
 prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys,