Skip to content

Commit 7469e15

Browse files
committed
Bugfix for GROUP BY on expression problem.
Problematic query was: SELECT count(*) FROM pt group by pt.id + 1;
1 parent 0a5f57d commit 7469e15

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

contrib/pg_exchange/exchange.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ EXCHANGE_Init_methods(void)
197197
/* Initialize path generator methods */
198198
exchange_path_methods.CustomName = EXCHANGEPATHNAME;
199199
exchange_path_methods.PlanCustomPath = ExchangePlanCustomPath;
200-
exchange_path_methods.ReparameterizeCustomPathByChild = NULL;
200+
exchange_path_methods.ReparameterizeCustomPathByChild = NULL;
201201

202202
exchange_plan_methods.CustomName = "ExchangePlan";
203203
exchange_plan_methods.CreateCustomScanState = EXCHANGE_Create_state;
@@ -399,7 +399,7 @@ add_exchange_paths(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry
399399
EXCH_GATHER);
400400
set_exchange_altrel(EXCH_GATHER, (ExchangePath *) path, rel, NULL, NULL,
401401
servers);
402-
path = create_distexec_path(root, rel, path, servers);
402+
path = (Path *) create_distexec_path(root, rel, path, servers);
403403
add_path(rel, path);
404404
}
405405
}
@@ -713,7 +713,6 @@ create_exchange_path(PlannerInfo *root, RelOptInfo *rel, Path *children,
713713
pathnode->pathkeys = NIL;
714714

715715
path->flags = 0;
716-
/* Contains only one path */
717716
path->custom_paths = lappend(path->custom_paths, children);
718717

719718
path->custom_private = NIL;
@@ -790,6 +789,7 @@ make_exchange(List *custom_plans, List *tlist)
790789
{
791790
CustomScan *node = makeNode(CustomScan);
792791
Plan *plan = &node->scan.plan;
792+
List *child_tlist;
793793

794794
plan->startup_cost = 1;
795795
plan->total_cost = 1;
@@ -804,9 +804,10 @@ make_exchange(List *custom_plans, List *tlist)
804804

805805
/* Setup methods and child plan */
806806
node->methods = &exchange_plan_methods;
807-
node->custom_scan_tlist = tlist;
808807
node->scan.scanrelid = 0;
809808
node->custom_plans = custom_plans;
809+
child_tlist = ((Plan *)linitial(node->custom_plans))->targetlist;
810+
node->custom_scan_tlist = child_tlist;
810811
node->custom_exprs = NIL;
811812
node->custom_private = NIL;
812813

contrib/pg_exchange/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ create_distributed_join_paths(PlannerInfo *root, RelOptInfo *joinrel,
226226
&inn_child->altrel, extra->restrictlist,
227227
bms_union(inner_servers, outer_servers));
228228
Assert(gather->altrel.part_scheme != NULL);
229-
path = create_distexec_path(root, gather->cp.path.parent, (Path *) gather,
229+
path = (Path *) create_distexec_path(root, joinrel, (Path *) gather,
230230
bms_union(inner_servers, outer_servers));
231231
dist_paths = lappend(dist_paths, path);
232232
list_free(outerrel->pathlist);

contrib/pg_exchange/nodeDistPlanExec.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ DistExec_Init_methods(void)
412412
/* Initialize path generator methods */
413413
distplanexec_path_methods.CustomName = DISTEXECPATHNAME;
414414
distplanexec_path_methods.PlanCustomPath = CreateDistExecPlan;
415-
distplanexec_path_methods.ReparameterizeCustomPathByChild = NULL;
415+
distplanexec_path_methods.ReparameterizeCustomPathByChild = NULL;
416416

417417
distplanexec_plan_methods.CustomName = "DistExecPlan";
418418
distplanexec_plan_methods.CreateCustomScanState = CreateDistPlanExecState;
@@ -440,6 +440,7 @@ make_distplanexec(List *custom_plans, List *tlist, List *private_data)
440440
CustomScan *node = makeNode(CustomScan);
441441
Plan *plan = &node->scan.plan;
442442
ListCell *lc;
443+
List *child_tlist;
443444

444445
plan->startup_cost = 10;
445446
plan->total_cost = 10;
@@ -454,9 +455,11 @@ make_distplanexec(List *custom_plans, List *tlist, List *private_data)
454455

455456
/* Setup methods and child plan */
456457
node->methods = &distplanexec_plan_methods;
457-
node->custom_scan_tlist = tlist;
458458
node->scan.scanrelid = 0;
459459
node->custom_plans = custom_plans;
460+
461+
child_tlist = ((Plan *)linitial(node->custom_plans))->targetlist;
462+
node->custom_scan_tlist = child_tlist;
460463
node->custom_exprs = NIL;
461464
node->custom_private = NIL;
462465

@@ -471,7 +474,7 @@ make_distplanexec(List *custom_plans, List *tlist, List *private_data)
471474
return node;
472475
}
473476

474-
Path *
477+
CustomPath *
475478
create_distexec_path(PlannerInfo *root, RelOptInfo *rel, Path *children,
476479
Bitmapset *servers)
477480
{
@@ -480,27 +483,29 @@ create_distexec_path(PlannerInfo *root, RelOptInfo *rel, Path *children,
480483
int member = -1;
481484

482485
pathnode->pathtype = T_CustomScan;
483-
pathnode->parent = rel;
484486
pathnode->pathtarget = rel->reltarget;
485487
pathnode->param_info = NULL;
488+
pathnode->parent = rel;
486489

487490
pathnode->parallel_aware = false; /* permanently */
488491
pathnode->parallel_safe = false; /* permanently */
489492
pathnode->parallel_workers = 0; /* permanently */
490493
pathnode->pathkeys = NIL;
491494

492-
pathnode->rows = rel->tuples;
493-
pathnode->startup_cost = 10;
494-
pathnode->total_cost = 10;
495-
496495
path->flags = 0;
497496
path->custom_paths = lappend(path->custom_paths, children);
497+
path->custom_private = NIL;
498498

499499
while ((member = bms_next_member(servers, member)) >= 0)
500500
path->custom_private = lappend_oid(path->custom_private, (Oid) member);
501501

502502
path->methods = &distplanexec_path_methods;
503-
return pathnode;
503+
504+
pathnode->rows = children->rows;
505+
pathnode->startup_cost = 100.;
506+
pathnode->total_cost = pathnode->startup_cost;
507+
508+
return path;
504509
}
505510

506511
bool

contrib/pg_exchange/nodeDistPlanExec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern char destsName[10];
3434
extern Bitmapset *extractForeignServers(CustomPath *path);
3535
extern void DistExec_Init_methods(void);
3636
extern CustomScan *make_distplanexec(List *custom_plans, List *tlist, List *private_data);
37-
extern Path *create_distexec_path(PlannerInfo *root, RelOptInfo *rel,
37+
extern CustomPath *create_distexec_path(PlannerInfo *root, RelOptInfo *rel,
3838
Path *children, Bitmapset *servers);
3939
extern bool localize_plan(PlanState *node, lcontext *context);
4040
extern void FSExtractServerName(Oid fsid, char **host, int *port);

contrib/pg_execplan/tests/test.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ SELECT count(*) FROM pt,rt WHERE pt.id=rt.id;
88
SELECT count(*) FROM pt,rt,st WHERE pt.id=rt.id and rt.id=st.id;
99
SELECT count(*) FROM pt,rt,st WHERE pt.id=rt.id and rt.id=st.payload;
1010
SELECT count(*) FROM pt,rt,st WHERE pt.id=rt.payload and rt.id=st.payload;
11+
SELECT count(*) FROM pt group by pt.id;
12+
SELECT count(*) FROM pt group by pt.id + 1;

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