@@ -60,54 +60,57 @@ func initGeneric(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64
6060 return
6161 }
6262
63- var ddlConnDatabase * DBConnector
64- if ddlConnDatabase , err = NewDBConnector (& tenantCacheDBOpts , - 1 , true , b .Logger , 1 ); err != nil {
65- b .Exit ("db: cannot create connection for DDL: %v" , err )
66- return
67- }
63+ var rowNum int64
64+
65+ if ! testDesc .Table .DisableAutoCreation {
66+ var ddlConnDatabase * DBConnector
67+ if ddlConnDatabase , err = NewDBConnector (& b .TestOpts .(* TestOpts ).DBOpts , - 1 , true , b .Logger , 1 ); err != nil {
68+ b .Exit ("db: cannot create connection for DDL: %v" , err )
69+ return
70+ }
6871
69- conn := ddlConnDatabase
72+ conn := ddlConnDatabase
7073
71- t := testRegistry .GetTableByName (tableName )
74+ t := testRegistry .GetTableByName (tableName )
7275
73- b .Logger .Debug ("initializing table '%s'" , tableName )
74- if testDesc .IsReadonly {
75- t .Create (conn , b )
76- b .Logger .Debug ("readonly test, skipping table '%s' initialization" , tableName )
77- if exists , err := conn .Database .TableExists (tableName ); err != nil {
78- b .Exit (fmt .Sprintf ("db: cannot check if table '%s' exists: %v" , tableName , err ))
79- } else if ! exists {
80- b .Exit ("The '%s' table doesn't exist, please create tables using -I option, or use individual insert test using the -t `insert-***`" , tableName )
76+ b .Logger .Debug ("initializing table '%s'" , tableName )
77+ if testDesc .IsReadonly {
78+ t .Create (conn , b )
79+ b .Logger .Debug ("readonly test, skipping table '%s' initialization" , tableName )
80+ if exists , err := conn .Database .TableExists (tableName ); err != nil {
81+ b .Exit (fmt .Sprintf ("db: cannot check if table '%s' exists: %v" , tableName , err ))
82+ } else if ! exists {
83+ b .Exit ("The '%s' table doesn't exist, please create tables using -I option, or use individual insert test using the -t `insert-***`" , tableName )
84+ }
85+ } else {
86+ b .Logger .Debug ("creating table '%s'" , tableName )
87+ t .Create (conn , b )
8188 }
82- } else {
83- b .Logger .Debug ("creating table '%s'" , tableName )
84- t .Create (conn , b )
85- }
8689
87- var session = conn .Database .Session (conn .Database .Context (context .Background (), false ))
88- var rowNum int64
89- if rows , err := session . Select ( tableName , & db. SelectCtrl { Fields : [] string { "COUNT(0)" }}); err != nil {
90- b . Exit ( fmt . Sprintf ( "db: cannot get rows count in table '%s': %v" , tableName , err ))
91- } else {
92- for rows .Next () {
93- if scanErr := rows . Scan ( & rowNum ); scanErr != nil {
94- b . Exit ( fmt . Sprintf ( "db: cannot get rows count in table '%s': %v" , tableName , scanErr ))
90+ var session = conn .Database .Session (conn .Database .Context (context .Background (), false ))
91+ if rows , err := session . Select ( tableName , & db. SelectCtrl { Fields : [] string { "COUNT(0)" }}); err != nil {
92+ b . Exit ( fmt . Sprintf ( "db: cannot get rows count in table '%s': %v" , tableName , err ))
93+ } else {
94+ for rows . Next () {
95+ if scanErr := rows .Scan ( & rowNum ); scanErr != nil {
96+ b . Exit ( fmt . Sprintf ( "db: cannot get rows count in table '%s': %v" , tableName , scanErr ))
97+ }
9598 }
99+ rows .Close ()
96100 }
97- rows .Close ()
98- }
99101
100- testDesc .Table .RowsCount = uint64 (rowNum )
101- b .Logger .Debug ("table '%s' has %d rows" , tableName , testDesc .Table .RowsCount )
102+ testDesc .Table .RowsCount = uint64 (rowNum )
103+ b .Logger .Debug ("table '%s' has %d rows" , tableName , testDesc .Table .RowsCount )
102104
103- if rowsRequired > 0 {
104- if testDesc .Table .RowsCount < rowsRequired {
105- b .Exit (fmt .Sprintf ("table '%s' has %d rows, but this test requires at least %d rows, please insert it first and then re-run the test" ,
106- testDesc .Table .TableName , testDesc .Table .RowsCount , rowsRequired ))
105+ if rowsRequired > 0 {
106+ if testDesc .Table .RowsCount < rowsRequired {
107+ b .Exit (fmt .Sprintf ("table '%s' has %d rows, but this test requires at least %d rows, please insert it first and then re-run the test" ,
108+ testDesc .Table .TableName , testDesc .Table .RowsCount , rowsRequired ))
109+ }
107110 }
108- }
109111
110- ddlConnDatabase .Release ()
112+ ddlConnDatabase .Release ()
113+ }
111114
112115 if b .TestOpts .(* TestOpts ).BenchOpts .ParquetDataSource != "" {
113116 var offset int64
@@ -144,7 +147,7 @@ func initWorker(worker *benchmark.BenchmarkWorker) {
144147 worker .Logger .Trace ("worker is initialized" )
145148}
146149
147- func initCommon (b * benchmark.Benchmark , testDesc * TestDesc , rowsRequired uint64 ) {
150+ func InitCommon (b * benchmark.Benchmark , testDesc * TestDesc , rowsRequired uint64 ) {
148151 b .Init = func () {
149152 initGeneric (b , testDesc , rowsRequired )
150153 }
@@ -192,7 +195,7 @@ func initCommon(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64)
192195 */
193196
194197func TestGeneric (b * benchmark.Benchmark , testDesc * TestDesc , workerFunc TestWorkerFunc , rowsRequired uint64 ) {
195- initCommon (b , testDesc , rowsRequired )
198+ InitCommon (b , testDesc , rowsRequired )
196199
197200 b .WorkerRunFunc = func (worker * benchmark.BenchmarkWorker ) (loops int ) {
198201 c := worker .Data .(* DBWorkerData ).workingConn
@@ -216,7 +219,7 @@ func TestSelectRun(
216219 orderByFunc func (worker * benchmark.BenchmarkWorker ) []string ,
217220 rowsRequired uint64 ,
218221) {
219- initCommon (b , testDesc , rowsRequired )
222+ InitCommon (b , testDesc , rowsRequired )
220223
221224 testOpts , ok := b .TestOpts .(* TestOpts )
222225 if ! ok {
@@ -285,7 +288,7 @@ func TestSelectRawSQLQuery(
285288 orderByFunc func (worker * benchmark.BenchmarkWorker ) string ,
286289 rowsRequired uint64 ,
287290) {
288- initCommon (b , testDesc , rowsRequired )
291+ InitCommon (b , testDesc , rowsRequired )
289292 batch := b .Vault .(* DBTestData ).EffectiveBatch
290293
291294 b .WorkerRunFunc = func (worker * benchmark.BenchmarkWorker ) (loops int ) {
@@ -368,7 +371,7 @@ func TestSelectRawSQLQuery(
368371 * INSERT worker
369372 */
370373
371- func getDBDriver (b * benchmark.Benchmark ) db.DialectName {
374+ func GetDBDriver (b * benchmark.Benchmark ) db.DialectName {
372375 var dialectName , err = db .GetDialectName (b .TestOpts .(* TestOpts ).DBOpts .ConnString )
373376 if err != nil {
374377 b .Exit (err )
@@ -378,13 +381,13 @@ func getDBDriver(b *benchmark.Benchmark) db.DialectName {
378381}
379382
380383func TestInsertGeneric (b * benchmark.Benchmark , testDesc * TestDesc ) {
381- colConfs := testDesc .Table .GetColumnsForInsert (db .WithAutoInc (getDBDriver (b )))
384+ colConfs := testDesc .Table .GetColumnsForInsert (db .WithAutoInc (GetDBDriver (b )))
382385
383386 if len (* colConfs ) == 0 {
384387 b .Exit (fmt .Sprintf ("internal error: no columns eligible for INSERT found in '%s' configuration" , testDesc .Table .TableName ))
385388 }
386389
387- initCommon (b , testDesc , 0 )
390+ InitCommon (b , testDesc , 0 )
388391
389392 batch := b .Vault .(* DBTestData ).EffectiveBatch
390393 table := & testDesc .Table
@@ -492,7 +495,7 @@ func InsertMultiValueDataWorker(b *benchmark.Benchmark, c *DBConnector, testDesc
492495 for i := 0 ; i < batch ; i ++ {
493496 var genColumns , vals , err = b .Randomizer .GenFakeData (colConfs , db .WithAutoInc (c .Database .DialectName ()))
494497 if err != nil {
495- b .Exit (err )
498+ b .Exit (err . Error () )
496499 }
497500
498501 if genColumns == nil {
@@ -525,14 +528,14 @@ func InsertMultiValueDataWorker(b *benchmark.Benchmark, c *DBConnector, testDesc
525528
526529func TestUpdateGeneric (b * benchmark.Benchmark , testDesc * TestDesc , updateRows uint64 , colConfs * []benchmark.DBFakeColumnConf ) {
527530 if colConfs == nil {
528- colConfs = testDesc .Table .GetColumnsForUpdate (db .WithAutoInc (getDBDriver (b )))
531+ colConfs = testDesc .Table .GetColumnsForUpdate (db .WithAutoInc (GetDBDriver (b )))
529532 }
530533
531534 if len (* colConfs ) == 0 {
532535 b .Exit (fmt .Sprintf ("internal error: no columns eligible for UPDATE found in '%s' configuration" , testDesc .Table .TableName ))
533536 }
534537
535- initCommon (b , testDesc , updateRows )
538+ InitCommon (b , testDesc , updateRows )
536539
537540 batch := b .Vault .(* DBTestData ).EffectiveBatch
538541 table := & testDesc .Table
@@ -594,7 +597,7 @@ func TestUpdateGeneric(b *benchmark.Benchmark, testDesc *TestDesc, updateRows ui
594597 */
595598// testDeleteGeneric is a generic DELETE worker
596599func testDeleteGeneric (b * benchmark.Benchmark , testDesc * TestDesc , deleteRows uint64 ) { //nolint:unused
597- initCommon (b , testDesc , deleteRows )
600+ InitCommon (b , testDesc , deleteRows )
598601
599602 batch := b .Vault .(* DBTestData ).EffectiveBatch
600603 table := & testDesc .Table
0 commit comments