1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Preserve pg_attribute.attstattarget across REINDEX CONCURRENTLY

For an index, attstattarget can be updated using ALTER INDEX SET
STATISTICS.  This data was lost on the new index after REINDEX
CONCURRENTLY.

The update of this field is done when the old and new indexes are
swapped to make the fix back-patchable.  Another approach we could look
after in the long-term is to change index_create() to pass the wanted
values of attstattarget when creating the new relation, but, as this
would cause an ABI breakage this can be done only on HEAD.

Reported-by: Ronan Dunklau
Author: Michael Paquier
Reviewed-by: Ronan Dunklau, Tomas Vondra
Discussion: https://postgr.es/m/16628084.uLZWGnKmhe@laptop-ronand
Backpatch-through: 12
This commit is contained in:
Michael Paquier
2021-02-10 13:06:48 +09:00
parent cd142e032e
commit bd12080980
5 changed files with 107 additions and 0 deletions

View File

@ -871,6 +871,33 @@ get_attnum(Oid relid, const char *attname)
return InvalidAttrNumber;
}
/*
* get_attstattarget
*
* Given the relation id and the attribute number,
* return the "attstattarget" field from the attribute relation.
*
* Errors if not found.
*/
int
get_attstattarget(Oid relid, AttrNumber attnum)
{
HeapTuple tp;
Form_pg_attribute att_tup;
int result;
tp = SearchSysCache2(ATTNUM,
ObjectIdGetDatum(relid),
Int16GetDatum(attnum));
if (!HeapTupleIsValid(tp))
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
attnum, relid);
att_tup = (Form_pg_attribute) GETSTRUCT(tp);
result = att_tup->attstattarget;
ReleaseSysCache(tp);
return result;
}
/*
* get_attgenerated
*