Skip to content

Commit a4957b5

Browse files
committed
Fix failure of btree_gin indexscans with "char" type and </<= operators.
As a result of confusion about whether the "char" type is signed or unsigned, scans for index searches like "col < 'x'" or "col <= 'x'" would start at the middle of the index not the left end, thus missing many or all of the entries they should find. Fortunately, this is not a symptom of index corruption. It's only the search logic that is broken, and we can fix it without unpleasant side-effects. Per report from Jason Kim. This has been wrong since btree_gin's beginning, so back-patch to all supported branches. Discussion: https://postgr.es/m/20210810001649.htnltbh7c63re42p@jasonk.me
1 parent 26f5391 commit a4957b5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

contrib/btree_gin/btree_gin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ GIN_SUPPORT(bpchar, true, leftmostvalue_text, bpcharcmp)
357357
static Datum
358358
leftmostvalue_char(void)
359359
{
360-
return CharGetDatum(SCHAR_MIN);
360+
return CharGetDatum(0);
361361
}
362362

363363
GIN_SUPPORT(char, false, leftmostvalue_char, btcharcmp)

contrib/btree_gin/expected/char.out

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ CREATE INDEX idx_char ON test_char USING gin (i);
77
SELECT * FROM test_char WHERE i<'d'::"char" ORDER BY i;
88
i
99
---
10-
(0 rows)
10+
a
11+
b
12+
c
13+
(3 rows)
1114

1215
SELECT * FROM test_char WHERE i<='d'::"char" ORDER BY i;
1316
i
1417
---
15-
(0 rows)
18+
a
19+
b
20+
c
21+
d
22+
(4 rows)
1623

1724
SELECT * FROM test_char WHERE i='d'::"char" ORDER BY i;
1825
i

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy