Re: Index plan returns different results to sequential scan

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: John Burns <john(at)impactdatametrics(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Index plan returns different results to sequential scan
Date: 2024-03-22 08:28:29
Message-ID: 4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 3/22/24 08:43, Tomas Vondra wrote:
> On 3/22/24 02:40, Peter Geoghegan wrote:
>> On Thu, Mar 21, 2024 at 9:22 PM Tomas Vondra
>> <tomas(dot)vondra(at)enterprisedb(dot)com> wrote:
>>> I don't know what the problem is, or whether it's a big in PG or in the
>>> postcode extension (I agree the extension is fairly straightforward).
>>
>> Could you try running amcheck's bt_index_check function against the index?
>>
>
> I tried (on master). It doesn't report anything:
>
> test=# select bt_index_check('xxx_postcode_idx', 't');
> bt_index_check
> ----------------
>
> (1 row)
>
> I also tried looking at the index using bt_page_items from pageinspect,
> and I did not notice anything obviously wrong. But I don't have much
> experience with btree at such low level ...
>

I realized I can create an index on e5adcb789, apply dd299df81 and
create another index, and then compare what bt_page_items says for those.

FWIW xxx_postcode_idx (created before e5adcb789) keeps returning the
correct data even after dd299df81 gets applied.

I'll only show 5 rows - the only difference is in the first item (which
I guess is hikey?), all other items are exactly the same.

For the index created on e5adcb789 (that returns the correct results
even with the new build), I get this:

test=# select * from bt_page_items(get_Raw_page('xxx_postcode_idx', 1))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+--------+---------+-------+------+-------------------------
1 | (2,15) | 16 | f | f | ce 51 20 50 00 00 00 00
2 | (0,1) | 16 | f | f | 27 48 20 01 00 00 00 00
3 | (0,2) | 16 | f | f | 30 48 20 01 00 00 00 00
4 | (0,3) | 16 | f | f | 41 48 20 01 00 00 00 00
5 | (0,4) | 16 | f | f | 41 48 20 01 00 00 00 00
(5 rows)

test=# select * from bt_page_items(get_Raw_page('xxx_postcode_idx', 2))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+--------+---------+-------+------+-------------------------
1 | (4,5) | 16 | f | f | 25 60 20 50 00 00 00 00
2 | (2,15) | 16 | f | f | ce 51 20 50 00 00 00 00
3 | (2,16) | 16 | f | f | d3 51 20 50 00 00 00 00
4 | (2,17) | 16 | f | f | d3 51 20 50 00 00 00 00
5 | (2,18) | 16 | f | f | d3 51 20 50 00 00 00 00
(5 rows)

test=# select * from bt_page_items(get_Raw_page('xxx_postcode_idx', 3))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+--------+---------+-------+------+-------------------------
1 | (1,0) | 8 | f | f |
2 | (2,15) | 16 | f | f | ce 51 20 50 00 00 00 00
3 | (4,5) | 16 | f | f | 25 60 20 50 00 00 00 00
(3 rows)

test=# select * from bt_page_items(get_Raw_page('xxx_postcode_idx', 4))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+-------+---------+-------+------+-------------------------
1 | (4,5) | 16 | f | f | 25 60 20 50 00 00 00 00
2 | (4,6) | 16 | f | f | 25 60 20 50 00 00 00 00
3 | (4,7) | 16 | f | f | 25 60 20 50 00 00 00 00
4 | (4,8) | 16 | f | f | 25 60 20 50 00 00 00 00
5 | (4,9) | 16 | f | f | 30 60 20 50 00 00 00 00
(5 rows)

while for the index created with dd299df81 (and returning incomplete
results) I get this:

test=# select * from bt_page_items(get_Raw_page('xxx2_postcode_idx', 1))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+-------+---------+-------+------+-------------------------
1 | (2,1) | 16 | f | f | ce 51 20 50 00 00 00 00
2 | (0,1) | 16 | f | f | 27 48 20 01 00 00 00 00
3 | (0,2) | 16 | f | f | 30 48 20 01 00 00 00 00
4 | (0,3) | 16 | f | f | 41 48 20 01 00 00 00 00
5 | (0,4) | 16 | f | f | 41 48 20 01 00 00 00 00
(5 rows)

test=# select * from bt_page_items(get_Raw_page('xxx2_postcode_idx', 2))
limit 5;
itemoffset | ctid | itemlen | nulls | vars |
data
------------+----------+---------+-------+------+-------------------------------------------------
1 | (4,4097) | 24 | f | f | 25 60 20 50 00 00 00
00 00 00 00 00 04 00 04 00
2 | (2,15) | 16 | f | f | ce 51 20 50 00 00 00 00
3 | (2,16) | 16 | f | f | d3 51 20 50 00 00 00 00
4 | (2,17) | 16 | f | f | d3 51 20 50 00 00 00 00
5 | (2,18) | 16 | f | f | d3 51 20 50 00 00 00 00
(5 rows)

test=# select * from bt_page_items(get_Raw_page('xxx2_postcode_idx', 3))
limit 5;
itemoffset | ctid | itemlen | nulls | vars |
data
------------+----------+---------+-------+------+-------------------------------------------------
1 | (1,0) | 8 | f | f |
2 | (2,1) | 16 | f | f | ce 51 20 50 00 00 00 00
3 | (4,4097) | 24 | f | f | 25 60 20 50 00 00 00
00 00 00 00 00 04 00 04 00
(3 rows)

test=# select * from bt_page_items(get_Raw_page('xxx2_postcode_idx', 4))
limit 5;
itemoffset | ctid | itemlen | nulls | vars | data
------------+-------+---------+-------+------+-------------------------
1 | (4,5) | 16 | f | f | 25 60 20 50 00 00 00 00
2 | (4,6) | 16 | f | f | 25 60 20 50 00 00 00 00
3 | (4,7) | 16 | f | f | 25 60 20 50 00 00 00 00
4 | (4,8) | 16 | f | f | 25 60 20 50 00 00 00 00
5 | (4,9) | 16 | f | f | 30 60 20 50 00 00 00 00
(5 rows)

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message walther 2024-03-22 08:33:38 Re: Regression tests fail with musl libc because libpq.so can't be loaded
Previous Message walther 2024-03-22 08:12:47 Re: Regression tests fail with musl libc because libpq.so can't be loaded