mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Re-order pg_attribute columns to eliminate some padding space.
Now that attcompression is just a char, there's a lot of wasted padding space after it. Move it into the group of char-wide columns to save a net of 4 bytes per pg_attribute entry. While we're at it, swap the order of attstorage and attalign to make for a more logical grouping of these columns. Also re-order actions in related code to match the new field ordering. This patch also fixes one outright bug: equalTupleDescs() failed to compare attcompression. That could, for example, cause relcache reload to fail to adopt a new value following a change. Michael Paquier and Tom Lane, per a gripe from Andres Freund. Discussion: https://postgr.es/m/20210517204803.iyk5wwvwgtjcmc5w@alap3.anarazel.de
This commit is contained in:
@@ -424,7 +424,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
* general it seems safer to check them always.
|
||||
*
|
||||
* attcacheoff must NOT be checked since it's possibly not set in both
|
||||
* copies.
|
||||
* copies. We also intentionally ignore atthasmissing, since that's
|
||||
* not very relevant in tupdescs, which lack the attmissingval field.
|
||||
*/
|
||||
if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
|
||||
return false;
|
||||
@@ -440,9 +441,11 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
return false;
|
||||
if (attr1->attbyval != attr2->attbyval)
|
||||
return false;
|
||||
if (attr1->attalign != attr2->attalign)
|
||||
return false;
|
||||
if (attr1->attstorage != attr2->attstorage)
|
||||
return false;
|
||||
if (attr1->attalign != attr2->attalign)
|
||||
if (attr1->attcompression != attr2->attcompression)
|
||||
return false;
|
||||
if (attr1->attnotnull != attr2->attnotnull)
|
||||
return false;
|
||||
@@ -460,7 +463,7 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
return false;
|
||||
if (attr1->attcollation != attr2->attcollation)
|
||||
return false;
|
||||
/* attacl, attoptions and attfdwoptions are not even present... */
|
||||
/* variable-length fields are not even present... */
|
||||
}
|
||||
|
||||
if (tupdesc1->constr != NULL)
|
||||
@@ -639,12 +642,11 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
att->attbyval = typeForm->typbyval;
|
||||
att->attalign = typeForm->typalign;
|
||||
att->attstorage = typeForm->typstorage;
|
||||
att->attcollation = typeForm->typcollation;
|
||||
|
||||
if (IsStorageCompressible(typeForm->typstorage))
|
||||
att->attcompression = GetDefaultToastCompression();
|
||||
else
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = typeForm->typcollation;
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
}
|
||||
@@ -709,6 +711,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->attbyval = false;
|
||||
att->attalign = TYPALIGN_INT;
|
||||
att->attstorage = TYPSTORAGE_EXTENDED;
|
||||
att->attcompression = GetDefaultToastCompression();
|
||||
att->attcollation = DEFAULT_COLLATION_OID;
|
||||
break;
|
||||
|
||||
@@ -717,6 +720,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->attbyval = true;
|
||||
att->attalign = TYPALIGN_CHAR;
|
||||
att->attstorage = TYPSTORAGE_PLAIN;
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = InvalidOid;
|
||||
break;
|
||||
|
||||
@@ -725,6 +729,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->attbyval = true;
|
||||
att->attalign = TYPALIGN_INT;
|
||||
att->attstorage = TYPSTORAGE_PLAIN;
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = InvalidOid;
|
||||
break;
|
||||
|
||||
@@ -733,6 +738,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->attbyval = FLOAT8PASSBYVAL;
|
||||
att->attalign = TYPALIGN_DOUBLE;
|
||||
att->attstorage = TYPSTORAGE_PLAIN;
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = InvalidOid;
|
||||
break;
|
||||
|
||||
|
||||
@@ -165,8 +165,8 @@ fillTypeDesc(SpGistTypeDesc *desc, Oid type)
|
||||
typtup = (Form_pg_type) GETSTRUCT(tp);
|
||||
desc->attlen = typtup->typlen;
|
||||
desc->attbyval = typtup->typbyval;
|
||||
desc->attstorage = typtup->typstorage;
|
||||
desc->attalign = typtup->typalign;
|
||||
desc->attstorage = typtup->typstorage;
|
||||
ReleaseSysCache(tp);
|
||||
}
|
||||
|
||||
@@ -304,8 +304,8 @@ getSpGistTupleDesc(Relation index, SpGistTypeDesc *keyType)
|
||||
att->attalign = keyType->attalign;
|
||||
att->attstorage = keyType->attstorage;
|
||||
/* We shouldn't need to bother with making these valid: */
|
||||
att->attcollation = InvalidOid;
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = InvalidOid;
|
||||
/* In case we changed typlen, we'd better reset following offsets */
|
||||
for (int i = spgFirstIncludeColumn; i < outTupDesc->natts; i++)
|
||||
TupleDescAttr(outTupDesc, i)->attcacheoff = -1;
|
||||
|
||||
Reference in New Issue
Block a user