From 41a794bc15cc95e097b0243aebab77260dc6ff84 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Mon, 11 Jul 2022 08:44:18 -0400 Subject: [PATCH] opt: clarify logic in Metadata.UpdateTableMeta Release note: None --- pkg/sql/opt/metadata.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/sql/opt/metadata.go b/pkg/sql/opt/metadata.go index e7670e54623f..060aa495d9e8 100644 --- a/pkg/sql/opt/metadata.go +++ b/pkg/sql/opt/metadata.go @@ -610,14 +610,15 @@ func (md *Metadata) QualifiedAlias(colID ColumnID, fullyQualify bool, catalog ca // TableMeta instance stores. func (md *Metadata) UpdateTableMeta(tables map[cat.StableID]cat.Table) { for i := range md.tables { - if tab, ok := tables[md.tables[i].Table.ID()]; ok { + oldTable := md.tables[i].Table + if newTable, ok := tables[oldTable.ID()]; ok { // If there are any inverted hypothetical indexes, the hypothetical table // will have extra inverted columns added. Add any new inverted columns to // the metadata. - for j, n := md.tables[i].Table.ColumnCount(), tab.ColumnCount(); j < n; j++ { - md.AddColumn(string(tab.Column(j).ColName()), types.Bytes) + for j, n := oldTable.ColumnCount(), newTable.ColumnCount(); j < n; j++ { + md.AddColumn(string(newTable.Column(j).ColName()), types.Bytes) } - md.tables[i].Table = tab + md.tables[i].Table = newTable } } }