Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling)

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling)
Date: 2016-09-02 14:18:38
Message-ID: CACjxUsO6t4pi-VLkn9gP9emQEYkjEW1D=qCG_p0nXWUmPg7dxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 2, 2016 at 9:11 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> On 2016-09-02 09:05:35 -0500, Kevin Grittner wrote:
>> On Fri, Sep 2, 2016 at 3:31 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>>> On Tue, Aug 23, 2016 at 3:10 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
>>
>>>> =# SELECT * FROM few, ROWS FROM(generate_series(1,3));
>>>> ┌────┬─────────────────┐
>>>> │ id │ generate_series │
>>>> ├────┼─────────────────┤
>>>> │ 1 │ 1 │
>>>> │ 2 │ 1 │
>>>> │ 1 │ 2 │
>>>> │ 2 │ 2 │
>>>> │ 1 │ 3 │
>>>> │ 2 │ 3 │
>>>> └────┴─────────────────┘
>>>> (6 rows)
>>>> surely isn't what was intended. So the join order needs to be enforced.
>>>
>>> In general, we've been skeptical about giving any guarantees about
>>> result ordering.
>
> Well, it's historically how we behaved for SRFs.

And until we had synchronized scans a sequential scan always
returned rows in the order they were present in the heap.
Implementation details are not guarantees.

> I'm pretty sure that people will be confused if
> SELECT generate_series(1, 10) FROM sometbl;
> suddenly returns rows in an order that reverse from what
> generate_series() returns.

If this changes, it is probably worth a mentioning in the release
notes.

>> I think it is a very bad idea to move away from the statement that
>> a query generates a set of rows, and that no order is guaranteed
>> unless the top level has an ORDER BY clause. How hard is it to add
>> ORDER BY 1, 2 to the above query? Let the optimizer notice when a
>> node returns data in the needed order and skip the sort if possible.
>
> There's no such infrastructure for SRFS/ROWS FROM.

Well, that's something to fix (or not), but not a justification for
"except on Tuesdays when the moon is full" sorts of exceptions to
simple rules about what to expect. No ORDER BY means no order
guaranteed.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2016-09-02 14:20:23 Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling)
Previous Message Andres Freund 2016-09-02 14:15:47 Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling)