Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFAuC-0007pk-Ir for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Oct 2019 05:41:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFAuA-0007MU-L8 for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Oct 2019 05:40:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFAuA-0007ME-DN for pgsql-bugs@lists.postgresql.org; Tue, 01 Oct 2019 05:40:58 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFAu3-0002JN-R4 for pgsql-bugs@lists.postgresql.org; Tue, 01 Oct 2019 05:40:58 +0000 Received: from [192.168.127.1] (port=56343 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.2 (FreeBSD)) (envelope-from ) id 1iFAu0-000F8Y-9P; Tue, 01 Oct 2019 05:40:48 +0000 Received: from localhost ([127.0.0.1]:16138 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.92.1 (FreeBSD)) (envelope-from ) id 1iFAu0-000CvZ-4t; Tue, 01 Oct 2019 05:40:48 +0000 From: Andrew Gierth To: David Raymond Cc: Tom Lane , "pgsql-bugs\@lists.postgresql.org" Subject: Re: BUG #16031: Group by returns duplicate groups In-Reply-To: (David Raymond's message of "Mon, 30 Sep 2019 21:48:59 +0000") Message-ID: <871rvxm4je.fsf@news-spur.riddles.org.uk> References: <16031-4ef55395a5fbb687@postgresql.org> <18850.1569867434@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (berkeley-unix) Date: Tue, 01 Oct 2019 06:40:47 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "David" == David Raymond writes: David> Looking possibly like indexing is part of the issue at the David> moment. Your original EXPLAIN didn't show any index scans being used...? I can think of a possible explanation if there's some other value in the big table which, due to some collation bug, is not consistently being compared as < 'DK' or > 'DK'. Unfortunately, we have two code paths for comparison, and one of them can't easily be exercised directly from SQL, since it is only used for sorts (and therefore also index builds). Can you try these queries: set enable_indexscan=off; set enable_bitmapscan=off; select count(*) c0, count(*) filter (where bttextcmp(name,'DK') < 0) c1_lt, count(*) filter (where bttextcmp(name,'DK') = 0) c1_eq, count(*) filter (where bttextcmp(name,'DK') > 0) c1_gt, count(*) filter (where bttextcmp('DK',name) > 0) c2_lt, count(*) filter (where bttextcmp('DK',name) = 0) c2_eq, count(*) filter (where bttextcmp('DK',name) < 0) c2_gt from big_table; with sd as (select name, row_number() over (order by name) rnum from big_table) select name from sd where rnum >= (select min(rnum) from sd where name='DK') and rnum <= (select max(rnum) from sd where name='DK') and name <> 'DK'; -- Andrew (irc:RhodiumToad)