pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedMissing SELECT output on btree_gin char, BTLess* strategy
3+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2021-08-10 a6bd28beb0 5a9df5d509 cd7d9b6b63 eefa4c2b5e a4957b5a72 843d2879aa 7ba487cf90 Fix failure of btree_gin indexscans with "char" type and </<= operators.
* Missing SELECT output on btree_gin char, BTLess* strategy
@ 2021-08-10 00:16 Jason Kim <git@jasonk.me>
2021-08-10 01:37 ` Re: Missing SELECT output on btree_gin char, BTLess* strategy Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 3+ messages in thread
From: Jason Kim @ 2021-08-10 00:16 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
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.
set enable_seqscan=off;
CREATE TABLE test_char (
i "char"
);
INSERT INTO test_char VALUES ('a'),('b'),('c'),('d'),('e'),('f');
CREATE INDEX idx_char ON test_char USING gin (i);
SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
gives
i
---
(0 rows)
i
---
(0 rows)
If Bitmap Scan is turned off, we get output, as expected:
set enable_bitmapscan=off;
SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
gives
i
---
a
b
c
(3 rows)
i
---
a
b
c
d
(4 rows)
I tried the following and got the same results:
- Do the inserts after the CREATE INDEX.
- Create the index with fastupdate turned off: CREATE INDEX ... WITH
(fastupdate = off).
- Reconnect (and don't forget to disable sequential scan).
- Stop and start the server: pg_ctl restart.
I'm on 15devel, but this issue appears to have been around for years.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Missing SELECT output on btree_gin char, BTLess* strategy
2021-08-10 00:16 Missing SELECT output on btree_gin char, BTLess* strategy Jason Kim <git@jasonk.me>
@ 2021-08-10 01:37 ` Peter Geoghegan <pg@bowt.ie>
2021-08-10 17:14 ` Re: Missing SELECT output on btree_gin char, BTLess* strategy Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Peter Geoghegan @ 2021-08-10 01:37 UTC (permalink / raw)
To: Jason Kim <git@jasonk.me>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
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? It
may be true that the tests show the wrong output, and always have. But
isn't the more concerning problem that the index gives wrong answers
in general, not the tests?
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Missing SELECT output on btree_gin char, BTLess* strategy
2021-08-10 00:16 Missing SELECT output on btree_gin char, BTLess* strategy Jason Kim <git@jasonk.me>
2021-08-10 01:37 ` Re: Missing SELECT output on btree_gin char, BTLess* strategy Peter Geoghegan <pg@bowt.ie>
@ 2021-08-10 17:14 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2021-08-10 17:14 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: Jason Kim <git@jasonk.me>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
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) download
diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c
index 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.out
index 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 =
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-08-10 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 00:16 Missing SELECT output on btree_gin char, BTLess* strategy Jason Kim <git@jasonk.me>
2021-08-10 01:37 ` Peter Geoghegan <pg@bowt.ie>
2021-08-10 17:14 ` Tom Lane <tgl@sss.pgh.pa.us>
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