pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: John Burns <john@impactdatametrics.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Index plan returns different results to sequential scan
Date: Fri, 22 Mar 2024 09:28:29 +0100
Message-ID: <4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com> (raw)
In-Reply-To: <bb9cf18a-c83c-4857-b3f0-4566918b0249@enterprisedb.com>
References: <3B86F188-F4BF-4331-AD79-E5FF2D0711A3@impactdatametrics.com>
	<72600f8a-4231-45b7-a116-8ceec5ccf66e@enterprisedb.com>
	<881DF028-5222-486C-A13B-451239C1316F@impactdatametrics.com>
	<27496161-e7ec-47bd-b559-3571fde4dcb4@enterprisedb.com>
	<b4ee59ca-a99a-474f-97cc-b26d4ce51e43@enterprisedb.com>
	<CAH2-Wzmyevb7yfM0MkmvWQKA8Pah=SSotRJf=LTw1upihhgtZQ@mail.gmail.com>
	<bb9cf18a-c83c-4857-b3f0-4566918b0249@enterprisedb.com>



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.vondra@enterprisedb.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





view thread (10+ messages)  latest in thread

Message-ID: <4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com>
Permalink:  ../4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com/
Also on:    postgresql.org/message-id/4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com

 · 

reply

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: tomas.vondra@enterprisedb.com, pg@bowt.ie, john@impactdatametrics.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Index plan returns different results to sequential scan
  In-Reply-To: <4d5e0228-b1cb-438c-8ab2-d3f94ce4c7eb@enterprisedb.com>

* 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