Skip to content

Commit ca7cf8d

Browse files
committed
sql: update MaxBatchSize comments
The comments for MaxBatchSize incorrectly state that it limits the number of KV batch entries. It actually limits the number of SQL-level batch rows. It includes only primary index rows, not secondary index rows. This commit updates all the comments to reflect what the code is actually doing. Epic: none Release note: None
1 parent 24bd59b commit ca7cf8d

File tree

9 files changed

+21
-19
lines changed

9 files changed

+21
-19
lines changed

pkg/sql/create_table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ func (n *createTableNode) startExec(params runParams) error {
596596
break
597597
}
598598

599-
// Periodically flush out the batches, so that we don't issue gigantic
600-
// raft commands.
599+
// Periodically flush out the SQL-level batches, so that we don't
600+
// issue gigantic raft commands.
601601
if ti.currentBatchSize >= ti.maxBatchSize ||
602602
ti.b.ApproximateMutationBytes() >= ti.maxBatchByteSize {
603603
if err := ti.flushAndStartNewBatch(params.ctx); err != nil {

pkg/sql/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (d *deleteNode) processBatch(params runParams) (lastBatch bool, err error)
138138
return false, err
139139
}
140140

141-
// Are we done yet with the current batch?
141+
// Are we done yet with the current SQL-level batch?
142142
if d.run.td.currentBatchSize >= d.run.td.maxBatchSize ||
143143
d.run.td.b.ApproximateMutationBytes() >= d.run.td.maxBatchByteSize {
144144
break

pkg/sql/insert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (n *insertNode) processBatch(params runParams) (lastBatch bool, err error)
335335
return false, err
336336
}
337337

338-
// Are we done yet with the current batch?
338+
// Are we done yet with the current SQL-level batch?
339339
if n.run.ti.currentBatchSize >= n.run.ti.maxBatchSize ||
340340
n.run.ti.b.ApproximateMutationBytes() >= n.run.ti.maxBatchByteSize {
341341
break

pkg/sql/mutations/mutations_util.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ var testingMaxBatchByteSize = metamorphic.ConstantWithTestRange(
2929
32<<20, /* max */
3030
)
3131

32-
// MaxBatchSize returns the max number of entries in the KV batch for a
33-
// mutation operation (delete, insert, update, upsert) - including secondary
34-
// index updates, FK cascading updates, etc - before the current KV batch is
35-
// executed and a new batch is started.
32+
// MaxBatchSize returns the max number of rows in the SQL-level batch for a
33+
// mutation operation (delete, insert, update, upsert). This only includes
34+
// modified rows from the primary index, not any secondary index rows.
3635
//
3736
// If forceProductionMaxBatchSize is true, then the "production" value will be
3837
// returned regardless of whether the build is metamorphic or not. This should

pkg/sql/opt/exec/execbuilder/mutation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (b *Builder) tryBuildFastPathInsert(
200200
insInput := ins.Input
201201
values, ok := insInput.(*memo.ValuesExpr)
202202
// Values expressions containing subqueries or UDFs, or having a size larger
203-
// than the max mutation batch size are disallowed.
203+
// than the max mutation SQL-level batch size are disallowed.
204204
if !ok || !memo.ValuesLegalForInsertFastPath(values) {
205205
return execPlan{}, colOrdMap{}, false, nil
206206
}

pkg/sql/opt/memo/insert_fastpath.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import (
1515
)
1616

1717
// ValuesLegalForInsertFastPath tests if `values` is a Values expression that
18-
// has no subqueries or UDFs and has less rows than the max number of entries in
19-
// a KV batch for a mutation operation.
18+
// has no subqueries or UDFs and has less rows than the max number of rows in
19+
// the SQL-level batch for a mutation operation.
2020
func ValuesLegalForInsertFastPath(values *ValuesExpr) bool {
2121
// - The input is Values with at most mutations.MaxBatchSize, and there are no
2222
// subqueries;
23-
// (note that mutations.MaxBatchSize() is a quantity of keys in the batch
24-
// that we send, not a number of rows. We use this as a guideline only,
25-
// and there is no guarantee that we won't produce a bigger batch.)
23+
// (note that mutations.MaxBatchSize() is a quantity of modified rows in
24+
// the SQL-level batch that we send, not the number of KV batch entries.
25+
// We use this as a guideline only, and there is no guarantee that we
26+
// won't produce a bigger batch.)
2627
if values.ChildCount() > mutations.MaxBatchSize(false /* forceProductionMaxBatchSize */) ||
2728
values.Relational().HasSubquery ||
2829
values.Relational().HasUDF {

pkg/sql/tablewriter.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ type tableWriterBase struct {
4949
// deadlockTimeout specifies the amount of time that the writer will wait
5050
// on a lock before checking if there is a race condition.
5151
deadlockTimeout time.Duration
52-
// maxBatchSize determines the maximum number of entries in the KV batch
53-
// for a mutation operation. By default, it will be set to 10k but can be
54-
// a different value in tests.
52+
// maxBatchSize determines the maximum number of rows in the SQL-level batch
53+
// for a mutation operation. By default, it will be set to 10k but can be a
54+
// different value in tests.
5555
maxBatchSize int
5656
// maxBatchByteSize determines the maximum number of key and value bytes in
5757
// the KV batch for a mutation operation.
58+
// NOTE: This is based on the bytes in the KV batch, while maxBatchSize is
59+
// based on the rows in the SQL-level batch.
5860
maxBatchByteSize int
5961
// currentBatchSize is the size of the current SQL-level batch (i.e. not the
6062
// KV-level batch). It is updated on every row() call and is reset once a new

pkg/sql/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (u *updateNode) processBatch(params runParams) (lastBatch bool, err error)
146146
return false, err
147147
}
148148

149-
// Are we done yet with the current batch?
149+
// Are we done yet with the current SQL-level batch?
150150
if u.run.tu.currentBatchSize >= u.run.tu.maxBatchSize ||
151151
u.run.tu.b.ApproximateMutationBytes() >= u.run.tu.maxBatchByteSize {
152152
break

pkg/sql/upsert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (n *upsertNode) processBatch(params runParams) (lastBatch bool, err error)
106106
return false, err
107107
}
108108

109-
// Are we done yet with the current batch?
109+
// Are we done yet with the current SQL-level batch?
110110
if n.run.tw.currentBatchSize >= n.run.tw.maxBatchSize ||
111111
n.run.tw.b.ApproximateMutationBytes() >= n.run.tw.maxBatchByteSize {
112112
break

0 commit comments

Comments
 (0)