Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw8Q1-0002sK-Uv for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Jun 2021 19:20:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lw8Q0-0007F9-TE for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Jun 2021 19:20:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw8Q0-0007Ez-Md for pgsql-bugs@lists.postgresql.org; Wed, 23 Jun 2021 19:20:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw8Py-0001Yq-L1 for pgsql-bugs@lists.postgresql.org; Wed, 23 Jun 2021 19:20:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 15NJK8ma2350898; Wed, 23 Jun 2021 15:20:09 -0400 From: Tom Lane To: tobias.wendorff@tu-dortmund.de cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17071: ORDER BY gets ignored when result set has only one row, but another one gets added by rollup() In-reply-to: <17071-24dc13fbfa29672d@postgresql.org> References: <17071-24dc13fbfa29672d@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 23 Jun 2021 13:05:23 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2350896.1624476008.1@sss.pgh.pa.us> Date: Wed, 23 Jun 2021 15:20:08 -0400 Message-ID: <2350897.1624476008@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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