From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Geoghegan <pg@bowt.ie>
Cc: Jason Kim <git@jasonk.me>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: Missing SELECT output on btree_gin char, BTLess* strategy
Date: Tue, 10 Aug 2021 13:14:07 -0400
Message-ID: <3821851.1628615647@sss.pgh.pa.us> (raw)
In-Reply-To: <CAH2-Wz=BOCuJgG6eAGu=aPxtFOK7EWx+xAywSh9wzkwXvmxZ0A@mail.gmail.com>
References: <20210810001649.htnltbh7c63re42p@jasonk.me>
<CAH2-Wz=BOCuJgG6eAGu=aPxtFOK7EWx+xAywSh9wzkwXvmxZ0A@mail.gmail.com>
Peter Geoghegan <pg@bowt.ie> writes:
> On Mon, Aug 9, 2021 at 6:15 PM Jason Kim <git@jasonk.me> wrote:
>> The expected output in contrib/btree_gin/expected/char.out is wrong for the
>> first two SELECTs using the BTLess* strategies: they should not be empty.
> Isn't this index corruption, or at least an inconsistent opclass?
Indeed. After a bit of poking around, I realized that btree_gin's
leftmostvalue_char() is not on the same page as btcharcmp() about
whether type "char" is signed or unsigned.
AFAICT, only the latter function matters while making index entries,
while the wrong value from leftmostvalue_char() affects only search
results. So we can just fix it, as attached.
regards, tom lane
Attachments:btree_gin-is-wrong-about-char-signedness.patch (text/x-diff, 969B) downloaddiff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.cindex e05b5c60ca..c50d68ce18 100644--- a/contrib/btree_gin/btree_gin.c+++ b/contrib/btree_gin/btree_gin.c@@ -357,7 +357,7 @@ GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
static Datum
leftmostvalue_char(void)
{
- return CharGetDatum(SCHAR_MIN);+ return CharGetDatum(0);
}
GIN_SUPPORT(char, false, leftmostvalue_char, btcharcmp)
diff --git a/contrib/btree_gin/expected/char.out b/contrib/btree_gin/expected/char.outindex 09e0315de0..6563546d3c 100644--- a/contrib/btree_gin/expected/char.out+++ b/contrib/btree_gin/expected/char.out@@ -7,12 +7,19 @@ CREATE INDEX idx_char ON test_char USING gin (i);
SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
i
---
-(0 rows)+ a+ b+ c+(3 rows)
SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
i
---
-(0 rows)+ a+ b+ c+ d+(4 rows)
SELECT * FROM test_char WHERE i='d'::"char" ORDER BY i;
i =
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, pg@bowt.ie, git@jasonk.me, pgsql-bugs@lists.postgresql.org
Subject: Re: Missing SELECT output on btree_gin char, BTLess* strategy
In-Reply-To: <3821851.1628615647@sss.pgh.pa.us>
* 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