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 1m0mx6-0006lf-Jt for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jul 2021 15:25:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m0mx5-0001it-Ha for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jul 2021 15:25:35 +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 1m0mx5-0001fQ-AV for pgsql-bugs@lists.postgresql.org; Tue, 06 Jul 2021 15:25:35 +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 1m0mx2-000168-9y for pgsql-bugs@lists.postgresql.org; Tue, 06 Jul 2021 15:25:34 +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 166FPUqT1679024; Tue, 6 Jul 2021 11:25:30 -0400 From: Tom Lane To: maxim.boguk@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17084: Wrong results of distinct node. In-reply-to: <17084-9f83b67ab464cc69@postgresql.org> References: <17084-9f83b67ab464cc69@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 06 Jul 2021 14:34:35 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1679022.1625585130.1@sss.pgh.pa.us> Date: Tue, 06 Jul 2021 11:25:30 -0400 Message-ID: <1679023.1625585130@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: > During investigation of weird app behaviour I found very strange results > with sorting/dising of some dataset. I am not sure there is a PG bug here. Your query is doing DISTINCT on (among other things) > array_agg(geo_id) AS geo_ids which is going to have results that vary depending on the unspecified order in which the first-level aggregation is done. So you might by luck have more or fewer distinct array values with different plans. If you still get unstable results after changing that to, say, array_agg(geo_id order by geo_id) AS geo_ids then I'd agree we need to investigate. regards, tom lane