diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-23 12:12:09 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-23 12:12:09 -0400 |
commit | f5024d8d7b04de2f5f4742ab433cc38160354861 (patch) | |
tree | 7cbd6c5ebc78fb3a1b221b8d28193f6ddc5efb90 /src/backend/commands/tablecmds.c | |
parent | bc2a389efb3b52d259cefd53c16cfa00742116f2 (diff) |
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
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 28 |
1 files changed, 12 insertions, 16 deletions
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); |