Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup() - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup()
Date
Msg-id 2350897.1624476008@sss.pgh.pa.us
Whole thread Raw
In response to BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup()  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup()  (Tobias Wendorff <tobias.wendorff@tu-dortmund.de>)
Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup()  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> SELECT
>     '2021-01-01'::date AS month
> GROUP BY
>     rollup(month)
> ORDER BY
>     month NULLS FIRST;
> [ produces unsorted output ]

Hm, that's certainly a bug, but so far as I can tell it's specific to the
case of a constant value being used as the GROUP BY/ORDER BY target.
Which doesn't seem very likely to be interesting in practice.  Do you have
a non-toy example where things go wrong?

The issue here is that ORDER BY a constant is normally deemed to be a
no-op.  Our parse representation fails to make it clear that in this
situation, the "constant" column isn't so constant after the GROUP BY has
been applied.  There's been some discussion of changing that, but it's a
large task and isn't likely to happen overnight (much less be a plausible
candidate for back-patching).  So I'm wondering if this was reduced from
a more realistic example that we might be able to fix in some other way.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Found a buffer-overflow defect in asynchronous database connection API PQconnectPoll
Next
From: Tobias Wendorff
Date:
Subject: Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup()