From f5024d8d7b04de2f5f4742ab433cc38160354861 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 23 May 2021 12:12:09 -0400 Subject: 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 --- src/backend/commands/tablecmds.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 85dcc330638..11e91c4ad33 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2640,8 +2640,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence, def->constraints = NIL; def->location = -1; if (CompressionMethodIsValid(attribute->attcompression)) - def->compression = pstrdup(GetCompressionMethodName( - attribute->attcompression)); + def->compression = + pstrdup(GetCompressionMethodName(attribute->attcompression)); else def->compression = NULL; inhSchema = lappend(inhSchema, def); @@ -6596,12 +6596,19 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, attribute.atttypid = typeOid; attribute.attstattarget = (newattnum > 0) ? -1 : 0; attribute.attlen = tform->typlen; - attribute.atttypmod = typmod; attribute.attnum = newattnum; - attribute.attbyval = tform->typbyval; attribute.attndims = list_length(colDef->typeName->arrayBounds); - attribute.attstorage = tform->typstorage; + attribute.atttypmod = typmod; + attribute.attbyval = tform->typbyval; attribute.attalign = tform->typalign; + attribute.attstorage = tform->typstorage; + /* do not set compression in views etc */ + if (rel->rd_rel->relkind == RELKIND_RELATION || + rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + attribute.attcompression = GetAttributeCompression(&attribute, + colDef->compression); + else + attribute.attcompression = InvalidCompressionMethod; attribute.attnotnull = colDef->is_not_null; attribute.atthasdef = false; attribute.atthasmissing = false; @@ -6612,17 +6619,6 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, attribute.attinhcount = colDef->inhcount; attribute.attcollation = collOid; - /* - * lookup attribute's compression method and store it in the - * attr->attcompression. - */ - if (rel->rd_rel->relkind == RELKIND_RELATION || - rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) - attribute.attcompression = GetAttributeCompression(&attribute, - colDef->compression); - else - attribute.attcompression = InvalidCompressionMethod; - /* attribute.attacl is handled by InsertPgAttributeTuples() */ ReleaseSysCache(typeTuple); -- cgit v1.2.3