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
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