Re: Issue with NULLS LAST, with postgres_fdw sort pushdown - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject Re: Issue with NULLS LAST, with postgres_fdw sort pushdown
Date
Msg-id CAFjFpReOMXWFEcbG1WYzJOXdVO3U6Puo-=NhBBg2DS7X3XY8SQ@mail.gmail.com
Whole thread Raw
In response to Re: Issue with NULLS LAST, with postgres_fdw sort pushdown  (Michael Paquier <michael.paquier@gmail.com>)
Responses Re: Issue with NULLS LAST, with postgres_fdw sort pushdown
List pgsql-hackers


On Thu, Mar 3, 2016 at 7:27 AM, Michael Paquier <michael.paquier@gmail.com> wrote:
On Wed, Mar 2, 2016 at 7:04 PM, Rajkumar Raghuwanshi
<rajkumar.raghuwanshi@enterprisedb.com> wrote:
> On Wed, Mar 2, 2016 at 2:35 PM, Ashutosh Bapat
> <ashutosh.bapat@enterprisedb.com> wrote:
>>
>> Thanks Rajkumar for your report. Let me know if the attached patch fixes
>> the issue.

         if (pathkey->pk_nulls_first)
             appendStringInfoString(buf, " NULLS FIRST");
+        else
+            appendStringInfoString(buf, " NULLS LAST");
Per explain.c, this looks inconsistent to me. Shouldn't NULLS LAST be
applied only if DESC is used in this ORDER BY clause?


I assume that you are referring to show_sortorder_options().

As per PG documentation http://www.postgresql.org/docs/9.4/static/queries-order.html, "By default, null values sort as if larger than any non-null value; that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise." What show_sortorder_options() is doing is just trying to avoid printing the defaults, which is arguably fine for an explain output; it leaves defaults to be interpreted by user. In this case we are constructing a query to be sent to the foreign server and it's better not to leave the defaults to be interpreted by the foreign server; in case it interprets them in different fashion. get_rule_orderby() also explicitly adds these options.

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: extend pgbench expressions with functions
Next
From: Tom Lane
Date:
Subject: Re: WIP: Upper planner pathification