Commit 49635d7b authored by Tom Lane's avatar Tom Lane

Minor additional refactoring of planner.c's PathTarget handling.

Teach make_group_input_target() and make_window_input_target() to work
entirely with the PathTarget representation of tlists, rather than
constructing a tlist and immediately deconstructing it into PathTarget
format.  In itself this only saves a few palloc's; the bigger picture is
that it opens the door for sharing cost_qual_eval work across all of
planner.c's constructions of PathTargets.  I'll come back to that later.

In support of this, flesh out tlist.c's infrastructure for PathTargets
a bit more.
parent 92f03fe7
This diff is collapsed.
...@@ -623,6 +623,17 @@ copy_pathtarget(PathTarget *src) ...@@ -623,6 +623,17 @@ copy_pathtarget(PathTarget *src)
return dst; return dst;
} }
/*
* create_empty_pathtarget
* Create an empty (zero columns, zero cost) PathTarget.
*/
PathTarget *
create_empty_pathtarget(void)
{
/* This is easy, but we don't want callers to hard-wire this ... */
return (PathTarget *) palloc0(sizeof(PathTarget));
}
/* /*
* add_column_to_pathtarget * add_column_to_pathtarget
* Append a target column to the PathTarget. * Append a target column to the PathTarget.
...@@ -655,6 +666,41 @@ add_column_to_pathtarget(PathTarget *target, Expr *expr, Index sortgroupref) ...@@ -655,6 +666,41 @@ add_column_to_pathtarget(PathTarget *target, Expr *expr, Index sortgroupref)
} }
} }
/*
* add_new_column_to_pathtarget
* Append a target column to the PathTarget, but only if it's not
* equal() to any pre-existing target expression.
*
* The caller cannot specify a sortgroupref, since it would be unclear how
* to merge that with a pre-existing column.
*
* As with make_pathtarget_from_tlist, we leave it to the caller to update
* the cost and width fields.
*/
void
add_new_column_to_pathtarget(PathTarget *target, Expr *expr)
{
if (!list_member(target->exprs, expr))
add_column_to_pathtarget(target, expr, 0);
}
/*
* add_new_columns_to_pathtarget
* Apply add_new_column_to_pathtarget() for each element of the list.
*/
void
add_new_columns_to_pathtarget(PathTarget *target, List *exprs)
{
ListCell *lc;
foreach(lc, exprs)
{
Expr *expr = (Expr *) lfirst(lc);
add_new_column_to_pathtarget(target, expr);
}
}
/* /*
* apply_pathtarget_labeling_to_tlist * apply_pathtarget_labeling_to_tlist
* Apply any sortgrouprefs in the PathTarget to matching tlist entries * Apply any sortgrouprefs in the PathTarget to matching tlist entries
......
...@@ -55,8 +55,11 @@ extern bool grouping_is_hashable(List *groupClause); ...@@ -55,8 +55,11 @@ extern bool grouping_is_hashable(List *groupClause);
extern PathTarget *make_pathtarget_from_tlist(List *tlist); extern PathTarget *make_pathtarget_from_tlist(List *tlist);
extern List *make_tlist_from_pathtarget(PathTarget *target); extern List *make_tlist_from_pathtarget(PathTarget *target);
extern PathTarget *copy_pathtarget(PathTarget *src); extern PathTarget *copy_pathtarget(PathTarget *src);
extern PathTarget *create_empty_pathtarget(void);
extern void add_column_to_pathtarget(PathTarget *target, extern void add_column_to_pathtarget(PathTarget *target,
Expr *expr, Index sortgroupref); Expr *expr, Index sortgroupref);
extern void add_new_column_to_pathtarget(PathTarget *target, Expr *expr);
extern void add_new_columns_to_pathtarget(PathTarget *target, List *exprs);
extern void apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target); extern void apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target);
/* Convenience macro to get a PathTarget with valid cost/width fields */ /* Convenience macro to get a PathTarget with valid cost/width fields */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment