Aggregates with ORDER BY clause cannot be shipped to the datanode.
authorPavan Deolasee <[email protected]>
Mon, 14 Mar 2016 11:38:05 +0000 (17:08 +0530)
committerPavan Deolasee <[email protected]>
Mon, 14 Mar 2016 11:38:05 +0000 (17:08 +0530)
A query such as "SELECT sum(x ORDER BY x) FROM tab" must not be shipped to the
remote side since the transition function must receive tuples in the specified
order. While it does not make much sense in this example, there could be other
aggregares, such as json_agg, where ordering could matter

src/backend/optimizer/plan/createplan.c

index fb558376a05098e75e351cc28e5b25f149fd43c2..8d1e5730cb1968a2895de97016a718b500e1d45d 100644 (file)
@@ -5338,6 +5338,12 @@ find_referenced_cols_walker(Node *node, find_referenced_cols_context *context)
                if (((Aggref *) node)->aggdistinct)
                        return true;
 
+               /*
+                * We can not push down aggregates with ORDER BY.
+                */
+               if (((Aggref *) node)->aggorder)
+                       return true;
+
                /*
                 * We need to add aggregate reference to the new tlist if it
                 * is not already there. Phase 1 aggregate is actually returns values