Re: Issue with NULLS LAST, with postgres_fdw sort pushdown

From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Rajkumar Raghuwanshi <rajkumar(dot)raghuwanshi(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issue with NULLS LAST, with postgres_fdw sort pushdown
Date: 2016-03-03 04:54:36
Message-ID: CAFjFpReOMXWFEcbG1WYzJOXdVO3U6Puo-=NhBBg2DS7X3XY8SQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Mar 3, 2016 at 7:27 AM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
wrote:

> On Wed, Mar 2, 2016 at 7:04 PM, Rajkumar Raghuwanshi
> <rajkumar(dot)raghuwanshi(at)enterprisedb(dot)com> wrote:
> > On Wed, Mar 2, 2016 at 2:35 PM, Ashutosh Bapat
> > <ashutosh(dot)bapat(at)enterprisedb(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-03-03 05:04:24 Re: WIP: Upper planner pathification
Previous Message Michael Paquier 2016-03-03 04:44:18 Re: extend pgbench expressions with functions