add a redistribution missing in create_distinct_paths
authorTomas Vondra <[email protected]>
Sun, 22 Jan 2017 17:57:40 +0000 (18:57 +0100)
committerTomas Vondra <[email protected]>
Sun, 22 Jan 2017 17:57:40 +0000 (18:57 +0100)
A redistribution was missing in the loop handling paths already
sorted for the DISTINCT case. So add it there.

src/backend/optimizer/plan/planner.c

index 2f1dc845b8dbbfa8d433d2ddd4e28bbfe0246043..4ea83f0b0d3dec59efdee0de1313fe87f93072e8 100644 (file)
@@ -4929,6 +4929,16 @@ create_distinct_paths(PlannerInfo *root,
 
                        if (pathkeys_contained_in(needed_pathkeys, path->pathkeys))
                        {
+                               /*
+                                * Make sure the distribution matches the distinct clause,
+                                * needed by the UNIQUE path.
+                                *
+                                * FIXME This could probably benefit from pushing a UNIQUE
+                                * to the remote side, and only doing a merge locally.
+                                */
+                               if (!grouping_distribution_match(root, parse, path, parse->distinctClause))
+                                       path = create_remotesubplan_path(root, path, NULL);
+
                                add_path(distinct_rel, (Path *)
                                                 create_upper_unique_path(root, distinct_rel,
                                                                                                  path,