diff --git a/pkg/sql/opt/cat/utils.go b/pkg/sql/opt/cat/utils.go index 83b31647c4bc..304246c6941b 100644 --- a/pkg/sql/opt/cat/utils.go +++ b/pkg/sql/opt/cat/utils.go @@ -121,17 +121,6 @@ func ResolveTableIndex( return found, foundTabName, nil } -// FindTableColumnByName returns the ordinal of the non-mutation column having -// the given name, if one exists in the given table. Otherwise, it returns -1. -func FindTableColumnByName(tab Table, name tree.Name) int { - for ord, n := 0, tab.AllColumnCount(); ord < n; ord++ { - if !IsMutationColumn(tab, ord) && tab.Column(ord).ColName() == name { - return ord - } - } - return -1 -} - // FormatTable nicely formats a catalog table using a treeprinter for debugging // and testing. func FormatTable(cat Catalog, tab Table, tp treeprinter.Node) { diff --git a/pkg/sql/opt/optbuilder/insert.go b/pkg/sql/opt/optbuilder/insert.go index 00d5daf6ab14..64d3dff51d49 100644 --- a/pkg/sql/opt/optbuilder/insert.go +++ b/pkg/sql/opt/optbuilder/insert.go @@ -904,7 +904,7 @@ func (mb *mutationBuilder) setUpsertCols(insertCols tree.NameList) { for _, name := range insertCols { // Table column must exist, since existence of insertCols has already // been checked previously. - ord := cat.FindTableColumnByName(mb.tab, name) + ord := findPublicTableColumnByName(mb.tab, name) mb.updateOrds[ord] = mb.insertOrds[ord] } } else { diff --git a/pkg/sql/opt/optbuilder/mutation_builder.go b/pkg/sql/opt/optbuilder/mutation_builder.go index cd5a4530c219..b1484bcfdc18 100644 --- a/pkg/sql/opt/optbuilder/mutation_builder.go +++ b/pkg/sql/opt/optbuilder/mutation_builder.go @@ -400,7 +400,7 @@ func (mb *mutationBuilder) addTargetColsByName(names tree.NameList) { for _, name := range names { // Determine the ordinal position of the named column in the table and // add it as a target column. - if ord := cat.FindTableColumnByName(mb.tab, name); ord != -1 { + if ord := findPublicTableColumnByName(mb.tab, name); ord != -1 { mb.addTargetCol(ord) continue } diff --git a/pkg/sql/opt/optbuilder/util.go b/pkg/sql/opt/optbuilder/util.go index 0933ef2438d0..152c428a737b 100644 --- a/pkg/sql/opt/optbuilder/util.go +++ b/pkg/sql/opt/optbuilder/util.go @@ -658,3 +658,15 @@ func resolveNumericColumnRefs(tab cat.Table, columns []tree.ColumnID) (ordinals } return ordinals } + +// findPublicTableColumnByName returns the ordinal of the non-mutation column +// having the given name, if one exists in the given table. Otherwise, it +// returns -1. +func findPublicTableColumnByName(tab cat.Table, name tree.Name) int { + for ord, n := 0, tab.AllColumnCount(); ord < n; ord++ { + if tab.Column(ord).ColName() == name && !cat.IsMutationColumn(tab, ord) { + return ord + } + } + return -1 +}