Skip to content

Commit 902900b

Browse files
committed
Adjust reltarget assignment for UPPERREL_PARTIAL_DISTINCT rel
A comment in grouping_planner() claimed that the PlannerInfo upper_targets array was not used in core code. However, the code that generated the paths for the UPPERREL_PARTIAL_DISTINCT rel made that comment untrue. Here we adjust the create_distinct_paths() function signature to pass down the PathTarget the same as is done for create_grouping_paths(), thus making the aforementioned comment true again. In passing adjust the order of the upper_targets[] assignments. These seem to be following the reverse enum order apart from UPPERREL_PARTIAL_DISTINCT. Also, update the header comment for generate_gather_paths() to mention the function is also used to create gather paths for partial distinct paths. Author: Richard Guo, David Rowley Discussion: https://postgr.es/m/CAMbWs48u9VoVOouJsys1qOaC9WVGVmBa+wT1dx8KvxF5GPzezA@mail.gmail.com
1 parent aa5edbe commit 902900b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,10 +3053,10 @@ set_worktable_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
30533053
*
30543054
* If we're generating paths for a scan or join relation, override_rows will
30553055
* be false, and we'll just use the relation's size estimate. When we're
3056-
* being called for a partially-grouped path, though, we need to override
3057-
* the rowcount estimate. (It's not clear that the particular value we're
3058-
* using here is actually best, but the underlying rel has no estimate so
3059-
* we must do something.)
3056+
* being called for a partially-grouped or partially-distinct path, though, we
3057+
* need to override the rowcount estimate. (It's not clear that the
3058+
* particular value we're using here is actually best, but the underlying rel
3059+
* has no estimate so we must do something.)
30603060
*/
30613061
void
30623062
generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)

src/backend/optimizer/plan/planner.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ static void create_one_window_path(PlannerInfo *root,
190190
WindowFuncLists *wflists,
191191
List *activeWindows);
192192
static RelOptInfo *create_distinct_paths(PlannerInfo *root,
193-
RelOptInfo *input_rel);
193+
RelOptInfo *input_rel,
194+
PathTarget *target);
194195
static void create_partial_distinct_paths(PlannerInfo *root,
195196
RelOptInfo *input_rel,
196-
RelOptInfo *final_distinct_rel);
197+
RelOptInfo *final_distinct_rel,
198+
PathTarget *target);
197199
static RelOptInfo *create_final_distinct_paths(PlannerInfo *root,
198200
RelOptInfo *input_rel,
199201
RelOptInfo *distinct_rel);
@@ -1644,8 +1646,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
16441646
*/
16451647
root->upper_targets[UPPERREL_FINAL] = final_target;
16461648
root->upper_targets[UPPERREL_ORDERED] = final_target;
1647-
root->upper_targets[UPPERREL_PARTIAL_DISTINCT] = sort_input_target;
16481649
root->upper_targets[UPPERREL_DISTINCT] = sort_input_target;
1650+
root->upper_targets[UPPERREL_PARTIAL_DISTINCT] = sort_input_target;
16491651
root->upper_targets[UPPERREL_WINDOW] = sort_input_target;
16501652
root->upper_targets[UPPERREL_GROUP_AGG] = grouping_target;
16511653

@@ -1695,7 +1697,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
16951697
if (parse->distinctClause)
16961698
{
16971699
current_rel = create_distinct_paths(root,
1698-
current_rel);
1700+
current_rel,
1701+
sort_input_target);
16991702
}
17001703
} /* end of if (setOperations) */
17011704

@@ -4568,12 +4571,14 @@ create_one_window_path(PlannerInfo *root,
45684571
* Build a new upperrel containing Paths for SELECT DISTINCT evaluation.
45694572
*
45704573
* input_rel: contains the source-data Paths
4574+
* target: the pathtarget for the result Paths to compute
45714575
*
45724576
* Note: input paths should already compute the desired pathtarget, since
45734577
* Sort/Unique won't project anything.
45744578
*/
45754579
static RelOptInfo *
4576-
create_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel)
4580+
create_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
4581+
PathTarget *target)
45774582
{
45784583
RelOptInfo *distinct_rel;
45794584

@@ -4601,7 +4606,7 @@ create_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel)
46014606
create_final_distinct_paths(root, input_rel, distinct_rel);
46024607

46034608
/* now build distinct paths based on input_rel's partial_pathlist */
4604-
create_partial_distinct_paths(root, input_rel, distinct_rel);
4609+
create_partial_distinct_paths(root, input_rel, distinct_rel, target);
46054610

46064611
/* Give a helpful error if we failed to create any paths */
46074612
if (distinct_rel->pathlist == NIL)
@@ -4643,7 +4648,8 @@ create_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel)
46434648
*/
46444649
static void
46454650
create_partial_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
4646-
RelOptInfo *final_distinct_rel)
4651+
RelOptInfo *final_distinct_rel,
4652+
PathTarget *target)
46474653
{
46484654
RelOptInfo *partial_distinct_rel;
46494655
Query *parse;
@@ -4664,7 +4670,7 @@ create_partial_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
46644670

46654671
partial_distinct_rel = fetch_upper_rel(root, UPPERREL_PARTIAL_DISTINCT,
46664672
NULL);
4667-
partial_distinct_rel->reltarget = root->upper_targets[UPPERREL_PARTIAL_DISTINCT];
4673+
partial_distinct_rel->reltarget = target;
46684674
partial_distinct_rel->consider_parallel = input_rel->consider_parallel;
46694675

46704676
/*

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