diff options
author | Peter Eisentraut | 2024-01-13 17:14:53 +0000 |
---|---|---|
committer | Peter Eisentraut | 2024-01-13 17:14:53 +0000 |
commit | 4f622503d6de975ac87448aea5cea7de4bc140d5 (patch) | |
tree | c09756e667e5150678e8ebf9aee6c1cd5e376a96 /src/backend/catalog/index.c | |
parent | 45da69371ebfc4d6982695e58791989660c1cc33 (diff) |
Make attstattarget nullable
This changes the pg_attribute field attstattarget into a nullable
field in the variable-length part of the row. If no value is set by
the user for attstattarget, it is now null instead of previously -1.
This saves space in pg_attribute and tuple descriptors for most
practical scenarios. (ATTRIBUTE_FIXED_PART_SIZE is reduced from 108
to 104.) Also, null is the semantically more correct value.
The ANALYZE code internally continues to represent the default
statistics target by -1, so that that code can avoid having to deal
with null values. But that is now contained to the ANALYZE code.
Only the DDL code deals with attstattarget possibly null.
For system columns, the field is now always null. The ANALYZE code
skips system columns anyway.
To set a column's statistics target to the default value, the new
command form ALTER TABLE ... SET STATISTICS DEFAULT can be used. (SET
STATISTICS -1 still works.)
Reviewed-by: Alvaro Herrera <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/catalog/index.c')
-rw-r--r-- | src/backend/catalog/index.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 88f7994b5a6..fbef3d5382d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -325,7 +325,6 @@ ConstructTupleDescriptor(Relation heapRelation, MemSet(to, 0, ATTRIBUTE_FIXED_PART_SIZE); to->attnum = i + 1; - to->attstattarget = -1; to->attcacheoff = -1; to->attislocal = true; to->attcollation = (i < numkeyatts) ? collationIds[i] : InvalidOid; @@ -1780,10 +1779,12 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName) while (HeapTupleIsValid((attrTuple = systable_getnext(scan)))) { Form_pg_attribute att = (Form_pg_attribute) GETSTRUCT(attrTuple); + HeapTuple tp; + Datum dat; + bool isnull; Datum repl_val[Natts_pg_attribute]; bool repl_null[Natts_pg_attribute]; bool repl_repl[Natts_pg_attribute]; - int attstattarget; HeapTuple newTuple; /* Ignore dropped columns */ @@ -1793,10 +1794,18 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName) /* * Get attstattarget from the old index and refresh the new value. */ - attstattarget = get_attstattarget(oldIndexId, att->attnum); + tp = SearchSysCache2(ATTNUM, ObjectIdGetDatum(oldIndexId), Int16GetDatum(att->attnum)); + if (!HeapTupleIsValid(tp)) + elog(ERROR, "cache lookup failed for attribute %d of relation %u", + att->attnum, oldIndexId); + dat = SysCacheGetAttr(ATTNUM, tp, Anum_pg_attribute_attstattarget, &isnull); + ReleaseSysCache(tp); - /* no need for a refresh if both match */ - if (attstattarget == att->attstattarget) + /* + * No need for a refresh if old index value is null. (All new + * index values are null at this point.) + */ + if (isnull) continue; memset(repl_val, 0, sizeof(repl_val)); @@ -1804,7 +1813,7 @@ index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName) memset(repl_repl, false, sizeof(repl_repl)); repl_repl[Anum_pg_attribute_attstattarget - 1] = true; - repl_val[Anum_pg_attribute_attstattarget - 1] = Int16GetDatum(attstattarget); + repl_val[Anum_pg_attribute_attstattarget - 1] = dat; newTuple = heap_modify_tuple(attrTuple, RelationGetDescr(pg_attribute), |