Skip to content

Commit 4f8b677

Browse files
committed
sql: bring back resultRowBuffer in updateRun and deleteRun
For some reason, updateRun and deleteRun differ from insertRun in that they were creating result slices for RETURNING in processSourceRow, instead of creating a resultRowBuffer in startExec. This commit does a small refactor to move allocation of resultRowBuffer to startExec. This refactor will make it easier for the new UPDATE and DELETE fast path planNodes to share updateRun and deleteRun with the existing updateNode and deleteNode. Epic: None Release note: None
1 parent 9fef4b2 commit 4f8b677

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

pkg/sql/delete.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type deleteRun struct {
4141
// to BatchedNext() has completed the work already.
4242
done bool
4343

44+
// resultRowBuffer is used to prepare a result row for accumulation
45+
// into the row container above, when rowsNeeded is set.
46+
resultRowBuffer tree.Datums
47+
4448
// traceKV caches the current KV tracing flag.
4549
traceKV bool
4650

@@ -67,6 +71,10 @@ func (d *deleteNode) startExec(params runParams) error {
6771
d.run.td.rows = rowcontainer.NewRowContainer(
6872
params.p.Mon().MakeBoundAccount(),
6973
colinfo.ColTypeInfoFromResCols(d.columns))
74+
d.run.resultRowBuffer = make([]tree.Datum, len(d.columns))
75+
for i := range d.run.resultRowBuffer {
76+
d.run.resultRowBuffer[i] = tree.DNull
77+
}
7078
}
7179
return d.run.td.init(params.ctx, params.p.txn, params.EvalContext())
7280
}
@@ -185,15 +193,14 @@ func (d *deleteNode) processSourceRow(params runParams, sourceVals tree.Datums)
185193
//
186194
// d.run.rows.NumCols() is guaranteed to only contain the requested
187195
// public columns.
188-
resultValues := make(tree.Datums, d.run.td.rows.NumCols())
189196
largestRetIdx := -1
190197
for i := range d.run.rowIdxToRetIdx {
191198
retIdx := d.run.rowIdxToRetIdx[i]
192199
if retIdx >= 0 {
193200
if retIdx >= largestRetIdx {
194201
largestRetIdx = retIdx
195202
}
196-
resultValues[retIdx] = deleteVals[i]
203+
d.run.resultRowBuffer[retIdx] = deleteVals[i]
197204
}
198205
}
199206

@@ -207,12 +214,12 @@ func (d *deleteNode) processSourceRow(params runParams, sourceVals tree.Datums)
207214

208215
for i := 0; i < d.run.numPassthrough; i++ {
209216
largestRetIdx++
210-
resultValues[largestRetIdx] = passthroughValues[i]
217+
d.run.resultRowBuffer[largestRetIdx] = passthroughValues[i]
211218
}
212219

213220
}
214221

215-
if _, err := d.run.td.rows.AddRow(params.ctx, resultValues); err != nil {
222+
if _, err := d.run.td.rows.AddRow(params.ctx, d.run.resultRowBuffer); err != nil {
216223
return err
217224
}
218225
}

pkg/sql/update.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ type updateRun struct {
4848
// BatchedNext() has completed the work already.
4949
done bool
5050

51+
// resultRowBuffer is used to prepare a result row for accumulation
52+
// into the row container above, when rowsNeeded is set.
53+
resultRowBuffer tree.Datums
54+
5155
// traceKV caches the current KV tracing flag.
5256
traceKV bool
5357

@@ -77,6 +81,10 @@ func (u *updateNode) startExec(params runParams) error {
7781
params.p.Mon().MakeBoundAccount(),
7882
colinfo.ColTypeInfoFromResCols(u.columns),
7983
)
84+
u.run.resultRowBuffer = make([]tree.Datum, len(u.columns))
85+
for i := range u.run.resultRowBuffer {
86+
u.run.resultRowBuffer[i] = tree.DNull
87+
}
8088
}
8189
return u.run.tu.init(params.ctx, params.p.txn, params.EvalContext())
8290
}
@@ -240,15 +248,14 @@ func (u *updateNode) processSourceRow(params runParams, sourceVals tree.Datums)
240248
//
241249
// MakeUpdater guarantees that the first columns of the new values
242250
// are those specified u.columns.
243-
resultValues := make([]tree.Datum, len(u.columns))
244251
largestRetIdx := -1
245252
for i := range u.run.rowIdxToRetIdx {
246253
retIdx := u.run.rowIdxToRetIdx[i]
247254
if retIdx >= 0 {
248255
if retIdx >= largestRetIdx {
249256
largestRetIdx = retIdx
250257
}
251-
resultValues[retIdx] = newValues[i]
258+
u.run.resultRowBuffer[retIdx] = newValues[i]
252259
}
253260
}
254261

@@ -257,10 +264,10 @@ func (u *updateNode) processSourceRow(params runParams, sourceVals tree.Datums)
257264
// clause that refer to other tables (from the FROM clause of the update).
258265
for i := 0; i < u.run.numPassthrough; i++ {
259266
largestRetIdx++
260-
resultValues[largestRetIdx] = passthroughValues[i]
267+
u.run.resultRowBuffer[largestRetIdx] = passthroughValues[i]
261268
}
262269

263-
if _, err := u.run.tu.rows.AddRow(params.ctx, resultValues); err != nil {
270+
if _, err := u.run.tu.rows.AddRow(params.ctx, u.run.resultRowBuffer); err != nil {
264271
return err
265272
}
266273
}

0 commit comments

Comments
 (0)