Preserve attstattarget on REINDEX CONCURRENTLY - Mailing list pgsql-hackers

From Ronan Dunklau
Subject Preserve attstattarget on REINDEX CONCURRENTLY
Date
Msg-id 16628084.uLZWGnKmhe@laptop-ronand
Whole thread Raw
Responses Re: Preserve attstattarget on REINDEX CONCURRENTLY
List 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

pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: logical replication worker accesses catalogs in error context callback
Next
From: Ibrar Ahmed
Date:
Subject: Re: Next Commitfest Manager.