Re: Index-only scan for btree_gist turns bpchar to char

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Japin Li <japinli(at)hotmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Index-only scan for btree_gist turns bpchar to char
Date: 2022-01-08 19:00:00
Message-ID: 7327d4f7-2dc4-0453-affa-5a916d3d907d@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

07.01.2022 12:00, Alexander Lakhin wrote:
> Hello,
> 07.01.2022 09:26, Japin Li wrote:
>> On Fri, 07 Jan 2022 at 03:21, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>
>> In any case, if we do need same() to implement the identical
>> behavior to bpchareq(), then the other solution isn't sufficient
>> either.
>>
>> So in short, it seems like we ought to do some compatibility testing
>> and see if this code misbehaves at all with an index created by the
>> old code. I don't particularly want to do that ... any volunteers?
>>
>> Thanks for your patch, it looks good to me. I'm not sure how to test this.
> I will test it tomorrow.
I've made a simple test based on the regression test (see attachment)
and can confirm that REINDEX after upgrade fixes the index contents.

Differences after upgrade but before REINDEX:
--- /tmp/pgtest/char.out        2022-01-08 21:27:43.912274805 +0300
+++ /tmp/pgtest/char.expected   2022-01-08 21:27:43.896274765 +0300
@@ -40,8 +40,8 @@
 (2 rows)
 
 SELECT * FROM chartmp WHERE a BETWEEN '31a' AND '31c';
-  a  
-------
- 31b0
+                a                
+----------------------------------
+ 31b0                           
 (1 row)
 
REINDEX INDEX charidx
Differences after upgrade and REINDEX:
Files /tmp/pgtest/char.out and /tmp/pgtest/char.expected are identical

(Unfortunately for me) I found no anomalies related to gbt_text_same()
with an index created with the previous implementation. I've added
diagnostic logging that shows when gbt_text_same() returns 0 for keys
that are the equal but have different padding. So I've observed that
gbt_text_same() returns incorrect result, but all the btree_gist tests
still pass. Moreover, unconditional "*result = 0;" in gbt_text_same()
doesn't affect the tests at all.
I've found that gbt_text_same() is called by gistKeyIsEQ() from
backend/access/gist/gistutil.c, and made gistKeyIsEQ() return false any
time. And even with such change all check-world tests still pass (except
for isolation/predicate-gist that failed due to locking of pages split
differently). So for now, I still don't know how to get incorrect query
results due to incorrect gistKeyIsEQ() behavior/excessive page splitting.

Best regards,
Alexander

Attachment Content-Type Size
btree_gist-bpchar-test.sh application/x-shellscript 1.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-01-08 19:07:21 Re: Index-only scan for btree_gist turns bpchar to char
Previous Message Justin Pryzby 2022-01-08 18:48:57 Re: pg_upgrade should truncate/remove its logs before running