269
267
uint parse_comma(const char *string, uint **range);
270
268
uint parse_delimiter(const char *script, statement **stmt, char delm);
271
269
uint parse_option(const char *origin, option_string **stmt, char delm);
272
static int drop_schema(MYSQL *mysql, const char *db);
270
static int drop_schema(DRIZZLE *drizzle, const char *db);
273
271
uint get_random_string(char *buf, size_t size);
274
272
static statement *build_table_string(void);
275
273
static statement *build_insert_string(void);
276
274
static statement *build_update_string(void);
277
275
static statement * build_select_string(bool key);
278
static int generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt);
276
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
279
277
static int drop_primary_key_list(void);
280
static int create_schema(MYSQL *mysql, const char *db, statement *stmt,
278
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
281
279
option_string *engine_stmt, stats *sptr);
282
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
280
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
284
282
pthread_handler_t run_task(void *p);
285
283
pthread_handler_t timer_thread(void *p);
286
284
void statement_cleanup(statement *stmt);
287
285
void option_cleanup(option_string *stmt);
288
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
289
static int run_statements(MYSQL *mysql, statement *stmt);
290
void slap_connect(MYSQL *mysql, bool connect_to_schema);
291
void slap_close(MYSQL *mysql);
292
static int run_query(MYSQL *mysql, const char *query, int len);
286
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
287
static int run_statements(DRIZZLE *drizzle, statement *stmt);
288
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
289
void slap_close(DRIZZLE *drizzle);
290
static int run_query(DRIZZLE *drizzle, const char *query, int len);
293
291
void standard_deviation (conclusions *con, stats *sptr);
295
293
static const char ALPHANUMERICS[]=
535
533
0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
536
534
{"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
537
535
"Add GUID based primary keys to auto-generated tables.",
538
(char**) &auto_generate_sql_guid_primary,
536
(char**) &auto_generate_sql_guid_primary,
539
537
(char**) &auto_generate_sql_guid_primary,
540
538
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
541
539
{"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
542
540
"Specify test load type: mixed, update, write, key, or read; default is mixed.",
543
541
(char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
544
542
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
545
{"auto-generate-sql-secondary-indexes",
546
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
543
{"auto-generate-sql-secondary-indexes",
544
OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
547
545
"Number of secondary indexes to add to auto-generated tables.",
548
(char**) &auto_generate_sql_secondary_indexes,
546
(char**) &auto_generate_sql_secondary_indexes,
549
547
(char**) &auto_generate_sql_secondary_indexes, 0,
550
548
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
551
{"auto-generate-sql-unique-query-number",
549
{"auto-generate-sql-unique-query-number",
552
550
OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
553
551
"Number of unique queries to generate for automatic tests.",
554
(char**) &auto_generate_sql_unique_query_number,
552
(char**) &auto_generate_sql_unique_query_number,
555
553
(char**) &auto_generate_sql_unique_query_number,
556
554
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
557
{"auto-generate-sql-unique-write-number",
555
{"auto-generate-sql-unique-write-number",
558
556
OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
559
557
"Number of unique queries to generate for auto-generate-sql-write-number.",
560
(char**) &auto_generate_sql_unique_write_number,
558
(char**) &auto_generate_sql_unique_write_number,
561
559
(char**) &auto_generate_sql_unique_write_number,
562
560
0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
563
561
{"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
586
584
(char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
587
585
0, 0, 0, 0, 0, 0},
588
586
{"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
589
(char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
587
(char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
590
588
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
591
589
{"csv", OPT_SLAP_CSV,
592
"Generate CSV output to named file or to stdout if no file is named.",
593
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
590
"Generate CSV output to named file or to stdout if no file is named.",
591
(char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
594
592
OPT_ARG, 0, 0, 0, 0, 0, 0},
595
593
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
596
594
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
597
595
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
598
596
{"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
599
597
(char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
600
{"delayed-start", OPT_SLAP_DELAYED_START,
598
{"delayed-start", OPT_SLAP_DELAYED_START,
601
599
"Delay the startup of threads by a random number of microsends (the maximum of the delay)",
602
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
600
(char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
603
601
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
604
602
{"delimiter", 'F',
605
603
"Delimiter to use in SQL statements supplied in file or command line.",
619
617
{"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
620
618
(char**) &opt_label, (char**) &opt_label, 0,
621
619
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
622
{"number-blob-cols", OPT_SLAP_BLOB_COL,
620
{"number-blob-cols", OPT_SLAP_BLOB_COL,
623
621
"Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
624
622
(char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
625
623
0, 0, 0, 0, 0, 0},
626
{"number-char-cols", 'x',
624
{"number-char-cols", 'x',
627
625
"Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
628
626
(char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
629
627
0, 0, 0, 0, 0, 0},
630
{"number-int-cols", 'y',
628
{"number-int-cols", 'y',
631
629
"Number of INT columns to create in table if specifying --auto-generate-sql.",
632
(char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
630
(char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
633
631
0, 0, 0, 0, 0, 0},
634
{"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY,
632
{"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
635
633
"Limit each client to this number of queries (this is not exact).",
636
634
(char**) &num_of_query, (char**) &num_of_query, 0,
637
635
GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
638
{"only-print", OPT_MYSQL_ONLY_PRINT,
639
"This causes mysqlslap to not connect to the databases, but instead print "
636
{"only-print", OPT_DRIZZLE_ONLY_PRINT,
637
"This causes drizzleslap to not connect to the databases, but instead print "
640
638
"out what it would have done instead.",
641
639
(char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL, NO_ARG,
642
640
0, 0, 0, 0, 0, 0},
643
641
{"password", 'p',
644
642
"Password to use when connecting to server. If password is not given it's "
645
643
"asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
646
{"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
647
(char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
644
{"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
645
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
649
647
{"post-query", OPT_SLAP_POST_QUERY,
650
648
"Query to run or file containing query to execute after tests have completed.",
651
(char**) &user_supplied_post_statements,
649
(char**) &user_supplied_post_statements,
652
650
(char**) &user_supplied_post_statements,
653
651
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
654
652
{"post-system", OPT_SLAP_POST_SYSTEM,
655
653
"system() string to execute after tests have completed.",
656
(char**) &post_system,
654
(char**) &post_system,
657
655
(char**) &post_system,
658
656
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
659
{"pre-query", OPT_SLAP_PRE_QUERY,
657
{"pre-query", OPT_SLAP_PRE_QUERY,
660
658
"Query to run or file containing query to execute before running tests.",
661
(char**) &user_supplied_pre_statements,
659
(char**) &user_supplied_pre_statements,
662
660
(char**) &user_supplied_pre_statements,
663
661
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
664
{"pre-system", OPT_SLAP_PRE_SYSTEM,
662
{"pre-system", OPT_SLAP_PRE_SYSTEM,
665
663
"system() string to execute before running tests.",
666
(char**) &pre_system,
664
(char**) &pre_system,
667
665
(char**) &pre_system,
668
666
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
669
{"protocol", OPT_MYSQL_PROTOCOL,
667
{"protocol", OPT_DRIZZLE_PROTOCOL,
670
668
"The protocol of connection (tcp,socket,pipe,memory).",
671
669
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
672
670
{"query", 'q', "Query to run or file containing query to run.",
673
671
(char**) &user_supplied_query, (char**) &user_supplied_query,
674
672
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
675
{"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
673
{"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
676
674
"Seed for random number generator (srandom(3))",
677
675
(char**)&opt_set_random_seed,
678
676
(char**)&opt_set_random_seed,0,
681
679
(char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL, NO_ARG,
682
680
0, 0, 0, 0, 0, 0},
683
681
{"socket", 'S', "Socket file to use for connection.",
684
(char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR,
682
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
685
683
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
686
{"timer-length", OPT_SLAP_TIMER_LENGTH,
687
"Require mysqlslap to run each specific test a certain amount of time in seconds.",
688
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
684
{"timer-length", OPT_SLAP_TIMER_LENGTH,
685
"Require drizzleslap to run each specific test a certain amount of time in seconds.",
686
(char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
689
687
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
690
688
#ifndef DONT_ALLOW_USER_CHANGE
691
689
{"user", 'u', "User for login if not current user.", (char**) &user,
1624
1618
if (verbose >= 3)
1625
1619
printf("%.*s;\n", len, query);
1626
return mysql_real_query(mysql, query, len);
1620
return drizzle_real_query(drizzle, query, len);
1631
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
1625
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1627
DRIZZLE_RES *result;
1635
1629
unsigned long long counter;
1639
Blackhole is a special case, this allows us to test the upper end
1633
Blackhole is a special case, this allows us to test the upper end
1640
1634
of the server during load runs.
1642
if (opt_only_print || (engine_stmt &&
1636
if (opt_only_print || (engine_stmt &&
1643
1637
strstr(engine_stmt->string, "blackhole")))
1645
1639
primary_keys_number_of= 1;
1646
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1647
primary_keys_number_of),
1640
primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1641
primary_keys_number_of),
1648
1642
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1649
1643
/* Yes, we strdup a const string to simplify the interface */
1650
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1644
primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1654
if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
1648
if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1656
1650
fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1657
mysql_error(mysql));
1651
drizzle_error(drizzle));
1661
result= mysql_store_result(mysql);
1662
primary_keys_number_of= mysql_num_rows(result);
1655
result= drizzle_store_result(drizzle);
1656
primary_keys_number_of= drizzle_num_rows(result);
1664
1658
/* So why check this? Blackhole :) */
1665
1659
if (primary_keys_number_of)
2470
2464
nptr= ptr->next;
2471
2465
if (ptr->string)
2472
my_free(ptr->string, MYF(0));
2466
my_free(ptr->string, MYF(0));
2473
2467
my_free(ptr, MYF(0));
2478
slap_close(MYSQL *mysql)
2472
slap_close(DRIZZLE *drizzle)
2477
drizzle_close(drizzle);
2487
slap_connect(MYSQL *mysql, bool connect_to_schema)
2481
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2489
2483
/* Connect to server */
2490
2484
static ulong connection_retry_sleep= 100000; /* Microseconds */
2491
2485
int x, connect_error= 1;
2496
2490
if (opt_delayed_start)
2497
2491
my_sleep(random()%opt_delayed_start);
2493
drizzle_create(drizzle);
2501
2495
if (opt_compress)
2502
mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
2496
drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
2503
2497
/* We always do opt_protocol to TCP/IP */
2504
mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
2505
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
2498
drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
2499
drizzle_options(drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
2507
2501
for (x= 0; x < 10; x++)
2511
if (mysql_real_connect(mysql, host, user, opt_password,
2505
if (drizzle_connect(drizzle, host, user, opt_password,
2512
2506
connect_to_schema ? create_schema_string : NULL,
2514
opt_mysql_unix_port,
2508
opt_drizzle_unix_port,
2515
2509
connect_flags))
2517
2511
/* Connect suceeded */