From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: David Raymond <David.Raymond@tomtom.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs\@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16031: Group by returns duplicate groups
Date: Tue, 01 Oct 2019 06:40:47 +0100
Message-ID: <871rvxm4je.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <VI1PR07MB6029CF9430ECED44CB457E3B87820@VI1PR07MB6029.eurprd07.prod.outlook.com>
References: <16031-4ef55395a5fbb687@postgresql.org>
<18850.1569867434@sss.pgh.pa.us>
<VI1PR07MB602902D7CE166594FC1EF5AE87820@VI1PR07MB6029.eurprd07.prod.outlook.com>
<VI1PR07MB6029CF9430ECED44CB457E3B87820@VI1PR07MB6029.eurprd07.prod.outlook.com>
>>>>> "David" == David Raymond <David.Raymond@tomtom.com> 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andrew@tao11.riddles.org.uk, David.Raymond@tomtom.com, tgl@sss.pgh.pa.us
Subject: Re: BUG #16031: Group by returns duplicate groups
In-Reply-To: <871rvxm4je.fsf@news-spur.riddles.org.uk>
References: <16031-4ef55395a5fbb687@postgresql.org> <18850.1569867434@sss.pgh.pa.us> <VI1PR07MB602902D7CE166594FC1EF5AE87820@VI1PR07MB6029.eurprd07.prod.outlook.com> <VI1PR07MB6029CF9430ECED44CB457E3B87820@VI1PR07MB6029.eurprd07.prod.outlook.com> <871rvxm4je.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox