/* Testcase for: Bug 75913 Compile : g++ bug75913.cpp -Wall -m64 -O3 -g -o bug75913 `mysql_config --libs_r` `mysql_config --include` Run : ./bug75913 --host=127.0.0.1 --port=3306 --user=root --num-queries=1000000000 --threads=1 */ #define SHUFFLE_QUERY_ORDER (1) #define PRINT_QUERY_ERRORS (0) #define PRINT_QUERIES (0) #include #include #include #include #include #include #include #include #include static pthread_t pthread_id[1000]; MYSQL *dbc; char *opt_user=NULL; char *opt_password=NULL; char *opt_host=NULL; static unsigned int opt_port=3306; char *opt_socket=NULL; char *opt_database=NULL; static int opt_help=0; static ulonglong opt_num_queries=1000; unsigned int opt_threads=1; int done=0; void *worker_thread(void *arg); int db_query(MYSQL *dbc, const char *sql, const unsigned long len); void print_usage(struct option *long_options); void default_options(); const char *init_queries[]= { "drop database if exists test;", "create database if not exists test;", "use test;", "delete from mysql.innodb_table_stats;", "delete from mysql.innodb_index_stats;", "flush tables;", NULL }; const char *runtime_queries[]= { "drop table if exists t1;", "create table if not exists `t1` (`a` int(11) not null,`b` int(11) not null,primary key (`a`,`b`),key `a` (`a`),key `b` (`b`)) engine=innodb;", "create table if not exists `t1` (`a` int(11) not null,`b` int(11) not null) engine=innodb;", "set @@global.innodb_trx_rseg_n_slots_debug = 1;", "set @@global.innodb_trx_rseg_n_slots_debug = 0;", "insert into t1 values (1, 2) ;", "delete from t1 where a=1 ;", "delete from t1 where b=2;", "delete from mysql.innodb_table_stats where table_name='t1';", "delete from mysql.innodb_index_stats where table_name='t1';", "set global innodb_file_per_table=1;", "set global innodb_file_per_table=0;", "start transaction;", "commit;", NULL }; /* getopt_long stores the option index here. */ static struct option long_options[] ={ {"help", no_argument, &opt_help, 1}, {"host", required_argument, 0, 'h'}, {"socket", required_argument, 0, 'S'}, {"port", required_argument, 0, 'P'}, {"user", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, {"database", required_argument, 0, 'd'}, {"threads", required_argument, 0, 't'}, {"num-queries",required_argument, 0, 'n'}, {0, 0, 0, 0} }; int main(int argc, char *argv[]) { int c=0; while(1) { int option_index = 0; c = getopt_long (argc, argv, "h:S:P:u:p:d:t:n:",long_options, &option_index); if (c == -1)break; switch(c) { case 0 : print_usage(long_options);break; case 'h': opt_host=strdup(optarg);break; case 'S': opt_socket=strdup(optarg);break; case 'P': opt_port=atoi(optarg);break; case 'u': opt_user=strdup(optarg);break; case 'p': opt_password=strdup(optarg);break; case 'd': opt_database=strdup(optarg);break; case 't': opt_threads=atoi(optarg);break; case 'n': opt_num_queries=atoll(optarg);break; default: print_usage(long_options);break; abort(); } }; if(opt_help) print_usage(long_options); default_options(); MYSQL *dbc=mysql_init(NULL); if(!mysql_real_connect(dbc, opt_host, opt_user,opt_password, NULL, opt_port, opt_socket, 0)) { fprintf(stderr,"#cannot connect: [%d] - %s!\n",mysql_errno(dbc),mysql_error(dbc)); goto cleanup; } fprintf(stdout, "Connected: %s [%s]\n",mysql_get_host_info(dbc),mysql_get_server_info(dbc)); mysql_select_db(dbc, opt_database); for(unsigned int i=0;init_queries[i];i++) { int r = db_query(dbc,init_queries[i],strlen(init_queries[i])); if(r!=0) { fprintf(stderr,"[%d] - %s : %s\n",mysql_errno(dbc),mysql_error(dbc),init_queries[i]); goto cleanup; } } for(unsigned int i=0;i 0) return -2; m = mysql_next_result(dbc); if (m>0)return -3; } while (0==m); return 0; } void default_options() { if(!opt_host) opt_host=strdup("localhost"); if(!opt_socket) opt_socket=strdup("/tmp/mysql.sock"); if(!opt_database)opt_database=strdup("test"); if(!opt_user) opt_user=strdup("root"); } void print_usage(struct option *long_options) { int i=0; fprintf(stdout,"Program Options: \n"); while(long_options[i].name) { fprintf(stdout,"\t\t[--%s",long_options[i].name); if(long_options[i].has_arg) fprintf(stdout,"=%s",long_options[i].name); fprintf(stdout,"]\n"); i++; } exit(0); }