@@ -328,17 +328,32 @@ func makeIndexAddTpccTest(
328
328
}
329
329
}
330
330
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
+
331
342
func registerSchemaChangeBulkIngest (r registry.Registry ) {
332
343
// Allow a long running time to account for runs that use a
333
344
// 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 ))
335
347
}
336
348
337
349
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 ,
339
354
) registry.TestSpec {
340
355
return registry.TestSpec {
341
- Name : "schemachange/bulkingest" ,
356
+ Name : fmt . Sprintf ( "schemachange/bulkingest/nodes=%d/rows=%d/%s" , numNodes , numRows , operation ) ,
342
357
Owner : registry .OwnerSQLFoundations ,
343
358
Benchmark : true ,
344
359
Cluster : r .MakeClusterSpec (numNodes , spec .WorkloadNode (), spec .SSD (4 )),
@@ -350,26 +365,18 @@ func makeSchemaChangeBulkIngestTest(
350
365
// The histogram tracks the total elapsed time for the CREATE INDEX operation.
351
366
totalElapsed := histogram .Elapsed
352
367
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.
365
372
}
366
- avgRatePerNode := roachtestutil .MetricPoint (float64 (dataSizeInMB ) / float64 (int64 (numNodes )* indexDuration ))
373
+ avgRatePerNode := roachtestutil .MetricPoint (float64 (numRows ) / float64 (int64 (numNodes )* schemaChangeDuration ))
367
374
368
375
return roachtestutil.AggregatedPerfMetrics {
369
376
{
370
377
Name : fmt .Sprintf ("%s_throughput" , test ),
371
378
Value : avgRatePerNode ,
372
- Unit : "MB /s/node" ,
379
+ Unit : "rows /s/node" ,
373
380
IsHigherBetter : true ,
374
381
},
375
382
}, nil
@@ -427,7 +434,7 @@ func makeSchemaChangeBulkIngestTest(
427
434
defer db .Close ()
428
435
429
436
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 .
431
438
sleepInterval := time .Minute * 5
432
439
maxSleep := length / 2
433
440
if sleepInterval > maxSleep {
@@ -436,16 +443,28 @@ func makeSchemaChangeBulkIngestTest(
436
443
time .Sleep (sleepInterval )
437
444
}
438
445
439
- t .L ().Printf ("Creating index" )
440
- // Tick once before starting the index creation.
446
+ // Tick once before starting the schema change.
441
447
tickHistogram ()
442
448
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 {
444
463
t .Fatal (err )
445
464
}
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.
447
466
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 ))
449
468
return nil
450
469
})
451
470
0 commit comments