Preserve attstattarget on REINDEX CONCURRENTLY
Ronan Dunklau <ronan@dunklau.fr>
From: Ronan Dunklau <ronan@dunklau.fr>
To: pgsql-hackers@postgresql.org
Date: 2021-02-04T10:04:38Z
Lists: pgsql-hackers
Attachments
- keep_attstattargets_on_reindex_concurrently.patch (text/x-patch)
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
Commits
-
Fix ORDER BY clause in new regression test of REINDEX CONCURRENTLY
- 5b2945ec0a39 12.7 landed
- c6cd20d91ce9 13.3 landed
- 4f4726005082 14.0 landed
-
Preserve pg_attribute.attstattarget across REINDEX CONCURRENTLY
- 85edb1f2615d 12.7 landed
- 849383138581 13.3 landed
- bd1208098029 14.0 landed