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:
27
src/backend/utils/cache/lsyscache.c
vendored
27
src/backend/utils/cache/lsyscache.c
vendored
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user