Skip to content

Commit 00bb6d4

Browse files
author
James Cor
committed
project too
1 parent 4dd25ce commit 00bb6d4

File tree

8 files changed

+38
-22
lines changed

8 files changed

+38
-22
lines changed

sql/expression/function/aggregation/group_concat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (g *groupConcatBuffer) Update(ctx *sql.Context, originalRow sql.Row) error
308308

309309
// Append the current value to the end of the row. We want to preserve the row's original structure
310310
// for sort ordering in the final step.
311-
g.rows = append(g.rows, append(originalRow, vs))
311+
g.rows = append(g.rows, append(originalRow.Copy(), vs))
312312

313313
return nil
314314
}

sql/rowexec/ddl_iters.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ func (i *loggingKeyValueIter) Close(ctx *sql.Context) error {
918918
// projectRowWithTypes projects the row given with the projections given and additionally converts them to the
919919
// corresponding types found in the schema given, using the standard type conversion logic.
920920
func projectRowWithTypes(ctx *sql.Context, oldSchema, newSchema sql.Schema, projections []sql.Expression, r sql.Row) (sql.Row, error) {
921-
newRow, err := ProjectRow(ctx, projections, r)
921+
newRow, err := ProjectRow(ctx, projections, r, nil)
922922
if err != nil {
923923
return nil, err
924924
}
@@ -1440,7 +1440,7 @@ func (i *addColumnIter) rewriteTable(ctx *sql.Context, rwt sql.RewritableTable)
14401440
return false, err
14411441
}
14421442

1443-
newRow, err := ProjectRow(ctx, projections, r)
1443+
newRow, err := ProjectRow(ctx, projections, r, nil)
14441444
if err != nil {
14451445
_ = inserter.DiscardChanges(ctx, err)
14461446
_ = inserter.Close(ctx)
@@ -1736,7 +1736,7 @@ func (i *dropColumnIter) rewriteTable(ctx *sql.Context, rwt sql.RewritableTable)
17361736
return false, err
17371737
}
17381738

1739-
newRow, err := ProjectRow(ctx, projections, r)
1739+
newRow, err := ProjectRow(ctx, projections, r, nil)
17401740
if err != nil {
17411741
_ = inserter.DiscardChanges(ctx, err)
17421742
_ = inserter.Close(ctx)
@@ -2240,7 +2240,7 @@ func buildIndex(ctx *sql.Context, n *plan.AlterIndex, ibt sql.IndexBuildingTable
22402240
}
22412241

22422242
if isVirtual {
2243-
r, err = ProjectRow(ctx, projections, r)
2243+
r, err = ProjectRow(ctx, projections, r, nil)
22442244
if err != nil {
22452245
return err
22462246
}
@@ -2326,7 +2326,7 @@ func rewriteTableForIndexCreate(ctx *sql.Context, n *plan.AlterIndex, table sql.
23262326
}
23272327

23282328
if isVirtual {
2329-
r, err = ProjectRow(ctx, projections, r)
2329+
r, err = ProjectRow(ctx, projections, r, nil)
23302330
if err != nil {
23312331
return err
23322332
}

sql/rowexec/insert.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@ func getInsertExpressions(values sql.Node) []sql.Expression {
6767
}
6868

6969
func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error) {
70-
row, err := i.rowSource.Next(ctx)
70+
origRow, err := i.rowSource.Next(ctx)
7171
if err == io.EOF {
7272
return nil, err
7373
}
74-
7574
if err != nil {
76-
return nil, i.ignoreOrClose(ctx, row, err)
75+
return nil, i.ignoreOrClose(ctx, origRow, err)
7776
}
7877

78+
row := origRow.Copy()
79+
7980
// Increment row number for error reporting (MySQL starts at 1)
8081
i.rowNumber++
8182

@@ -107,9 +108,6 @@ func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error)
107108
return nil, i.ignoreOrClose(ctx, row, err)
108109
}
109110

110-
origRow := make(sql.Row, len(row))
111-
copy(origRow, row)
112-
113111
// Do any necessary type conversions to the target schema
114112
for idx, col := range i.schema {
115113
if row[idx] != nil {

sql/rowexec/join_iters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func (i *joinIter) buildRow(primary, secondary sql.Row) sql.Row {
214214
}
215215

216216
func (i *joinIter) Close(ctx *sql.Context) (err error) {
217-
i.rowBuffer.Reset()
218-
sql.RowBufPool.Put(i.rowBuffer)
217+
//i.rowBuffer.Reset()
218+
//sql.RowBufPool.Put(i.rowBuffer)
219219

220220
if i.primary != nil {
221221
if err = i.primary.Close(ctx); err != nil {

sql/rowexec/merge_join.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (i *mergeJoinIter) Next(ctx *sql.Context) (sql.Row, error) {
320320
}
321321

322322
func (i *mergeJoinIter) copyReturnRow() sql.Row {
323-
ret := i.rowBuffer.Get(len(i.fullRow))
323+
ret := make(sql.Row, len(i.fullRow))
324324
copy(ret, i.fullRow)
325325
return ret
326326
}
@@ -580,6 +580,9 @@ func (i *mergeJoinIter) removeParentRow(r sql.Row) sql.Row {
580580
}
581581

582582
func (i *mergeJoinIter) Close(ctx *sql.Context) (err error) {
583+
i.rowBuffer.Reset()
584+
sql.RowBufPool.Put(i.rowBuffer)
585+
583586
if i.left != nil {
584587
err = i.left.Close(ctx)
585588
}

sql/rowexec/rel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (b *BaseBuilder) buildValues(ctx *sql.Context, n *plan.Values, row sql.Row)
9797
// For the values node, the relevant values to evaluate are the tuple itself. We may need to project
9898
// DEFAULT values onto them, which ProjectRow handles correctly (could require multiple passes)
9999
var err error
100-
vals, err = ProjectRow(ctx, et, vals)
100+
vals, err = ProjectRow(ctx, et, vals, nil)
101101
if err != nil {
102102
return nil, err
103103
}
@@ -315,6 +315,7 @@ func (b *BaseBuilder) buildProject(ctx *sql.Context, n *plan.Project, row sql.Ro
315315
canDefer: n.CanDefer,
316316
hasNestedIters: n.IncludesNestedIters,
317317
childIter: i,
318+
rowBuffer: sql.RowBufPool.Get().(*sql.RowBuffer),
318319
}), nil
319320
}
320321

@@ -326,6 +327,7 @@ func (b *BaseBuilder) buildVirtualColumnTable(ctx *sql.Context, n *plan.VirtualC
326327
return sql.NewSpanIter(span, &ProjectIter{
327328
projs: n.Projections,
328329
childIter: tableIter,
330+
rowBuffer: sql.RowBufPool.Get().(*sql.RowBuffer),
329331
}), nil
330332
}
331333

sql/rowexec/rel_iters.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ type ProjectIter struct {
132132
hasNestedIters bool
133133
nestedState *nestedIterState
134134
childIter sql.RowIter
135+
136+
rowBuffer *sql.RowBuffer
135137
}
136138

137139
type nestedIterState struct {
@@ -150,10 +152,12 @@ func (i *ProjectIter) Next(ctx *sql.Context) (sql.Row, error) {
150152
return nil, err
151153
}
152154

153-
return ProjectRow(ctx, i.projs, childRow)
155+
return ProjectRow(ctx, i.projs, childRow, i.rowBuffer)
154156
}
155157

156158
func (i *ProjectIter) Close(ctx *sql.Context) error {
159+
i.rowBuffer.Reset()
160+
sql.RowBufPool.Put(i.rowBuffer)
157161
return i.childIter.Close(ctx)
158162
}
159163

@@ -178,7 +182,7 @@ func (i *ProjectIter) ProjectRowWithNestedIters(
178182
// Other iterator values will be NULL after they are depleted. All non-iterator fields for the row are returned
179183
// identically for each row in the result set.
180184
if i.nestedState != nil {
181-
row, err := ProjectRow(ctx, i.nestedState.projections, i.nestedState.sourceRow)
185+
row, err := ProjectRow(ctx, i.nestedState.projections, i.nestedState.sourceRow, nil)
182186
if err != nil {
183187
return nil, err
184188
}
@@ -304,8 +308,14 @@ func ProjectRow(
304308
ctx *sql.Context,
305309
projections []sql.Expression,
306310
row sql.Row,
311+
rowBuffer *sql.RowBuffer,
307312
) (sql.Row, error) {
308-
var fields = make(sql.Row, len(projections))
313+
var fields sql.Row
314+
if rowBuffer != nil {
315+
fields = rowBuffer.Get(len(projections))
316+
} else {
317+
fields = make(sql.Row, len(projections))
318+
}
309319
var secondPass []int
310320
for i, expr := range projections {
311321
// Default values that are expressions may reference other fields, thus they must evaluate after all other exprs.

sql/rows.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ func rowFromRow2(sch Schema, r Row2) Row {
226226

227227
// RowsToRowIter creates a RowIter that iterates over the given rows.
228228
func RowsToRowIter(rows ...Row) RowIter {
229-
return &sliceRowIter{rows: rows}
229+
allRows := make([]Row, len(rows))
230+
for i, row := range rows {
231+
allRows[i] = row.Copy()
232+
}
233+
return &sliceRowIter{rows: allRows}
230234
}
231235

232236
type sliceRowIter struct {
@@ -238,10 +242,9 @@ func (i *sliceRowIter) Next(*Context) (Row, error) {
238242
if i.idx >= len(i.rows) {
239243
return nil, io.EOF
240244
}
241-
242245
r := i.rows[i.idx]
243246
i.idx++
244-
return r.Copy(), nil
247+
return r, nil
245248
}
246249

247250
func (i *sliceRowIter) Close(*Context) error {

0 commit comments

Comments
 (0)