Skip to content

Commit

Permalink
opt, sql: reshape the result row in an UPSERT mutation
Browse files Browse the repository at this point in the history
This change reshapes the result row in an upsert to have NULL values
when values for the column weren't specified.

Release note: None
  • Loading branch information
Ridwan Sharif committed Jul 9, 2019
1 parent 5ad6a4a commit ff6ce77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions pkg/sql/rowcontainer/datum_row_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ func (c *RowContainer) allocChunks(ctx context.Context, numChunks int) error {
func (c *RowContainer) rowSize(row tree.Datums) int64 {
rsz := c.fixedColsSize
for _, i := range c.varSizedColumns {
if i < len(row) && row[i] != nil {
rsz += int64(row[i].Size())
}
rsz += int64(row[i].Size())
}
return rsz
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/tablewriter_upsert_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,18 @@ func (tu *optTableUpserter) updateConflictingRow(
return nil
}

// We now need a row that has the shape of the result row.
// We now need a row that has the shape of the result row with
// the appropriate return columns. Make sure all the fetch columns
// are present.
tu.resultRow = tu.makeResultFromRow(fetchRow, tu.ru.FetchColIDtoRowIndex)

// Make sure all the updated columns are present.
for colID, returnIndex := range tu.colIDToReturnIndex {
// If an update value for a given column exists, use that; else use the
// existing value of that column if it has been fetched.
rowIndex, ok := tu.ru.UpdateColIDtoRowIndex[colID]
if ok {
tu.resultRow[returnIndex] = updateValues[rowIndex]
} else {
rowIndex, ok = tu.ru.FetchColIDtoRowIndex[colID]
if ok {
tu.resultRow[returnIndex] = fetchRow[rowIndex]
}
}
}

Expand Down

0 comments on commit ff6ce77

Please sign in to comment.