Preserve attstattarget on REINDEX CONCURRENTLY

From: Ronan Dunklau <ronan(at)dunklau(dot)fr>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Preserve attstattarget on REINDEX CONCURRENTLY
Date: 2021-02-04 10:04:38
Message-ID: 16628084.uLZWGnKmhe@laptop-ronand
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello !

We encountered the following bug recently in production: when running REINDEX
CONCURRENTLY on an index, the attstattarget is reset to 0.

Consider the following example:

junk=# \d+ t1_date_trunc_idx
Index "public.t1_date_trunc_idx"
Column | Type | Key? | Definition
| Storage | Stats target
------------+-----------------------------+------
+-----------------------------+---------+--------------
date_trunc | timestamp without time zone | yes | date_trunc('day'::text, ts)
| plain | 1000
btree, for table "public.t1"

junk=# REINDEX INDEX t1_date_trunc_idx;
REINDEX
junk=# \d+ t1_date_trunc_idx
Index "public.t1_date_trunc_idx"
Column | Type | Key? | Definition
| Storage | Stats target
------------+-----------------------------+------
+-----------------------------+---------+--------------
date_trunc | timestamp without time zone | yes | date_trunc('day'::text, ts)
| plain | 1000
btree, for table "public.t1"

junk=# REINDEX INDEX CONCURRENTLY t1_date_trunc_idx;
REINDEX
junk=# \d+ t1_date_trunc_idx
Index "public.t1_date_trunc_idx"
Column | Type | Key? | Definition
| Storage | Stats target
------------+-----------------------------+------
+-----------------------------+---------+--------------
date_trunc | timestamp without time zone | yes | date_trunc('day'::text, ts)
| plain |
btree, for table "public.t1"

I'm attaching a patch possibly solving the problem, but maybe the proposed
changes will be too intrusive ?

Regards,

--
Ronan Dunklau

Attachment Content-Type Size
keep_attstattargets_on_reindex_concurrently.patch text/x-patch 9.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ibrar Ahmed 2021-02-04 10:07:22 Re: Next Commitfest Manager.
Previous Message Bharath Rupireddy 2021-02-04 09:38:42 Re: logical replication worker accesses catalogs in error context callback