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 1pFR80-00029q-4A for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 02:46:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pFR7y-0003Iv-II for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 02:46:10 +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 1pFR7y-0003Im-75 for pgsql-hackers@lists.postgresql.org; Wed, 11 Jan 2023 02:46:10 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pFR7r-0007CA-Oo for pgsql-hackers@lists.postgresql.org; Wed, 11 Jan 2023 02:46:09 +0000 Received: by mail-pj1-x102c.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso15625573pjo.3 for ; Tue, 10 Jan 2023 18:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3n7HpornbkKWrkVgjxKISpzLAqOm1L/hO21/rNFG7Lk=; b=psbgT2McNVYqiOrdPnTA8nJPp44z6czKvp1jx23CdczHVUmaqGvuL0sCWDIZqAoELN 58k/HdeHTPIDjCiIqHa89tnlVMAYWqLvNysekINC5/Pl31gO/OtVVTIChnOxTedCUm1a vWsMu0xHG9GHfik7+uUK3LD2KL9dLzW5V9Cn/k+WuHP4vkwx6pO3i4cbRh1jXbNxSEB5 9YWkkd/V4DWP4e1NBhfxxLu73E4tbEjTpVSGcc3qTfSkB2IBxIB4w3uRpK7ZWkGf5sxB cMjr3fBINlLV7YFG1N9A/hdRW3cFbtUy8jJ6fKl7S/dqPJW/AthEfHCAGtOdsjbZCK/h wNNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3n7HpornbkKWrkVgjxKISpzLAqOm1L/hO21/rNFG7Lk=; b=liksfpmxaURP+9yuY0fHWpt+GCKNbZydopnfMdhfAJBurJPv6hHOLASDnuzCM0RMMa WUl6hhq3qJysNK8eTc3gpsY8n9VsXrJtRJ38o9A/VpmXMQLbSuqtRhKFbMObpItZ7fvX 2J8FL4mQIFyCoLZUHfKSgsMZbrY1XwD8Jz9voVPCWfg+mxDEnYcW0akK1u51UCixDdId k3uM5i4egsbEnjuxblFcBRhdSbWEcHz/REpkKFZwaHSOifbgQgZ/ktd8N+127+p3a05R XYmBr3b0iqvYLOQxig9jJ2+Mi6Q/jmfG/QbniV1ZFIsA5BwOmYXh/QYdg5ffitbw4Hho rjsw== X-Gm-Message-State: AFqh2kpRUljiKI4xi6yNd2g9Eer8H1vJ6zekWF7TfVeUVZCHnxue8USt vEh/snh0mcKJ0Ln2Vuc2LZervs2e4eyABEm8sPQ= X-Google-Smtp-Source: AMrXdXt70gmgQj1LiYh8d3jL4liIIHHEWpK7mYdgbS1iiVOFdQMbBw5yxKdJFwPkty30eqh/VouYt9p9Jq1c9xFBIJc= X-Received: by 2002:a17:90a:db0a:b0:227:b12:9b1b with SMTP id g10-20020a17090adb0a00b002270b129b1bmr929334pjv.210.1673405162453; Tue, 10 Jan 2023 18:46:02 -0800 (PST) MIME-Version: 1.0 References: <3163474.aeNJFYEL58@aivenronan> <9f61ddbf-2989-1536-b31e-6459370a6baa@postgrespro.ru> <2202180.iZASKD2KPV@aivenlaptop> In-Reply-To: From: Richard Guo Date: Wed, 11 Jan 2023 10:45:51 +0800 Message-ID: Subject: Re: Add proper planner support for ORDER BY / DISTINCT aggregates To: Dean Rasheed Cc: David Rowley , Ronan Dunklau , Justin Pryzby , Pavel Luzanov , Tom Lane , pgsql-hackers@lists.postgresql.org, Ranier Vilela Content-Type: multipart/alternative; boundary="00000000000046004d05f1f400cd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000046004d05f1f400cd Content-Type: text/plain; charset="UTF-8" On Tue, Jan 10, 2023 at 6:12 PM Dean Rasheed wrote: > While doing some random testing, I noticed that the following is broken in > HEAD: > > SELECT COUNT(DISTINCT random()) FROM generate_series(1,10); > > ERROR: ORDER/GROUP BY expression not found in targetlist > > It appears to have been broken by 1349d279, though I haven't looked at > the details. Yeah, this is definitely broken. For this query, we try to sort the scan/join path by random() before performing the Aggregate, which is an optimization implemented in 1349d2790b. However the scan/join plan's tlist does not contain random(), which I think we need to fix. Thanks Richard --00000000000046004d05f1f400cd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Tue, Jan 10, 2023 at 6:12 PM Dean Rash= eed <dean.a.rasheed@gmail.co= m> wrote:
While doing some random testing, I noticed that the following is broken in= HEAD:

SELECT COUNT(DISTINCT random()) FROM generate_series(1,10);

ERROR:=C2=A0 ORDER/GROUP BY expression not found in targetlist

It appears to have been broken by 1349d279, though I haven't looked at<= br> the details.
=C2=A0
Yeah, this is definitely bro= ken.=C2=A0 For this query, we try to sort the
scan/join path by random()= before performing the Aggregate, which is an
optimization implemented i= n 1349d2790b.=C2=A0 However the scan/join plan's
tlist does not cont= ain random(), which I think we need to fix.

Thanks
Richard
--00000000000046004d05f1f400cd--