On Sat, Dec 3, 2016 at 5:20 PM, Tomas Vondra <tomas.vondra@xxxxxxxxxxxxxxx> wrote: > So the sort is probably slow because of CPU, as it compares strings. In > some locales that may be very expensive - not sure which locale is used > in this case, as it was not mentioned. I wonder what it would take to teach the optimizer to consider the possibility of a "collation strength reduction". In other words, for aggregates that perform a sort (or for aggregates that rely on the presence of a sort node without there being some other dependency on the sort node), it should be possible for the optimizer to determine that it would be just fine to use the C locale, since the user isn't entitled to assume anything about the exact sort order. There are of course cases where this can make a huge difference. -- Peter Geoghegan -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general