On Wed, May 11, 2016 at 1:57 PM, Robert Haas <robertmh...@gmail.com> wrote: > I don't immediately understand what's going wrong here. It looks to > me like make_group_input_target() already called, and that worked OK, > but now make_partialgroup_input_target() is failing using more-or-less > the same logic. Presumably that's because make_group_input_target() > was called on final_target as returned by create_pathtarget(root, > tlist), but make_partialgroup_input_target() is being called on > grouping_target, which I'm guessing came from > make_window_input_target, which somehow lacks sortgroupref labeling. > But I don't immediately see how that would happen, so there's > obviously something I'm missing here.
So, it turns out you can reproduce this bug pretty easily without force_parallel_mode, like this: alter table int4_tbl set (parallel_degree = 4); SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42; Or you can just a query that involves a window function on a table large enough for parallelism to be considered: SELECT SUM(COUNT(aid)) OVER () FROM pgbench_accounts; The crash goes way if the target list involves at least one plain column that uses no aggregate or window function, because then the PathTarget list has a sortgrouprefs array. Trivial fix patch attached, although some more review from you (Tom Lane, PathTarget inventor and planner whiz) and David Rowley (author of this function) would be appreciated in case there are deeper issues here. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 6770836..5c5e5ab 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -4305,7 +4305,10 @@ make_partialgroup_input_target(PlannerInfo *root, PathTarget *final_target) foreach(lc, final_target->exprs) { Expr *expr = (Expr *) lfirst(lc); - Index sgref = final_target->sortgrouprefs[i]; + Index sgref = 0; + + if (final_target->sortgrouprefs != NULL) + sgref = final_target->sortgrouprefs[i]; if (sgref && parse->groupClause && get_sortgroupref_clause_noerr(sgref, parse->groupClause) != NULL)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers