Re: BUG #18437: The index scan result is more than the full scan result, and the primary key index has duplicate val

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: 1165125080(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18437: The index scan result is more than the full scan result, and the primary key index has duplicate val
Date: 2024-04-15 14:18:04
Message-ID: 33fd6b8acc5c3a8a34d0a8c6ee360cde4c23a5b1.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, 2024-04-15 at 13:25 +0000, PG Bug reporting form wrote:
> PostgreSQL version: 12.6
>
> I have a table sch.tb1 with the following structure:
>
> dste_pg_db=# \d sch.tb1
> ...
> Indexes:
> "tb1_id_pkey" PRIMARY KEY, btree (id)
> "dste_col_i_1" btree (col3)
> "dste_col_i_2" btree (col4)
> "dste_col_i_3" btree (col7)
> "dste_col_i_4" btree (col11)
> "dste_col_i_5" btree (col1)
> "dste_col_i_6" btree (col8)
>
>
> Use seq scan,the number of lines is 125680
>
> set enable_indexscan = off;
> select count(id) from dste_smt.dste_role_t;
> count
> --------
> 125680
> (1 row)
>
> But with index only scan, the number of rows is more than the real number.
>
> All indexes are, including primary keys.
>
> set enable_indexscan = on;
> dste_pg_db=# select count(id) from dste_smt.dste_role_t;
> count
> --------
> 125684
> (1 row)

Yes, that must be data corruption.

You'll have to identify and delete duplicate values, then rebuild the indexes.

That *might* be caused by a PostgreSQL bug, and it might well be a bug that
got fixed since 12.6. Hard to tell. You should have applied the latest
minor release (but that cannot fix the problem now).

Without a way to reproduce this in PostgreSQL 12.18, there is little we can do.

Yours,
Laurenz Albe

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-04-15 14:20:33 Re: BUG #18429: Inconsistent results on similar queries with join lateral
Previous Message PG Bug reporting form 2024-04-15 13:25:28 BUG #18437: The index scan result is more than the full scan result, and the primary key index has duplicate val