Skip to content

Commit cba955d

Browse files
committed
sql: combine allocations of fetch and update col lists
Release note: None
1 parent 976d03a commit cba955d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pkg/sql/opt_exec_factory.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,8 @@ func (ef *execFactory) ConstructUpdate(
15961596
}
15971597

15981598
// If rows are not needed, no columns are returned.
1599+
// TODO(mgartner): Combine returnCols allocations with allocations for
1600+
// fetchCols and updateCols in constructUpdateRun.
15991601
var returnCols []catalog.Column
16001602
if rowsNeeded {
16011603
returnCols = makeColList(table, returnColOrdSet)
@@ -1719,8 +1721,7 @@ func (ef *execFactory) constructUpdateRun(
17191721
lockedIndexes cat.IndexOrdinals,
17201722
) error {
17211723
tabDesc := table.(*optTable).desc
1722-
fetchCols := makeColList(table, fetchColOrdSet)
1723-
updateCols := makeColList(table, updateColOrdSet)
1724+
fetchCols, updateCols := makeColList2(table, fetchColOrdSet, updateColOrdSet)
17241725

17251726
// Create the table updater.
17261727
ru, err := row.MakeUpdater(
@@ -2569,6 +2570,27 @@ func makeColList(table cat.Table, cols exec.TableColumnOrdinalSet) []catalog.Col
25692570
return ret
25702571
}
25712572

2573+
// makeColList2 is similar to makeColList, but it takes two sets of ordinals and
2574+
// allocates a single slice which is split into two.
2575+
func makeColList2(
2576+
table cat.Table, a, b exec.TableColumnOrdinalSet,
2577+
) ([]catalog.Column, []catalog.Column) {
2578+
tab := table.(optCatalogTableInterface)
2579+
lenA, lenB := a.Len(), b.Len()
2580+
cols := make([]catalog.Column, 0, lenA+lenB)
2581+
listA, listB := cols[:0:lenA], cols[lenA:lenA]
2582+
for i, n := 0, table.ColumnCount(); i < n; i++ {
2583+
col := tab.getCol(i)
2584+
if a.Contains(i) {
2585+
listA = append(listA, col)
2586+
}
2587+
if b.Contains(i) {
2588+
listB = append(listB, col)
2589+
}
2590+
}
2591+
return listA, listB
2592+
}
2593+
25722594
// makePublicToReturnColumnIndexMapping returns a map from the ordinals
25732595
// of the table's public columns to ordinals in the returnColDescs slice.
25742596
//

0 commit comments

Comments
 (0)