Skip to content

Commit

Permalink
Merge pull request #6141 from petermattis/pmattis/result-row-alloc-chunk
Browse files Browse the repository at this point in the history
sql: allocate backing storage for ResultRow.Values slices in chunks
petermattis committed Apr 19, 2016
2 parents 250d0af + 5e31554 commit 280659d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sql/executor.go
Original file line number Diff line number Diff line change
@@ -900,10 +900,26 @@ func (e *Executor) execStmt(
}
}

// valuesAlloc is used to allocate the backing storage for the
// ResultRow.Values slices in chunks.
var valuesAlloc []parser.Datum
const maxChunkSize = 64 // Arbitrary, could use tuning.
chunkSize := 4 // Arbitrary as well.

for plan.Next() {
// The plan.Values DTuple needs to be copied on each iteration.
values := plan.Values()
row := ResultRow{Values: make([]parser.Datum, 0, len(values))}

n := len(values)
if len(valuesAlloc) < n {
valuesAlloc = make([]parser.Datum, len(result.Columns)*chunkSize)
if chunkSize < maxChunkSize {
chunkSize *= 2
}
}
row := ResultRow{Values: valuesAlloc[:0:n]}
valuesAlloc = valuesAlloc[n:]

for _, val := range values {
if err := checkResultDatum(val); err != nil {
return result, roachpb.NewError(err)

0 comments on commit 280659d

Please sign in to comment.