Skip to content

Commit 4df8533

Browse files
committed
sql: combine index slice allocations for updates and upserts
Release note: None
1 parent cba955d commit 4df8533

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

pkg/sql/opt_exec_factory.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,25 @@ func ordinalsToIndexes(table cat.Table, ords cat.IndexOrdinals) []catalog.Index
14011401
return retval
14021402
}
14031403

1404+
func ordinalsToIndexes2(
1405+
table cat.Table, a, b cat.IndexOrdinals,
1406+
) ([]catalog.Index, []catalog.Index) {
1407+
lenA, lenB := len(a), len(b)
1408+
if lenA+lenB == 0 {
1409+
return nil, nil
1410+
}
1411+
1412+
indexes := make([]catalog.Index, lenA+lenB)
1413+
indexesA, indexesB := indexes[:lenA:lenA], indexes[lenA:]
1414+
for i, idx := range a {
1415+
indexesA[i] = table.Index(idx).(*optIndex).idx
1416+
}
1417+
for i, idx := range b {
1418+
indexesB[i] = table.Index(idx).(*optIndex).idx
1419+
}
1420+
return indexesA, indexesB
1421+
}
1422+
14041423
func (ef *execFactory) ConstructInsert(
14051424
input exec.Node,
14061425
table cat.Table,
@@ -1724,11 +1743,12 @@ func (ef *execFactory) constructUpdateRun(
17241743
fetchCols, updateCols := makeColList2(table, fetchColOrdSet, updateColOrdSet)
17251744

17261745
// Create the table updater.
1746+
tombstoneIdxs, lockIdxs := ordinalsToIndexes2(table, uniqueWithTombstoneIndexes, lockedIndexes)
17271747
ru, err := row.MakeUpdater(
17281748
ef.planner.ExecCfg().Codec,
17291749
tabDesc,
1730-
ordinalsToIndexes(table, uniqueWithTombstoneIndexes),
1731-
ordinalsToIndexes(table, lockedIndexes),
1750+
tombstoneIdxs,
1751+
lockIdxs,
17321752
updateCols,
17331753
fetchCols,
17341754
row.UpdaterDefault,
@@ -1799,11 +1819,12 @@ func (ef *execFactory) ConstructUpsert(
17991819
}
18001820

18011821
// Create the table updater, which does the bulk of the update-related work.
1822+
tombstoneIdxs, lockIdxs := ordinalsToIndexes2(table, uniqueWithTombstoneIndexes, lockedIndexes)
18021823
ru, err := row.MakeUpdater(
18031824
ef.planner.ExecCfg().Codec,
18041825
tabDesc,
1805-
ordinalsToIndexes(table, uniqueWithTombstoneIndexes),
1806-
ordinalsToIndexes(table, lockedIndexes),
1826+
tombstoneIdxs,
1827+
lockIdxs,
18071828
updateCols,
18081829
fetchCols,
18091830
row.UpdaterDefault,

0 commit comments

Comments
 (0)