Skip to content

Commit 30a2101

Browse files
committed
roachtest: add schemachange/bulkingest variant for ADD COLUMN
This patch adds testing for ADD COLUMN backfills. This differs from the CREATE INDEX operation since ADD COLUMN populates an index in order, so it runs more quickly. Measuring this will help us observe improvements in CREATE INDEX. Release note: None
1 parent 90ae675 commit 30a2101

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

pkg/cmd/roachtest/tests/schemachange.go

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,32 @@ func makeIndexAddTpccTest(
328328
}
329329
}
330330

331+
// bulkIngestSchemaChangeOp represents the type of schema change operation to
332+
// perform during bulk ingestion testing.
333+
type bulkIngestSchemaChangeOp string
334+
335+
const (
336+
// createIndexOp runs CREATE INDEX, which adds keys in unsorted order.
337+
createIndexOp bulkIngestSchemaChangeOp = "create_index"
338+
// addColumnOp runs ADD COLUMN, which adds keys in sorted order.
339+
addColumnOp bulkIngestSchemaChangeOp = "add_column"
340+
)
341+
331342
func registerSchemaChangeBulkIngest(r registry.Registry) {
332343
// Allow a long running time to account for runs that use a
333344
// cockroach build with runtime assertions enabled.
334-
r.Add(makeSchemaChangeBulkIngestTest(r, 12, 4_000_000_000, 5*time.Hour))
345+
r.Add(makeSchemaChangeBulkIngestTest(r, 12, 4_000_000_000, 5*time.Hour, createIndexOp))
346+
r.Add(makeSchemaChangeBulkIngestTest(r, 12, 4_000_000_000, 5*time.Hour, addColumnOp))
335347
}
336348

337349
func makeSchemaChangeBulkIngestTest(
338-
r registry.Registry, numNodes, numRows int, length time.Duration,
350+
r registry.Registry,
351+
numNodes, numRows int,
352+
length time.Duration,
353+
operation bulkIngestSchemaChangeOp,
339354
) registry.TestSpec {
340355
return registry.TestSpec{
341-
Name: "schemachange/bulkingest",
356+
Name: fmt.Sprintf("schemachange/bulkingest/nodes=%d/rows=%d/%s", numNodes, numRows, operation),
342357
Owner: registry.OwnerSQLFoundations,
343358
Benchmark: true,
344359
Cluster: r.MakeClusterSpec(numNodes, spec.WorkloadNode(), spec.SSD(4)),
@@ -350,26 +365,18 @@ func makeSchemaChangeBulkIngestTest(
350365
// The histogram tracks the total elapsed time for the CREATE INDEX operation.
351366
totalElapsed := histogram.Elapsed
352367

353-
// Calculate the approximate data size for the index.
354-
// The index is on (payload, a) where payload is 40 bytes.
355-
// Approximate size per row for index: 40 bytes (payload) + 8 bytes (a) = 48 bytes
356-
rowsIndexed := int64(numRows)
357-
bytesPerRow := int64(48)
358-
mb := int64(1 << 20)
359-
dataSizeInMB := (rowsIndexed * bytesPerRow) / mb
360-
361-
// Calculate throughput in MB/s per node.
362-
indexDuration := int64(totalElapsed / 1000) // Convert to seconds.
363-
if indexDuration == 0 {
364-
indexDuration = 1 // Avoid division by zero.
368+
// Calculate throughput in rows/sec per node.
369+
schemaChangeDuration := int64(totalElapsed / 1000) // Convert to seconds.
370+
if schemaChangeDuration == 0 {
371+
schemaChangeDuration = 1 // Avoid division by zero.
365372
}
366-
avgRatePerNode := roachtestutil.MetricPoint(float64(dataSizeInMB) / float64(int64(numNodes)*indexDuration))
373+
avgRatePerNode := roachtestutil.MetricPoint(float64(numRows) / float64(int64(numNodes)*schemaChangeDuration))
367374

368375
return roachtestutil.AggregatedPerfMetrics{
369376
{
370377
Name: fmt.Sprintf("%s_throughput", test),
371378
Value: avgRatePerNode,
372-
Unit: "MB/s/node",
379+
Unit: "rows/s/node",
373380
IsHigherBetter: true,
374381
},
375382
}, nil
@@ -427,7 +434,7 @@ func makeSchemaChangeBulkIngestTest(
427434
defer db.Close()
428435

429436
if !c.IsLocal() {
430-
// Wait for the load generator to run for a few minutes before creating the index.
437+
// Wait for the load generator to run for a few minutes before performing the schema change.
431438
sleepInterval := time.Minute * 5
432439
maxSleep := length / 2
433440
if sleepInterval > maxSleep {
@@ -436,16 +443,28 @@ func makeSchemaChangeBulkIngestTest(
436443
time.Sleep(sleepInterval)
437444
}
438445

439-
t.L().Printf("Creating index")
440-
// Tick once before starting the index creation.
446+
// Tick once before starting the schema change.
441447
tickHistogram()
442448
before := timeutil.Now()
443-
if _, err := db.Exec(`CREATE INDEX payload_a ON bulkingest.bulkingest (payload, a)`); err != nil {
449+
450+
var stmt string
451+
switch operation {
452+
case createIndexOp:
453+
t.L().Printf("Creating index")
454+
stmt = `CREATE INDEX payload_a ON bulkingest.bulkingest (payload, a)`
455+
case addColumnOp:
456+
t.L().Printf("Adding column")
457+
stmt = `ALTER TABLE bulkingest.bulkingest ADD COLUMN new_column INT NOT NULL DEFAULT 42`
458+
default:
459+
t.Fatalf("Unknown operation: %s", operation)
460+
}
461+
462+
if _, err := db.Exec(stmt); err != nil {
444463
t.Fatal(err)
445464
}
446-
// Tick once after the index creation to capture the total elapsed time.
465+
// Tick once after the schema change to capture the total elapsed time.
447466
tickHistogram()
448-
t.L().Printf("CREATE INDEX took %v\n", timeutil.Since(before))
467+
t.L().Printf("%s took %v\n", stmt, timeutil.Since(before))
449468
return nil
450469
})
451470

0 commit comments

Comments
 (0)