Skip to content

Commit

Permalink
opt: move FindTableColumnBYName to optbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
RaduBerinde committed Jul 14, 2020
1 parent 9ad21b1 commit a6ad229
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
11 changes: 0 additions & 11 deletions pkg/sql/opt/cat/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/optbuilder/mutation_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/opt/optbuilder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a6ad229

Please sign in to comment.