~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 MySQL
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 
 
16
   original idea: Brian Aker via playing with ab for too many years
 
17
   coded by: Patrick Galbraith
 
18
*/
20
19
 
21
20
 
22
21
/*
23
 
  Drizzle Slap
 
22
  MySQL Slap
24
23
 
25
24
  A simple program designed to work as if multiple clients querying the database,
26
25
  then reporting the timing of each stage.
27
26
 
28
 
  Drizzle slap runs three stages:
 
27
  MySQL slap runs three stages:
29
28
  1) Create schema,table, and optionally any SP or data you want to beign
30
 
  the test with. (single client)
 
29
     the test with. (single client)
31
30
  2) Load test (many clients)
32
31
  3) Cleanup (disconnection, drop table if specified, single client)
33
32
 
34
33
  Examples:
35
34
 
36
 
  Supply your own create and query SQL statements, with 50 clients
 
35
  Supply your own create and query SQL statements, with 50 clients 
37
36
  querying (200 selects for each):
38
37
 
39
 
  drizzleslap --delimiter=";" \
40
 
  --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
41
 
  --query="SELECT * FROM A" --concurrency=50 --iterations=200
 
38
    mysqlslap --delimiter=";" \
 
39
              --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
 
40
              --query="SELECT * FROM A" --concurrency=50 --iterations=200
42
41
 
43
42
  Let the program build the query SQL statement with a table of two int
44
43
  columns, three varchar columns, five clients querying (20 times each),
45
44
  don't create the table or insert the data (using the previous test's
46
45
  schema and data):
47
46
 
48
 
  drizzleslap --concurrency=5 --iterations=20 \
49
 
  --number-int-cols=2 --number-char-cols=3 \
50
 
  --auto-generate-sql
 
47
    mysqlslap --concurrency=5 --iterations=20 \
 
48
              --number-int-cols=2 --number-char-cols=3 \
 
49
              --auto-generate-sql
51
50
 
52
51
  Tell the program to load the create, insert and query SQL statements from
53
52
  the specified files, where the create.sql file has multiple table creation
54
53
  statements delimited by ';' and multiple insert statements delimited by ';'.
55
 
  The --query file will have multiple queries delimited by ';', run all the
 
54
  The --query file will have multiple queries delimited by ';', run all the 
56
55
  load statements, and then run all the queries in the query file
57
56
  with five clients (five times each):
58
57
 
59
 
  drizzleslap --concurrency=5 \
60
 
  --iterations=5 --query=query.sql --create=create.sql \
61
 
  --delimiter=";"
 
58
    mysqlslap --concurrency=5 \
 
59
              --iterations=5 --query=query.sql --create=create.sql \
 
60
              --delimiter=";"
62
61
 
63
 
  TODO:
 
62
TODO:
64
63
  Add language for better tests
65
64
  String length for files and those put on the command line are not
66
 
  setup to handle binary data.
 
65
    setup to handle binary data.
67
66
  More stats
68
67
  Break up tests and run them on multiple hosts at once.
69
68
  Allow output to be fed into a database directly.
77
76
#define DEFAULT_BLOB_SIZE 1024
78
77
 
79
78
#include "client_priv.h"
 
79
#include <mysqld_error.h>
 
80
#include <my_dir.h>
80
81
#include <signal.h>
81
82
#include <stdarg.h>
82
83
#include <sys/types.h>
83
84
#include <sys/wait.h>
84
85
#include <ctype.h>
85
 
#include <string>
86
 
 
87
 
using namespace std;
88
 
 
89
 
#ifdef HAVE_SMEM
 
86
 
 
87
#ifdef HAVE_SMEM 
90
88
static char *shared_memory_base_name=0;
91
89
#endif
92
90
 
99
97
pthread_cond_t sleep_threshhold;
100
98
 
101
99
/* Global Thread timer */
102
 
static bool timer_alarm= false;
 
100
static my_bool timer_alarm= FALSE;
103
101
pthread_mutex_t timer_alarm_mutex;
104
102
pthread_cond_t timer_alarm_threshold;
105
103
 
106
104
static char **defaults_argv;
107
105
 
108
106
char **primary_keys;
109
 
uint64_t primary_keys_number_of;
 
107
unsigned long long primary_keys_number_of;
110
108
 
111
109
static char *host= NULL, *opt_password= NULL, *user= NULL,
112
 
  *user_supplied_query= NULL,
113
 
  *user_supplied_pre_statements= NULL,
114
 
  *user_supplied_post_statements= NULL,
115
 
  *default_engine= NULL,
116
 
  *pre_system= NULL,
117
 
  *post_system= NULL,
118
 
  *opt_drizzle_unix_port= NULL;
 
110
            *user_supplied_query= NULL,
 
111
            *user_supplied_pre_statements= NULL,
 
112
            *user_supplied_post_statements= NULL,
 
113
            *default_engine= NULL,
 
114
            *pre_system= NULL,
 
115
            *post_system= NULL,
 
116
            *opt_mysql_unix_port= NULL;
119
117
 
120
118
const char *delimiter= "\n";
121
119
 
122
 
const char *create_schema_string= "drizzleslap";
 
120
const char *create_schema_string= "mysqlslap";
123
121
 
124
 
static bool opt_preserve= true;
125
 
static bool debug_info_flag= 0, debug_check_flag= 0;
126
 
static bool opt_only_print= false;
127
 
static bool opt_burnin= false;
128
 
static bool opt_ignore_sql_errors= false;
129
 
static bool opt_compress= false, tty_password= false,
130
 
  opt_silent= false,
131
 
  auto_generate_sql_autoincrement= false,
132
 
  auto_generate_sql_guid_primary= false,
133
 
  auto_generate_sql= false;
 
122
static my_bool opt_preserve= TRUE;
 
123
static my_bool debug_info_flag= 0, debug_check_flag= 0;
 
124
static my_bool opt_only_print= FALSE;
 
125
static my_bool opt_burnin= FALSE;
 
126
static my_bool opt_ignore_sql_errors= FALSE;
 
127
static my_bool opt_compress= FALSE, tty_password= FALSE,
 
128
               opt_silent= FALSE,
 
129
               auto_generate_sql_autoincrement= FALSE,
 
130
               auto_generate_sql_guid_primary= FALSE,
 
131
               auto_generate_sql= FALSE;
134
132
const char *opt_auto_generate_sql_type= "mixed";
135
133
 
136
134
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
137
 
  CLIENT_MULTI_STATEMENTS;
 
135
                                    CLIENT_MULTI_STATEMENTS;
138
136
 
139
137
static int verbose, delimiter_length;
140
138
static uint commit_rate;
155
153
static unsigned int num_blob_cols= 0;
156
154
static unsigned int num_blob_cols_size;
157
155
static unsigned int num_blob_cols_size_min;
158
 
static unsigned int num_int_cols_index= 0;
 
156
static unsigned int num_int_cols_index= 0; 
159
157
static unsigned int num_char_cols_index= 0;
160
158
static unsigned int iterations;
161
159
static uint my_end_arg= 0;
162
 
static uint64_t actual_queries= 0;
163
 
static uint64_t auto_actual_queries;
164
 
static uint64_t auto_generate_sql_unique_write_number;
165
 
static uint64_t auto_generate_sql_unique_query_number;
 
160
static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
 
161
static ulonglong actual_queries= 0;
 
162
static ulonglong auto_actual_queries;
 
163
static ulonglong auto_generate_sql_unique_write_number;
 
164
static ulonglong auto_generate_sql_unique_query_number;
166
165
static unsigned int auto_generate_sql_secondary_indexes;
167
 
static uint64_t num_of_query;
168
 
static uint64_t auto_generate_sql_number;
 
166
static ulonglong num_of_query;
 
167
static ulonglong auto_generate_sql_number;
169
168
const char *concurrency_str= NULL;
170
169
static char *create_string;
171
170
uint *concurrency;
172
171
 
173
 
const char *default_dbug_option="d:t:o,/tmp/drizzleslap.trace";
 
172
const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
174
173
const char *opt_csv_str;
175
174
File csv_file;
176
175
 
 
176
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
177
 
177
178
static int get_options(int *argc,char ***argv);
178
 
static uint opt_drizzle_port= 0;
 
179
static uint opt_mysql_port= 0;
179
180
 
180
 
static const char *load_default_groups[]= { "drizzleslap","client",0 };
 
181
static const char *load_default_groups[]= { "mysqlslap","client",0 };
181
182
 
182
183
/* Types */
183
184
typedef enum {
217
218
  long int timing;
218
219
  uint users;
219
220
  uint real_users;
220
 
  uint64_t rows;
 
221
  unsigned long long rows;
221
222
  long int create_timing;
222
 
  uint64_t create_count;
 
223
  unsigned long long create_count;
223
224
};
224
225
 
225
226
typedef struct thread_context thread_context;
226
227
 
227
228
struct thread_context {
228
229
  statement *stmt;
229
 
  uint64_t limit;
 
230
  ulonglong limit;
230
231
};
231
232
 
232
233
typedef struct conclusions conclusions;
238
239
  long int min_timing;
239
240
  uint users;
240
241
  uint real_users;
241
 
  uint64_t avg_rows;
 
242
  unsigned long long avg_rows;
242
243
  long int sum_of_time;
243
244
  long int std_dev;
244
245
  /* These are just for create time stats */
245
246
  long int create_avg_timing;
246
247
  long int create_max_timing;
247
248
  long int create_min_timing;
248
 
  uint64_t create_count;
 
249
  unsigned long long create_count;
249
250
  /* The following are not used yet */
250
 
  uint64_t max_rows;
251
 
  uint64_t min_rows;
 
251
  unsigned long long max_rows;
 
252
  unsigned long long min_rows;
252
253
};
253
254
 
254
255
static option_string *engine_options= NULL;
255
 
static option_string *query_options= NULL;
256
 
static statement *pre_statements= NULL;
257
 
static statement *post_statements= NULL;
 
256
static option_string *query_options= NULL; 
 
257
static statement *pre_statements= NULL; 
 
258
static statement *post_statements= NULL; 
258
259
static statement *create_statements= NULL;
259
260
 
260
261
static statement **query_statements= NULL;
268
269
uint parse_comma(const char *string, uint **range);
269
270
uint parse_delimiter(const char *script, statement **stmt, char delm);
270
271
uint parse_option(const char *origin, option_string **stmt, char delm);
271
 
static int drop_schema(DRIZZLE *drizzle, const char *db);
 
272
static int drop_schema(MYSQL *mysql, const char *db);
272
273
uint get_random_string(char *buf, size_t size);
273
274
static statement *build_table_string(void);
274
275
static statement *build_insert_string(void);
275
276
static statement *build_update_string(void);
276
 
static statement * build_select_string(bool key);
277
 
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
 
277
static statement * build_select_string(my_bool key);
 
278
static int generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt);
278
279
static int drop_primary_key_list(void);
279
 
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
 
280
static int create_schema(MYSQL *mysql, const char *db, statement *stmt, 
280
281
                         option_string *engine_stmt, stats *sptr);
281
 
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
282
 
                         uint64_t limit);
 
282
static int run_scheduler(stats *sptr, statement **stmts, uint concur, 
 
283
                         ulonglong limit);
283
284
pthread_handler_t run_task(void *p);
284
285
pthread_handler_t timer_thread(void *p);
285
286
void statement_cleanup(statement *stmt);
286
287
void option_cleanup(option_string *stmt);
287
 
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
288
 
static int run_statements(DRIZZLE *drizzle, statement *stmt);
289
 
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
290
 
void slap_close(DRIZZLE *drizzle);
291
 
static int run_query(DRIZZLE *drizzle, const char *query, int len);
 
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, my_bool connect_to_schema);
 
291
void slap_close(MYSQL *mysql);
 
292
static int run_query(MYSQL *mysql, const char *query, int len);
292
293
void standard_deviation (conclusions *con, stats *sptr);
293
294
 
294
295
static const char ALPHANUMERICS[]=
295
 
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
 
296
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
296
297
 
297
298
#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
298
299
 
299
300
 
300
301
static long int timedif(struct timeval a, struct timeval b)
301
302
{
302
 
  register int us, s;
303
 
 
304
 
  us = a.tv_usec - b.tv_usec;
305
 
  us /= 1000;
306
 
  s = a.tv_sec - b.tv_sec;
307
 
  s *= 1000;
308
 
  return s + us;
 
303
    register int us, s;
 
304
 
 
305
    us = a.tv_usec - b.tv_usec;
 
306
    us /= 1000;
 
307
    s = a.tv_sec - b.tv_sec;
 
308
    s *= 1000;
 
309
    return s + us;
309
310
}
310
311
 
311
312
int main(int argc, char **argv)
312
313
{
313
 
  DRIZZLE drizzle;
 
314
  MYSQL mysql;
314
315
  option_string *eptr;
315
316
  unsigned int x;
316
317
 
318
319
 
319
320
  MY_INIT(argv[0]);
320
321
 
 
322
  if (!(mysql_thread_safe()))
 
323
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
 
324
 
321
325
  load_defaults("my",load_default_groups,&argc,&argv);
322
326
  defaults_argv=argv;
323
327
  if (get_options(&argc,&argv))
346
350
    exit(1);
347
351
  }
348
352
 
349
 
  slap_connect(&drizzle, false);
 
353
  slap_connect(&mysql, FALSE);
350
354
 
351
 
  pthread_mutex_init(&counter_mutex, NULL);
352
 
  pthread_cond_init(&count_threshhold, NULL);
353
 
  pthread_mutex_init(&sleeper_mutex, NULL);
354
 
  pthread_cond_init(&sleep_threshhold, NULL);
355
 
  pthread_mutex_init(&timer_alarm_mutex, NULL);
356
 
  pthread_cond_init(&timer_alarm_threshold, NULL);
 
355
  VOID(pthread_mutex_init(&counter_mutex, NULL));
 
356
  VOID(pthread_cond_init(&count_threshhold, NULL));
 
357
  VOID(pthread_mutex_init(&sleeper_mutex, NULL));
 
358
  VOID(pthread_cond_init(&sleep_threshhold, NULL));
 
359
  VOID(pthread_mutex_init(&timer_alarm_mutex, NULL));
 
360
  VOID(pthread_cond_init(&timer_alarm_threshold, NULL));
357
361
 
358
362
 
359
363
  /* Main iterations loop */
370
374
    if (*concurrency)
371
375
    {
372
376
      for (current= concurrency; current && *current; current++)
373
 
        concurrency_loop(&drizzle, *current, eptr);
 
377
        concurrency_loop(&mysql, *current, eptr);
374
378
    }
375
379
    else
376
380
    {
377
381
      uint infinite= 1;
378
382
      do {
379
 
        concurrency_loop(&drizzle, infinite, eptr);
 
383
        concurrency_loop(&mysql, infinite, eptr);
380
384
      }
381
385
      while (infinite++);
382
386
    }
383
387
 
384
388
    if (!opt_preserve)
385
 
      drop_schema(&drizzle, create_schema_string);
 
389
      drop_schema(&mysql, create_schema_string);
386
390
 
387
391
  } while (eptr ? (eptr= eptr->next) : 0);
388
 
 
 
392
  
389
393
  if (opt_burnin)
390
394
    goto burnin;
391
395
 
392
 
  pthread_mutex_destroy(&counter_mutex);
393
 
  pthread_cond_destroy(&count_threshhold);
394
 
  pthread_mutex_destroy(&sleeper_mutex);
395
 
  pthread_cond_destroy(&sleep_threshhold);
396
 
  pthread_mutex_destroy(&timer_alarm_mutex);
397
 
  pthread_cond_destroy(&timer_alarm_threshold);
 
396
  VOID(pthread_mutex_destroy(&counter_mutex));
 
397
  VOID(pthread_cond_destroy(&count_threshhold));
 
398
  VOID(pthread_mutex_destroy(&sleeper_mutex));
 
399
  VOID(pthread_cond_destroy(&sleep_threshhold));
 
400
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
 
401
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
398
402
 
399
 
  slap_close(&drizzle);
 
403
  slap_close(&mysql);
400
404
 
401
405
  /* now free all the strings we created */
402
406
  if (opt_password)
403
 
    free(opt_password);
 
407
    my_free(opt_password, MYF(0));
404
408
 
405
 
  free(concurrency);
 
409
  my_free(concurrency, MYF(0));
406
410
 
407
411
  statement_cleanup(create_statements);
408
412
  for (x= 0; x < query_statements_count; x++)
409
413
    statement_cleanup(query_statements[x]);
410
 
  free(query_statements);
 
414
  my_free(query_statements, MYF(0));
411
415
  statement_cleanup(pre_statements);
412
416
  statement_cleanup(post_statements);
413
417
  option_cleanup(engine_options);
415
419
 
416
420
#ifdef HAVE_SMEM
417
421
  if (shared_memory_base_name)
418
 
    free(shared_memory_base_name);
 
422
    my_free(shared_memory_base_name, MYF(MY_ALLOW_ZERO_PTR));
419
423
#endif
420
424
  free_defaults(defaults_argv);
421
425
  my_end(my_end_arg);
423
427
  return 0;
424
428
}
425
429
 
426
 
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr)
 
430
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
427
431
{
428
432
  unsigned int x;
429
433
  stats *head_sptr;
430
434
  stats *sptr;
431
435
  conclusions conclusion;
432
 
  uint64_t client_limit;
 
436
  unsigned long long client_limit;
433
437
 
434
 
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
 
438
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations, 
435
439
                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
436
440
 
437
 
  memset(&conclusion, 0, sizeof(conclusions));
 
441
  bzero(&conclusion, sizeof(conclusions));
438
442
 
439
443
  if (auto_actual_queries)
440
444
    client_limit= auto_actual_queries;
450
454
      a stored_procedure that doesn't use data, or we know we already have
451
455
      data in the table.
452
456
    */
453
 
    if (opt_preserve == false)
454
 
      drop_schema(drizzle, create_schema_string);
 
457
    if (opt_preserve == FALSE)
 
458
      drop_schema(mysql, create_schema_string);
455
459
 
456
460
    /* First we create */
457
461
    if (create_statements)
458
 
      create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
 
462
      create_schema(mysql, create_schema_string, create_statements, eptr, sptr);
459
463
 
460
464
    /*
461
465
      If we generated GUID we need to build a list of them from creation that
464
468
    if (verbose >= 2)
465
469
      printf("Generating primary key list\n");
466
470
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
467
 
      generate_primary_key_list(drizzle, eptr);
 
471
      generate_primary_key_list(mysql, eptr);
468
472
 
469
473
    if (commit_rate)
470
 
      run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
474
      run_query(mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
471
475
 
472
476
    if (pre_system)
473
477
      system(pre_system);
474
478
 
475
 
    /*
476
 
      Pre statements are always run after all other logic so they can
477
 
      correct/adjust any item that they want.
 
479
    /* 
 
480
      Pre statements are always run after all other logic so they can 
 
481
      correct/adjust any item that they want. 
478
482
    */
479
483
    if (pre_statements)
480
 
      run_statements(drizzle, pre_statements);
481
 
 
482
 
    run_scheduler(sptr, query_statements, current, client_limit);
483
 
 
 
484
      run_statements(mysql, pre_statements);
 
485
 
 
486
    run_scheduler(sptr, query_statements, current, client_limit); 
 
487
    
484
488
    if (post_statements)
485
 
      run_statements(drizzle, post_statements);
 
489
      run_statements(mysql, post_statements);
486
490
 
487
491
    if (post_system)
488
492
      system(post_system);
502
506
  if (opt_csv_str)
503
507
    print_conclusions_csv(&conclusion);
504
508
 
505
 
  free(head_sptr);
 
509
  my_free(head_sptr, MYF(0));
506
510
 
507
511
}
508
512
 
510
514
static struct my_option my_long_options[] =
511
515
{
512
516
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
513
 
   0, 0, 0, 0, 0, 0},
 
517
    0, 0, 0, 0, 0, 0},
514
518
  {"auto-generate-sql-select-columns", OPT_SLAP_AUTO_GENERATE_SELECT_COLUMNS,
515
 
   "Provide a string to use for the select fields used in auto tests.",
516
 
   (char**) &auto_generate_selected_columns_opt,
517
 
   (char**) &auto_generate_selected_columns_opt,
518
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
519
    "Provide a string to use for the select fields used in auto tests.",
 
520
    (uchar**) &auto_generate_selected_columns_opt, 
 
521
    (uchar**) &auto_generate_selected_columns_opt,
 
522
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
519
523
  {"auto-generate-sql", 'a',
520
 
   "Generate SQL where not supplied by file or command line.",
521
 
   (char**) &auto_generate_sql, (char**) &auto_generate_sql,
522
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
524
    "Generate SQL where not supplied by file or command line.",
 
525
    (uchar**) &auto_generate_sql, (uchar**) &auto_generate_sql,
 
526
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
523
527
  {"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
524
 
   "Add an AUTO_INCREMENT column to auto-generated tables.",
525
 
   (char**) &auto_generate_sql_autoincrement,
526
 
   (char**) &auto_generate_sql_autoincrement,
527
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
528
    "Add an AUTO_INCREMENT column to auto-generated tables.",
 
529
    (uchar**) &auto_generate_sql_autoincrement, 
 
530
    (uchar**) &auto_generate_sql_autoincrement,
 
531
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
528
532
  {"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
529
 
   "Set this number to generate a set number of queries to run.",
530
 
   (char**) &auto_actual_queries, (char**) &auto_actual_queries,
531
 
   0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
533
    "Set this number to generate a set number of queries to run.",
 
534
    (uchar**) &auto_actual_queries, (uchar**) &auto_actual_queries,
 
535
    0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
532
536
  {"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
533
 
   "Add GUID based primary keys to auto-generated tables.",
534
 
   (char**) &auto_generate_sql_guid_primary,
535
 
   (char**) &auto_generate_sql_guid_primary,
536
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
537
    "Add GUID based primary keys to auto-generated tables.",
 
538
    (uchar**) &auto_generate_sql_guid_primary, 
 
539
    (uchar**) &auto_generate_sql_guid_primary,
 
540
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
537
541
  {"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
538
 
   "Specify test load type: mixed, update, write, key, or read; default is mixed.",
539
 
   (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
540
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
541
 
  {"auto-generate-sql-secondary-indexes",
542
 
   OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
543
 
   "Number of secondary indexes to add to auto-generated tables.",
544
 
   (char**) &auto_generate_sql_secondary_indexes,
545
 
   (char**) &auto_generate_sql_secondary_indexes, 0,
546
 
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
547
 
  {"auto-generate-sql-unique-query-number",
548
 
   OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
549
 
   "Number of unique queries to generate for automatic tests.",
550
 
   (char**) &auto_generate_sql_unique_query_number,
551
 
   (char**) &auto_generate_sql_unique_query_number,
552
 
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
553
 
  {"auto-generate-sql-unique-write-number",
554
 
   OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
555
 
   "Number of unique queries to generate for auto-generate-sql-write-number.",
556
 
   (char**) &auto_generate_sql_unique_write_number,
557
 
   (char**) &auto_generate_sql_unique_write_number,
558
 
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
542
    "Specify test load type: mixed, update, write, key, or read; default is mixed.",
 
543
    (uchar**) &opt_auto_generate_sql_type, (uchar**) &opt_auto_generate_sql_type,
 
544
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
545
  {"auto-generate-sql-secondary-indexes", 
 
546
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES, 
 
547
    "Number of secondary indexes to add to auto-generated tables.",
 
548
    (uchar**) &auto_generate_sql_secondary_indexes, 
 
549
    (uchar**) &auto_generate_sql_secondary_indexes, 0,
 
550
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
551
  {"auto-generate-sql-unique-query-number", 
 
552
    OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
 
553
    "Number of unique queries to generate for automatic tests.",
 
554
    (uchar**) &auto_generate_sql_unique_query_number, 
 
555
    (uchar**) &auto_generate_sql_unique_query_number,
 
556
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
557
  {"auto-generate-sql-unique-write-number", 
 
558
    OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
 
559
    "Number of unique queries to generate for auto-generate-sql-write-number.",
 
560
    (uchar**) &auto_generate_sql_unique_write_number, 
 
561
    (uchar**) &auto_generate_sql_unique_write_number,
 
562
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
559
563
  {"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
560
 
   "Number of row inserts to perform for each thread (default is 100).",
561
 
   (char**) &auto_generate_sql_number, (char**) &auto_generate_sql_number,
562
 
   0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
 
564
    "Number of row inserts to perform for each thread (default is 100).",
 
565
    (uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number,
 
566
    0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
563
567
  {"burnin", OPT_SLAP_BURNIN, "Run full test case in infinite loop.",
564
 
   (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
565
 
   0, 0, 0},
566
 
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS,
567
 
   "Ignore SQL erros in query run.",
568
 
   (char**) &opt_ignore_sql_errors,
569
 
   (char**) &opt_ignore_sql_errors,
570
 
   0, GET_BOOL, NO_ARG, 0, 0, 0,
571
 
   0, 0, 0},
 
568
    (uchar**) &opt_burnin, (uchar**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
569
    0, 0, 0},
 
570
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS, 
 
571
    "Ignore SQL erros in query run.",
 
572
    (uchar**) &opt_ignore_sql_errors, 
 
573
    (uchar**) &opt_ignore_sql_errors, 
 
574
    0, GET_BOOL, NO_ARG, 0, 0, 0,
 
575
    0, 0, 0},
572
576
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
573
 
   (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
574
 
   0, 0, 0, 0, 0, 0},
 
577
    (uchar**) &commit_rate, (uchar**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
 
578
    0, 0, 0, 0, 0, 0},
575
579
  {"compress", 'C', "Use compression in server/client protocol.",
576
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
577
 
   0, 0, 0},
 
580
    (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
581
    0, 0, 0},
578
582
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
579
 
   (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
580
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
583
    (uchar**) &concurrency_str, (uchar**) &concurrency_str, 0, GET_STR,
 
584
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
581
585
  {"create", OPT_SLAP_CREATE_STRING, "File or string to use create tables.",
582
 
   (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
583
 
   0, 0, 0, 0, 0, 0},
 
586
    (uchar**) &create_string, (uchar**) &create_string, 0, GET_STR, REQUIRED_ARG,
 
587
    0, 0, 0, 0, 0, 0},
584
588
  {"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
585
 
   (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
586
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
589
    (uchar**) &create_schema_string, (uchar**) &create_schema_string, 0, GET_STR, 
 
590
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
587
591
  {"csv", OPT_SLAP_CSV,
588
 
   "Generate CSV output to named file or to stdout if no file is named.",
589
 
   (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
590
 
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
592
        "Generate CSV output to named file or to stdout if no file is named.",
 
593
    (uchar**) &opt_csv_str, (uchar**) &opt_csv_str, 0, GET_STR, 
 
594
    OPT_ARG, 0, 0, 0, 0, 0, 0},
 
595
#ifdef DBUG_OFF
 
596
  {"debug", '#', "This is a non-debug version. Catch this and exit.",
 
597
   0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
598
#else
 
599
  {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
 
600
    (uchar**) &default_dbug_option, (uchar**) &default_dbug_option, 0, GET_STR,
 
601
    OPT_ARG, 0, 0, 0, 0, 0, 0},
 
602
#endif
591
603
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
592
 
    (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
593
 
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
594
 
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
595
 
    (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
596
 
  {"delayed-start", OPT_SLAP_DELAYED_START,
597
 
   "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
598
 
   (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
599
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
604
   (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
 
605
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
606
  {"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
 
607
   (uchar**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
608
  {"delayed-start", OPT_SLAP_DELAYED_START, 
 
609
    "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
 
610
    (uchar**) &opt_delayed_start, (uchar**) &opt_delayed_start, 0, GET_UINT, 
 
611
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
600
612
  {"delimiter", 'F',
601
 
   "Delimiter to use in SQL statements supplied in file or command line.",
602
 
   (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
603
 
   0, 0, 0, 0, 0, 0},
 
613
    "Delimiter to use in SQL statements supplied in file or command line.",
 
614
    (uchar**) &delimiter, (uchar**) &delimiter, 0, GET_STR, REQUIRED_ARG,
 
615
    0, 0, 0, 0, 0, 0},
604
616
  {"detach", OPT_SLAP_DETACH,
605
 
   "Detach (close and reopen) connections after X number of requests.",
606
 
   (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
607
 
   0, 0, 0, 0, 0, 0},
 
617
    "Detach (close and reopen) connections after X number of requests.",
 
618
    (uchar**) &detach_rate, (uchar**) &detach_rate, 0, GET_UINT, REQUIRED_ARG, 
 
619
    0, 0, 0, 0, 0, 0},
608
620
  {"engine", 'e', "Storage engine to use for creating the table.",
609
 
   (char**) &default_engine, (char**) &default_engine, 0,
610
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
611
 
  {"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
612
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
613
 
  {"iterations", 'i', "Number of times to run the tests.", (char**) &iterations,
614
 
   (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
 
621
    (uchar**) &default_engine, (uchar**) &default_engine, 0,
 
622
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
623
  {"host", 'h', "Connect to host.", (uchar**) &host, (uchar**) &host, 0, GET_STR,
 
624
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
625
  {"iterations", 'i', "Number of times to run the tests.", (uchar**) &iterations,
 
626
    (uchar**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
615
627
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
616
 
   (char**) &opt_label, (char**) &opt_label, 0,
617
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
618
 
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
619
 
   "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. ",
620
 
   (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
621
 
   0, 0, 0, 0, 0, 0},
622
 
  {"number-char-cols", 'x',
623
 
   "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
624
 
   (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
625
 
   0, 0, 0, 0, 0, 0},
626
 
  {"number-int-cols", 'y',
627
 
   "Number of INT columns to create in table if specifying --auto-generate-sql.",
628
 
   (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
629
 
   0, 0, 0, 0, 0, 0},
630
 
  {"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
631
 
   "Limit each client to this number of queries (this is not exact).",
632
 
   (char**) &num_of_query, (char**) &num_of_query, 0,
633
 
   GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
634
 
  {"only-print", OPT_DRIZZLE_ONLY_PRINT,
635
 
   "This causes drizzleslap to not connect to the databases, but instead print "
636
 
   "out what it would have done instead.",
637
 
   (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
638
 
   0, 0, 0, 0, 0, 0},
 
628
    (uchar**) &opt_label, (uchar**) &opt_label, 0,
 
629
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
630
  {"number-blob-cols", OPT_SLAP_BLOB_COL, 
 
631
    "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. ",
 
632
    (uchar**) &num_blob_cols_opt, (uchar**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
633
    0, 0, 0, 0, 0, 0},
 
634
  {"number-char-cols", 'x', 
 
635
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
 
636
    (uchar**) &num_char_cols_opt, (uchar**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
637
    0, 0, 0, 0, 0, 0},
 
638
  {"number-int-cols", 'y', 
 
639
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
 
640
    (uchar**) &num_int_cols_opt, (uchar**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG, 
 
641
    0, 0, 0, 0, 0, 0},
 
642
  {"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY, 
 
643
    "Limit each client to this number of queries (this is not exact).",
 
644
    (uchar**) &num_of_query, (uchar**) &num_of_query, 0,
 
645
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
646
  {"only-print", OPT_MYSQL_ONLY_PRINT,
 
647
    "This causes mysqlslap to not connect to the databases, but instead print "
 
648
      "out what it would have done instead.",
 
649
    (uchar**) &opt_only_print, (uchar**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
 
650
    0, 0, 0, 0, 0, 0},
639
651
  {"password", 'p',
640
 
   "Password to use when connecting to server. If password is not given it's "
641
 
   "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
642
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
643
 
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
644
 
   0},
 
652
    "Password to use when connecting to server. If password is not given it's "
 
653
      "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
654
  {"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
 
655
    (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
 
656
    0},
645
657
  {"post-query", OPT_SLAP_POST_QUERY,
646
 
   "Query to run or file containing query to execute after tests have completed.",
647
 
   (char**) &user_supplied_post_statements,
648
 
   (char**) &user_supplied_post_statements,
649
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
658
    "Query to run or file containing query to execute after tests have completed.",
 
659
    (uchar**) &user_supplied_post_statements, 
 
660
    (uchar**) &user_supplied_post_statements,
 
661
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
650
662
  {"post-system", OPT_SLAP_POST_SYSTEM,
651
 
   "system() string to execute after tests have completed.",
652
 
   (char**) &post_system,
653
 
   (char**) &post_system,
654
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
655
 
  {"pre-query", OPT_SLAP_PRE_QUERY,
656
 
   "Query to run or file containing query to execute before running tests.",
657
 
   (char**) &user_supplied_pre_statements,
658
 
   (char**) &user_supplied_pre_statements,
659
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
660
 
  {"pre-system", OPT_SLAP_PRE_SYSTEM,
661
 
   "system() string to execute before running tests.",
662
 
   (char**) &pre_system,
663
 
   (char**) &pre_system,
664
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
665
 
  {"protocol", OPT_DRIZZLE_PROTOCOL,
666
 
   "The protocol of connection (tcp,socket,pipe,memory).",
667
 
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
663
    "system() string to execute after tests have completed.",
 
664
    (uchar**) &post_system, 
 
665
    (uchar**) &post_system,
 
666
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
667
  {"pre-query", OPT_SLAP_PRE_QUERY, 
 
668
    "Query to run or file containing query to execute before running tests.",
 
669
    (uchar**) &user_supplied_pre_statements, 
 
670
    (uchar**) &user_supplied_pre_statements,
 
671
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
672
  {"pre-system", OPT_SLAP_PRE_SYSTEM, 
 
673
    "system() string to execute before running tests.",
 
674
    (uchar**) &pre_system, 
 
675
    (uchar**) &pre_system,
 
676
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
677
  {"protocol", OPT_MYSQL_PROTOCOL,
 
678
    "The protocol of connection (tcp,socket,pipe,memory).",
 
679
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
668
680
  {"query", 'q', "Query to run or file containing query to run.",
669
 
   (char**) &user_supplied_query, (char**) &user_supplied_query,
670
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
671
 
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
672
 
   "Seed for random number generator (srandom(3))",
673
 
   (char**)&opt_set_random_seed,
674
 
   (char**)&opt_set_random_seed,0,
675
 
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
681
    (uchar**) &user_supplied_query, (uchar**) &user_supplied_query,
 
682
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
683
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED, 
 
684
    "Seed for random number generator (srandom(3))",
 
685
    (uchar**)&opt_set_random_seed,
 
686
    (uchar**)&opt_set_random_seed,0,
 
687
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
688
#ifdef HAVE_SMEM
 
689
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
 
690
    "Base name of shared memory.", (uchar**) &shared_memory_base_name,
 
691
    (uchar**) &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG,
 
692
    0, 0, 0, 0, 0, 0},
 
693
#endif
676
694
  {"silent", 's', "Run program in silent mode - no output.",
677
 
   (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
678
 
   0, 0, 0, 0, 0, 0},
 
695
    (uchar**) &opt_silent, (uchar**) &opt_silent, 0, GET_BOOL,  NO_ARG,
 
696
    0, 0, 0, 0, 0, 0},
679
697
  {"socket", 'S', "Socket file to use for connection.",
680
 
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
681
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
682
 
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
683
 
   "Require drizzleslap to run each specific test a certain amount of time in seconds.",
684
 
   (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
685
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
698
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
 
699
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
700
  {"timer-length", OPT_SLAP_TIMER_LENGTH, 
 
701
    "Require mysqlslap to run each specific test a certain amount of time in seconds.", 
 
702
    (uchar**) &opt_timer_length, (uchar**) &opt_timer_length, 0, GET_UINT, 
 
703
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
686
704
#ifndef DONT_ALLOW_USER_CHANGE
687
 
  {"user", 'u', "User for login if not current user.", (char**) &user,
688
 
   (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
705
  {"user", 'u', "User for login if not current user.", (uchar**) &user,
 
706
    (uchar**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
689
707
#endif
690
708
  {"verbose", 'v',
691
 
   "More verbose output; you can use this multiple times to get even more "
692
 
   "verbose output.", (char**) &verbose, (char**) &verbose, 0,
693
 
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
709
    "More verbose output; you can use this multiple times to get even more "
 
710
      "verbose output.", (uchar**) &verbose, (uchar**) &verbose, 0, 
 
711
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
694
712
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
695
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
713
    NO_ARG, 0, 0, 0, 0, 0, 0},
696
714
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
697
715
};
698
716
 
699
717
 
 
718
#include <help_start.h>
 
719
 
700
720
static void print_version(void)
701
721
{
702
722
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
703
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
723
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
704
724
}
705
725
 
706
726
 
707
727
static void usage(void)
708
728
{
709
729
  print_version();
710
 
  puts("Copyright (C) 2005 DRIZZLE AB");
 
730
  puts("Copyright (C) 2005 MySQL AB");
711
731
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
712
732
       \nand you are welcome to modify and redistribute it under the GPL \
713
733
       license\n");
717
737
  my_print_help(my_long_options);
718
738
}
719
739
 
720
 
static bool
 
740
#include <help_end.h>
 
741
 
 
742
static my_bool
721
743
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
722
744
               char *argument)
723
745
{
724
 
 
 
746
  DBUG_ENTER("get_one_option");
725
747
  switch(optid) {
726
748
  case 'v':
727
749
    verbose++;
730
752
    if (argument)
731
753
    {
732
754
      char *start= argument;
733
 
      free(opt_password);
 
755
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
734
756
      opt_password= my_strdup(argument,MYF(MY_FAE));
735
 
      while (*argument) *argument++= 'x';    /* Destroy argument */
 
757
      while (*argument) *argument++= 'x';               /* Destroy argument */
736
758
      if (*start)
737
 
        start[1]= 0;        /* Cut length of argument */
 
759
        start[1]= 0;                            /* Cut length of argument */
738
760
      tty_password= 0;
739
761
    }
740
762
    else
741
763
      tty_password= 1;
742
764
    break;
 
765
  case '#':
 
766
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
767
    debug_check_flag= 1;
 
768
    break;
743
769
  case 'V':
744
770
    print_version();
745
771
    exit(0);
746
772
    break;
747
773
  case '?':
748
 
  case 'I':          /* Info */
 
774
  case 'I':                                     /* Info */
749
775
    usage();
750
776
    exit(0);
751
777
  }
752
 
  return(0);
 
778
  DBUG_RETURN(0);
753
779
}
754
780
 
755
781
 
758
784
{
759
785
  char *buf_ptr= buf;
760
786
  size_t x;
761
 
 
 
787
  DBUG_ENTER("get_random_string");
762
788
  for (x= size; x > 0; x--)
763
789
    *buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
764
 
  return(buf_ptr - buf);
 
790
  DBUG_RETURN(buf_ptr - buf);
765
791
}
766
792
 
767
793
 
777
803
  char       buf[HUGE_STRING_LENGTH];
778
804
  unsigned int        col_count;
779
805
  statement *ptr;
780
 
  string table_string;
781
 
 
782
 
  table_string.reserve(HUGE_STRING_LENGTH);
783
 
 
784
 
  table_string= "CREATE TABLE `t1` (";
 
806
  DYNAMIC_STRING table_string;
 
807
  DBUG_ENTER("build_table_string");
 
808
 
 
809
  DBUG_PRINT("info", ("num int cols %u num char cols %u",
 
810
                      num_int_cols, num_char_cols));
 
811
 
 
812
  init_dynamic_string(&table_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
813
 
 
814
  dynstr_append(&table_string, "CREATE TABLE `t1` (");
785
815
 
786
816
  if (auto_generate_sql_autoincrement)
787
817
  {
788
 
    table_string.append("id serial");
 
818
    dynstr_append(&table_string, "id serial");
789
819
 
790
820
    if (num_int_cols || num_char_cols)
791
 
      table_string.append(",");
 
821
      dynstr_append(&table_string, ",");
792
822
  }
793
823
 
794
824
  if (auto_generate_sql_guid_primary)
795
825
  {
796
 
    table_string.append("id varchar(128) primary key");
 
826
    dynstr_append(&table_string, "id varchar(128) primary key");
797
827
 
798
828
    if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
799
 
      table_string.append(",");
 
829
      dynstr_append(&table_string, ",");
800
830
  }
801
831
 
802
832
  if (auto_generate_sql_secondary_indexes)
806
836
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
807
837
    {
808
838
      if (count) /* Except for the first pass we add a comma */
809
 
        table_string.append(",");
 
839
        dynstr_append(&table_string, ",");
810
840
 
811
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
 
841
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count) 
812
842
          > HUGE_STRING_LENGTH)
813
843
      {
814
844
        fprintf(stderr, "Memory Allocation error in create table\n");
815
845
        exit(1);
816
846
      }
817
 
      table_string.append(buf);
 
847
      dynstr_append(&table_string, buf);
818
848
    }
819
849
 
820
850
    if (num_int_cols || num_char_cols)
821
 
      table_string.append(",");
 
851
      dynstr_append(&table_string, ",");
822
852
  }
823
853
 
824
854
  if (num_int_cols)
826
856
    {
827
857
      if (num_int_cols_index)
828
858
      {
829
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT, INDEX(intcol%d)",
 
859
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32), INDEX(intcol%d)", 
830
860
                     col_count, col_count) > HUGE_STRING_LENGTH)
831
861
        {
832
862
          fprintf(stderr, "Memory Allocation error in create table\n");
835
865
      }
836
866
      else
837
867
      {
838
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT ", col_count)
 
868
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32) ", col_count) 
839
869
            > HUGE_STRING_LENGTH)
840
870
        {
841
871
          fprintf(stderr, "Memory Allocation error in create table\n");
842
872
          exit(1);
843
873
        }
844
874
      }
845
 
      table_string.append(buf);
 
875
      dynstr_append(&table_string, buf);
846
876
 
847
877
      if (col_count < num_int_cols || num_char_cols > 0)
848
 
        table_string.append(",");
 
878
        dynstr_append(&table_string, ",");
849
879
    }
850
880
 
851
881
  if (num_char_cols)
853
883
    {
854
884
      if (num_char_cols_index)
855
885
      {
856
 
        if (snprintf(buf, HUGE_STRING_LENGTH,
857
 
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ",
 
886
        if (snprintf(buf, HUGE_STRING_LENGTH, 
 
887
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ", 
858
888
                     col_count, col_count) > HUGE_STRING_LENGTH)
859
889
        {
860
890
          fprintf(stderr, "Memory Allocation error in creating table\n");
863
893
      }
864
894
      else
865
895
      {
866
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)",
 
896
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)", 
867
897
                     col_count) > HUGE_STRING_LENGTH)
868
898
        {
869
899
          fprintf(stderr, "Memory Allocation error in creating table\n");
870
900
          exit(1);
871
901
        }
872
902
      }
873
 
      table_string.append(buf);
 
903
      dynstr_append(&table_string, buf);
874
904
 
875
905
      if (col_count < num_char_cols || num_blob_cols > 0)
876
 
        table_string.append(",");
 
906
        dynstr_append(&table_string, ",");
877
907
    }
878
908
 
879
909
  if (num_blob_cols)
880
910
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
881
911
    {
882
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob",
 
912
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob", 
883
913
                   col_count) > HUGE_STRING_LENGTH)
884
914
      {
885
915
        fprintf(stderr, "Memory Allocation error in creating table\n");
886
916
        exit(1);
887
917
      }
888
 
      table_string.append(buf);
 
918
      dynstr_append(&table_string, buf);
889
919
 
890
920
      if (col_count < num_blob_cols)
891
 
        table_string.append(",");
 
921
        dynstr_append(&table_string, ",");
892
922
    }
893
923
 
894
 
  table_string.append(")");
895
 
  ptr= (statement *)my_malloc(sizeof(statement),
 
924
  dynstr_append(&table_string, ")");
 
925
  ptr= (statement *)my_malloc(sizeof(statement), 
896
926
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
897
 
  ptr->string = (char *)my_malloc(table_string.length()+1,
 
927
  ptr->string = (char *)my_malloc(table_string.length+1,
898
928
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
899
 
  ptr->length= table_string.length()+1;
 
929
  ptr->length= table_string.length+1;
900
930
  ptr->type= CREATE_TABLE_TYPE;
901
 
  my_stpcpy(ptr->string, table_string.c_str());
902
 
  return(ptr);
 
931
  strmov(ptr->string, table_string.str);
 
932
  dynstr_free(&table_string);
 
933
  DBUG_RETURN(ptr);
903
934
}
904
935
 
905
936
/*
914
945
  char       buf[HUGE_STRING_LENGTH];
915
946
  unsigned int        col_count;
916
947
  statement *ptr;
917
 
  string update_string;
918
 
 
919
 
  update_string.reserve(HUGE_STRING_LENGTH);
920
 
 
921
 
  update_string= "UPDATE t1 SET ";
 
948
  DYNAMIC_STRING update_string;
 
949
  DBUG_ENTER("build_update_string");
 
950
 
 
951
  init_dynamic_string(&update_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
952
 
 
953
  dynstr_append(&update_string, "UPDATE t1 SET ");
922
954
 
923
955
  if (num_int_cols)
924
956
    for (col_count= 1; col_count <= num_int_cols; col_count++)
925
957
    {
926
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count,
 
958
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count, 
927
959
                   random()) > HUGE_STRING_LENGTH)
928
960
      {
929
961
        fprintf(stderr, "Memory Allocation error in creating update\n");
930
962
        exit(1);
931
963
      }
932
 
      update_string.append(buf);
 
964
      dynstr_append(&update_string, buf);
933
965
 
934
966
      if (col_count < num_int_cols || num_char_cols > 0)
935
 
        update_string.append(",", 1);
 
967
        dynstr_append_mem(&update_string, ",", 1);
936
968
    }
937
969
 
938
970
  if (num_char_cols)
941
973
      char rand_buffer[RAND_STRING_SIZE];
942
974
      int buf_len= get_random_string(rand_buffer, RAND_STRING_SIZE);
943
975
 
944
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count,
945
 
                   buf_len, rand_buffer)
 
976
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count, 
 
977
                   buf_len, rand_buffer) 
946
978
          > HUGE_STRING_LENGTH)
947
979
      {
948
980
        fprintf(stderr, "Memory Allocation error in creating update\n");
949
981
        exit(1);
950
982
      }
951
 
      update_string.append(buf);
 
983
      dynstr_append(&update_string, buf);
952
984
 
953
985
      if (col_count < num_char_cols)
954
 
        update_string.append(",", 1);
 
986
        dynstr_append_mem(&update_string, ",", 1);
955
987
    }
956
988
 
957
989
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
958
 
    update_string.append(" WHERE id = ");
959
 
 
960
 
 
961
 
  ptr= (statement *)my_malloc(sizeof(statement),
 
990
    dynstr_append(&update_string, " WHERE id = ");
 
991
 
 
992
 
 
993
  ptr= (statement *)my_malloc(sizeof(statement), 
962
994
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
963
995
 
964
 
  ptr->string= (char *)my_malloc(update_string.length() + 1,
965
 
                                 MYF(MY_ZEROFILL|MY_FAE|MY_WME));
966
 
  ptr->length= update_string.length()+1;
 
996
  ptr->string= (char *)my_malloc(update_string.length + 1,
 
997
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
998
  ptr->length= update_string.length+1;
967
999
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
968
1000
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
969
1001
  else
970
1002
    ptr->type= UPDATE_TYPE;
971
 
  my_stpcpy(ptr->string, update_string.c_str());
972
 
  return(ptr);
 
1003
  strmov(ptr->string, update_string.str);
 
1004
  dynstr_free(&update_string);
 
1005
  DBUG_RETURN(ptr);
973
1006
}
974
1007
 
975
1008
 
985
1018
  char       buf[HUGE_STRING_LENGTH];
986
1019
  unsigned int        col_count;
987
1020
  statement *ptr;
988
 
  string insert_string;
989
 
 
990
 
  insert_string.reserve(HUGE_STRING_LENGTH);
991
 
 
992
 
  insert_string= "INSERT INTO t1 VALUES (";
 
1021
  DYNAMIC_STRING insert_string;
 
1022
  DBUG_ENTER("build_insert_string");
 
1023
 
 
1024
  init_dynamic_string(&insert_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
1025
 
 
1026
  dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
993
1027
 
994
1028
  if (auto_generate_sql_autoincrement)
995
1029
  {
996
 
    insert_string.append("NULL");
 
1030
    dynstr_append(&insert_string, "NULL");
997
1031
 
998
1032
    if (num_int_cols || num_char_cols)
999
 
      insert_string.append(",");
 
1033
      dynstr_append(&insert_string, ",");
1000
1034
  }
1001
1035
 
1002
1036
  if (auto_generate_sql_guid_primary)
1003
1037
  {
1004
 
    insert_string.append("uuid()");
 
1038
    dynstr_append(&insert_string, "uuid()");
1005
1039
 
1006
1040
    if (num_int_cols || num_char_cols)
1007
 
      insert_string.append(",");
 
1041
      dynstr_append(&insert_string, ",");
1008
1042
  }
1009
1043
 
1010
1044
  if (auto_generate_sql_secondary_indexes)
1014
1048
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1015
1049
    {
1016
1050
      if (count) /* Except for the first pass we add a comma */
1017
 
        insert_string.append(",");
 
1051
        dynstr_append(&insert_string, ",");
1018
1052
 
1019
 
      insert_string.append("uuid()");
 
1053
      dynstr_append(&insert_string, "uuid()");
1020
1054
    }
1021
1055
 
1022
1056
    if (num_int_cols || num_char_cols)
1023
 
      insert_string.append(",");
 
1057
      dynstr_append(&insert_string, ",");
1024
1058
  }
1025
1059
 
1026
1060
  if (num_int_cols)
1031
1065
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1032
1066
        exit(1);
1033
1067
      }
1034
 
      insert_string.append(buf);
 
1068
      dynstr_append(&insert_string, buf);
1035
1069
 
1036
1070
      if (col_count < num_int_cols || num_char_cols > 0)
1037
 
        insert_string.append(",");
 
1071
        dynstr_append_mem(&insert_string, ",", 1);
1038
1072
    }
1039
1073
 
1040
1074
  if (num_char_cols)
1041
1075
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1042
1076
    {
1043
1077
      int buf_len= get_random_string(buf, RAND_STRING_SIZE);
1044
 
      insert_string.append("'", 1);
1045
 
      insert_string.append(buf, buf_len);
1046
 
      insert_string.append("'", 1);
 
1078
      dynstr_append_mem(&insert_string, "'", 1);
 
1079
      dynstr_append_mem(&insert_string, buf, buf_len);
 
1080
      dynstr_append_mem(&insert_string, "'", 1);
1047
1081
 
1048
1082
      if (col_count < num_char_cols || num_blob_cols > 0)
1049
 
        insert_string.append(",", 1);
 
1083
        dynstr_append_mem(&insert_string, ",", 1);
1050
1084
    }
1051
1085
 
1052
1086
  if (num_blob_cols)
1056
1090
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1057
1091
    {
1058
1092
      blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
1059
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1093
                             MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1060
1094
      if (!blob_ptr)
1061
1095
      {
1062
1096
        fprintf(stderr, "Memory Allocation error in creating select\n");
1074
1108
      unsigned int size;
1075
1109
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1076
1110
 
1077
 
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1078
 
        num_blob_cols_size;
 
1111
      size= difference ? (num_blob_cols_size_min + (random() % difference)) : 
 
1112
                          num_blob_cols_size;
1079
1113
 
1080
1114
      buf_len= get_random_string(blob_ptr, size);
1081
1115
 
1082
 
      insert_string.append("'", 1);
1083
 
      insert_string.append(blob_ptr, buf_len);
1084
 
      insert_string.append("'", 1);
 
1116
      dynstr_append_mem(&insert_string, "'", 1);
 
1117
      dynstr_append_mem(&insert_string, blob_ptr, buf_len);
 
1118
      dynstr_append_mem(&insert_string, "'", 1);
1085
1119
 
1086
1120
      if (col_count < num_blob_cols)
1087
 
        insert_string.append(",", 1);
 
1121
        dynstr_append_mem(&insert_string, ",", 1);
1088
1122
    }
1089
1123
 
1090
1124
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1091
 
      free(blob_ptr);
 
1125
      my_free(blob_ptr, MYF(0));
1092
1126
  }
1093
1127
 
1094
 
  insert_string.append(")", 1);
 
1128
  dynstr_append_mem(&insert_string, ")", 1);
1095
1129
 
1096
1130
  if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1097
1131
  {
1098
1132
    fprintf(stderr, "Memory Allocation error in creating select\n");
1099
1133
    exit(1);
1100
1134
  }
1101
 
  if (!(ptr->string= (char *)my_malloc(insert_string.length() + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
 
1135
  if (!(ptr->string= (char *)my_malloc(insert_string.length + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1102
1136
  {
1103
1137
    fprintf(stderr, "Memory Allocation error in creating select\n");
1104
1138
    exit(1);
1105
1139
  }
1106
 
  ptr->length= insert_string.length()+1;
 
1140
  ptr->length= insert_string.length+1;
1107
1141
  ptr->type= INSERT_TYPE;
1108
 
  my_stpcpy(ptr->string, insert_string.c_str());
1109
 
  return(ptr);
 
1142
  strmov(ptr->string, insert_string.str);
 
1143
  dynstr_free(&insert_string);
 
1144
 
 
1145
  DBUG_RETURN(ptr);
1110
1146
}
1111
1147
 
1112
1148
 
1117
1153
  statement or file containing a query statement
1118
1154
*/
1119
1155
static statement *
1120
 
build_select_string(bool key)
 
1156
build_select_string(my_bool key)
1121
1157
{
1122
1158
  char       buf[HUGE_STRING_LENGTH];
1123
1159
  unsigned int        col_count;
1124
1160
  statement *ptr;
1125
 
  string query_string;
1126
 
 
1127
 
  query_string.reserve(HUGE_STRING_LENGTH);
1128
 
 
1129
 
  query_string.append("SELECT ", 7);
 
1161
  static DYNAMIC_STRING query_string;
 
1162
  DBUG_ENTER("build_select_string");
 
1163
 
 
1164
  init_dynamic_string(&query_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
1165
 
 
1166
  dynstr_append_mem(&query_string, "SELECT ", 7);
1130
1167
  if (auto_generate_selected_columns_opt)
1131
1168
  {
1132
 
    query_string.append(auto_generate_selected_columns_opt);
 
1169
    dynstr_append(&query_string, auto_generate_selected_columns_opt);
1133
1170
  }
1134
1171
  else
1135
1172
  {
1136
1173
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1137
1174
    {
1138
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count)
 
1175
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count) 
1139
1176
          > HUGE_STRING_LENGTH)
1140
1177
      {
1141
1178
        fprintf(stderr, "Memory Allocation error in creating select\n");
1142
1179
        exit(1);
1143
1180
      }
1144
 
      query_string.append(buf);
 
1181
      dynstr_append(&query_string, buf);
1145
1182
 
1146
1183
      if (col_count < num_int_cols || num_char_cols > 0)
1147
 
        query_string.append(",", 1);
 
1184
        dynstr_append_mem(&query_string, ",", 1);
1148
1185
 
1149
1186
    }
1150
1187
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1155
1192
        fprintf(stderr, "Memory Allocation error in creating select\n");
1156
1193
        exit(1);
1157
1194
      }
1158
 
      query_string.append(buf);
 
1195
      dynstr_append(&query_string, buf);
1159
1196
 
1160
1197
      if (col_count < num_char_cols || num_blob_cols > 0)
1161
 
        query_string.append(",", 1);
 
1198
        dynstr_append_mem(&query_string, ",", 1);
1162
1199
 
1163
1200
    }
1164
1201
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1169
1206
        fprintf(stderr, "Memory Allocation error in creating select\n");
1170
1207
        exit(1);
1171
1208
      }
1172
 
      query_string.append(buf);
 
1209
      dynstr_append(&query_string, buf);
1173
1210
 
1174
1211
      if (col_count < num_blob_cols)
1175
 
        query_string.append(",", 1);
 
1212
        dynstr_append_mem(&query_string, ",", 1);
1176
1213
    }
1177
1214
  }
1178
 
  query_string.append(" FROM t1");
 
1215
  dynstr_append(&query_string, " FROM t1");
1179
1216
 
1180
 
  if ((key) &&
 
1217
  if ((key) && 
1181
1218
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1182
 
    query_string.append(" WHERE id = ");
 
1219
    dynstr_append(&query_string, " WHERE id = ");
1183
1220
 
1184
1221
  ptr= (statement *)my_malloc(sizeof(statement),
1185
1222
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1186
 
  ptr->string= (char *)my_malloc(query_string.length() + 1,
1187
 
                                 MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1188
 
  ptr->length= query_string.length()+1;
1189
 
  if ((key) &&
 
1223
  ptr->string= (char *)my_malloc(query_string.length + 1,
 
1224
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1225
  ptr->length= query_string.length+1;
 
1226
  if ((key) && 
1190
1227
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1191
1228
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1192
1229
  else
1193
1230
    ptr->type= SELECT_TYPE;
1194
 
  my_stpcpy(ptr->string, query_string.c_str());
1195
 
  return(ptr);
 
1231
  strmov(ptr->string, query_string.str);
 
1232
  dynstr_free(&query_string);
 
1233
  DBUG_RETURN(ptr);
1196
1234
}
1197
1235
 
1198
1236
static int
1204
1242
  option_string *sql_type;
1205
1243
  unsigned int sql_type_count= 0;
1206
1244
 
1207
 
 
 
1245
  DBUG_ENTER("get_options");
1208
1246
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1209
1247
    exit(ho_error);
1210
1248
  if (debug_info_flag)
1217
1255
 
1218
1256
  /* If something is created we clean it up, otherwise we leave schemas alone */
1219
1257
  if (create_string || auto_generate_sql)
1220
 
    opt_preserve= false;
 
1258
    opt_preserve= FALSE;
1221
1259
 
1222
1260
  if (auto_generate_sql && (create_string || user_supplied_query))
1223
1261
  {
1224
 
    fprintf(stderr,
1225
 
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1226
 
            my_progname);
1227
 
    exit(1);
 
1262
      fprintf(stderr,
 
1263
              "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
 
1264
              my_progname);
 
1265
      exit(1);
1228
1266
  }
1229
1267
 
1230
 
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
 
1268
  if (auto_generate_sql && auto_generate_sql_guid_primary && 
1231
1269
      auto_generate_sql_autoincrement)
1232
1270
  {
1233
 
    fprintf(stderr,
1234
 
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1235
 
            my_progname);
1236
 
    exit(1);
 
1271
      fprintf(stderr,
 
1272
              "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
 
1273
              my_progname);
 
1274
      exit(1);
1237
1275
  }
1238
1276
 
1239
1277
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1240
1278
  {
1241
 
    fprintf(stderr,
1242
 
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1243
 
            my_progname);
1244
 
    exit(1);
 
1279
      fprintf(stderr,
 
1280
              "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
 
1281
              my_progname);
 
1282
      exit(1);
1245
1283
  }
1246
1284
 
1247
1285
  parse_comma(concurrency_str ? concurrency_str : "1", &concurrency);
1248
1286
 
1249
1287
  if (opt_csv_str)
1250
1288
  {
1251
 
    opt_silent= true;
1252
 
 
 
1289
    opt_silent= TRUE;
 
1290
    
1253
1291
    if (opt_csv_str[0] == '-')
1254
1292
    {
1255
1293
      csv_file= fileno(stdout);
1267
1305
  }
1268
1306
 
1269
1307
  if (opt_only_print)
1270
 
    opt_silent= true;
 
1308
    opt_silent= TRUE;
1271
1309
 
1272
1310
  if (num_int_cols_opt)
1273
1311
  {
1321
1359
 
1322
1360
  if (auto_generate_sql)
1323
1361
  {
1324
 
    uint64_t x= 0;
 
1362
    unsigned long long x= 0;
1325
1363
    statement *ptr_statement;
1326
1364
 
1327
1365
    if (verbose >= 2)
1328
1366
      printf("Building Create Statements for Auto\n");
1329
1367
 
1330
1368
    create_statements= build_table_string();
1331
 
    /*
1332
 
      Pre-populate table
 
1369
    /* 
 
1370
      Pre-populate table 
1333
1371
    */
1334
 
    for (ptr_statement= create_statements, x= 0;
1335
 
         x < auto_generate_sql_unique_write_number;
 
1372
    for (ptr_statement= create_statements, x= 0; 
 
1373
         x < auto_generate_sql_unique_write_number; 
1336
1374
         x++, ptr_statement= ptr_statement->next)
1337
1375
    {
1338
1376
      ptr_statement->next= build_insert_string();
1344
1382
    if (!opt_auto_generate_sql_type)
1345
1383
      opt_auto_generate_sql_type= "mixed";
1346
1384
 
1347
 
    query_statements_count=
 
1385
    query_statements_count= 
1348
1386
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1349
1387
 
1350
1388
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1358
1396
        if (verbose >= 2)
1359
1397
          printf("Generating SELECT Statements for Auto\n");
1360
1398
 
1361
 
        query_statements[sql_type_count]= build_select_string(false);
1362
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1363
 
             x < auto_generate_sql_unique_query_number;
 
1399
        query_statements[sql_type_count]= build_select_string(FALSE);
 
1400
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1401
             x < auto_generate_sql_unique_query_number; 
1364
1402
             x++, ptr_statement= ptr_statement->next)
1365
1403
        {
1366
 
          ptr_statement->next= build_select_string(false);
 
1404
          ptr_statement->next= build_select_string(FALSE);
1367
1405
        }
1368
1406
      }
1369
1407
      else if (sql_type->string[0] == 'k')
1371
1409
        if (verbose >= 2)
1372
1410
          printf("Generating SELECT for keys Statements for Auto\n");
1373
1411
 
1374
 
        if ( auto_generate_sql_autoincrement == false &&
1375
 
             auto_generate_sql_guid_primary == false)
 
1412
        if ( auto_generate_sql_autoincrement == FALSE &&
 
1413
             auto_generate_sql_guid_primary == FALSE)
1376
1414
        {
1377
1415
          fprintf(stderr,
1378
1416
                  "%s: Can't perform key test without a primary key!\n",
1380
1418
          exit(1);
1381
1419
        }
1382
1420
 
1383
 
        query_statements[sql_type_count]= build_select_string(true);
1384
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1385
 
             x < auto_generate_sql_unique_query_number;
 
1421
        query_statements[sql_type_count]= build_select_string(TRUE);
 
1422
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1423
             x < auto_generate_sql_unique_query_number; 
1386
1424
             x++, ptr_statement= ptr_statement->next)
1387
1425
        {
1388
 
          ptr_statement->next= build_select_string(true);
 
1426
          ptr_statement->next= build_select_string(TRUE);
1389
1427
        }
1390
1428
      }
1391
1429
      else if (sql_type->string[0] == 'w')
1392
1430
      {
1393
1431
        /*
1394
 
          We generate a number of strings in case the engine is
 
1432
          We generate a number of strings in case the engine is 
1395
1433
          Archive (since strings which were identical one after another
1396
1434
          would be too easily optimized).
1397
1435
        */
1398
1436
        if (verbose >= 2)
1399
1437
          printf("Generating INSERT Statements for Auto\n");
1400
1438
        query_statements[sql_type_count]= build_insert_string();
1401
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1402
 
             x < auto_generate_sql_unique_query_number;
 
1439
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1440
             x < auto_generate_sql_unique_query_number; 
1403
1441
             x++, ptr_statement= ptr_statement->next)
1404
1442
        {
1405
1443
          ptr_statement->next= build_insert_string();
1407
1445
      }
1408
1446
      else if (sql_type->string[0] == 'u')
1409
1447
      {
1410
 
        if ( auto_generate_sql_autoincrement == false &&
1411
 
             auto_generate_sql_guid_primary == false)
 
1448
        if ( auto_generate_sql_autoincrement == FALSE &&
 
1449
             auto_generate_sql_guid_primary == FALSE)
1412
1450
        {
1413
1451
          fprintf(stderr,
1414
1452
                  "%s: Can't perform update test without a primary key!\n",
1417
1455
        }
1418
1456
 
1419
1457
        query_statements[sql_type_count]= build_update_string();
1420
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1421
 
             x < auto_generate_sql_unique_query_number;
 
1458
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1459
             x < auto_generate_sql_unique_query_number; 
1422
1460
             x++, ptr_statement= ptr_statement->next)
1423
1461
        {
1424
1462
          ptr_statement->next= build_update_string();
1429
1467
        int coin= 0;
1430
1468
 
1431
1469
        query_statements[sql_type_count]= build_insert_string();
1432
 
        /*
 
1470
        /* 
1433
1471
          This logic should be extended to do a more mixed load,
1434
1472
          at the moment it results in "every other".
1435
1473
        */
1436
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1437
 
             x < auto_generate_sql_unique_query_number;
 
1474
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1475
             x < auto_generate_sql_unique_query_number; 
1438
1476
             x++, ptr_statement= ptr_statement->next)
1439
1477
        {
1440
1478
          if (coin)
1444
1482
          }
1445
1483
          else
1446
1484
          {
1447
 
            ptr_statement->next= build_select_string(true);
 
1485
            ptr_statement->next= build_select_string(TRUE);
1448
1486
            coin= 1;
1449
1487
          }
1450
1488
        }
1457
1495
    if (create_string && !stat(create_string, &sbuf))
1458
1496
    {
1459
1497
      File data_file;
1460
 
      if (!S_ISREG(sbuf.st_mode))
 
1498
      if (!MY_S_ISREG(sbuf.st_mode))
1461
1499
      {
1462
1500
        fprintf(stderr,"%s: Create file was not a regular file\n",
1463
1501
                my_progname);
1469
1507
        exit(1);
1470
1508
      }
1471
1509
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1472
 
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1473
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1510
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1511
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1474
1512
      tmp_string[sbuf.st_size]= '\0';
1475
1513
      my_close(data_file,MYF(0));
1476
1514
      parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1477
 
      free(tmp_string);
 
1515
      my_free(tmp_string, MYF(0));
1478
1516
    }
1479
1517
    else if (create_string)
1480
1518
    {
1481
 
      parse_delimiter(create_string, &create_statements, delimiter[0]);
 
1519
        parse_delimiter(create_string, &create_statements, delimiter[0]);
1482
1520
    }
1483
1521
 
1484
1522
    /* Set this up till we fully support options on user generated queries */
1485
1523
    if (user_supplied_query)
1486
1524
    {
1487
 
      query_statements_count=
 
1525
      query_statements_count= 
1488
1526
        parse_option("default", &query_options, ',');
1489
1527
 
1490
1528
      query_statements= (statement **)my_malloc(sizeof(statement *),
1494
1532
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1495
1533
    {
1496
1534
      File data_file;
1497
 
      if (!S_ISREG(sbuf.st_mode))
 
1535
      if (!MY_S_ISREG(sbuf.st_mode))
1498
1536
      {
1499
1537
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1500
1538
                my_progname);
1507
1545
      }
1508
1546
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1509
1547
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1510
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1548
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1511
1549
      tmp_string[sbuf.st_size]= '\0';
1512
1550
      my_close(data_file,MYF(0));
1513
1551
      if (user_supplied_query)
1514
1552
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1515
1553
                                        delimiter[0]);
1516
 
      free(tmp_string);
1517
 
    }
 
1554
      my_free(tmp_string, MYF(0));
 
1555
    } 
1518
1556
    else if (user_supplied_query)
1519
1557
    {
1520
1558
      actual_queries= parse_delimiter(user_supplied_query, &query_statements[0],
1526
1564
      && !stat(user_supplied_pre_statements, &sbuf))
1527
1565
  {
1528
1566
    File data_file;
1529
 
    if (!S_ISREG(sbuf.st_mode))
 
1567
    if (!MY_S_ISREG(sbuf.st_mode))
1530
1568
    {
1531
1569
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1532
1570
              my_progname);
1539
1577
    }
1540
1578
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1541
1579
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1542
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1580
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1543
1581
    tmp_string[sbuf.st_size]= '\0';
1544
1582
    my_close(data_file,MYF(0));
1545
1583
    if (user_supplied_pre_statements)
1546
1584
      (void)parse_delimiter(tmp_string, &pre_statements,
1547
1585
                            delimiter[0]);
1548
 
    free(tmp_string);
1549
 
  }
 
1586
    my_free(tmp_string, MYF(0));
 
1587
  } 
1550
1588
  else if (user_supplied_pre_statements)
1551
1589
  {
1552
1590
    (void)parse_delimiter(user_supplied_pre_statements,
1558
1596
      && !stat(user_supplied_post_statements, &sbuf))
1559
1597
  {
1560
1598
    File data_file;
1561
 
    if (!S_ISREG(sbuf.st_mode))
 
1599
    if (!MY_S_ISREG(sbuf.st_mode))
1562
1600
    {
1563
1601
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1564
1602
              my_progname);
1571
1609
    }
1572
1610
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1573
1611
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1574
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1612
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1575
1613
    tmp_string[sbuf.st_size]= '\0';
1576
1614
    my_close(data_file,MYF(0));
1577
1615
    if (user_supplied_post_statements)
1578
1616
      (void)parse_delimiter(tmp_string, &post_statements,
1579
1617
                            delimiter[0]);
1580
 
    free(tmp_string);
1581
 
  }
 
1618
    my_free(tmp_string, MYF(0));
 
1619
  } 
1582
1620
  else if (user_supplied_post_statements)
1583
1621
  {
1584
1622
    (void)parse_delimiter(user_supplied_post_statements, &post_statements,
1592
1630
    parse_option(default_engine, &engine_options, ',');
1593
1631
 
1594
1632
  if (tty_password)
1595
 
    opt_password= get_tty_password(NULL);
1596
 
  return(0);
 
1633
    opt_password= get_tty_password(NullS);
 
1634
  DBUG_RETURN(0);
1597
1635
}
1598
1636
 
1599
1637
 
1600
 
static int run_query(DRIZZLE *drizzle, const char *query, int len)
 
1638
static int run_query(MYSQL *mysql, const char *query, int len)
1601
1639
{
1602
1640
  if (opt_only_print)
1603
1641
  {
1607
1645
 
1608
1646
  if (verbose >= 3)
1609
1647
    printf("%.*s;\n", len, query);
1610
 
  return drizzle_real_query(drizzle, query, len);
 
1648
  return mysql_real_query(mysql, query, len);
1611
1649
}
1612
1650
 
1613
1651
 
1614
1652
static int
1615
 
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
 
1653
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
1616
1654
{
1617
 
  DRIZZLE_RES *result;
1618
 
  DRIZZLE_ROW row;
1619
 
  uint64_t counter;
1620
 
 
1621
 
 
1622
 
  /*
1623
 
    Blackhole is a special case, this allows us to test the upper end
 
1655
  MYSQL_RES *result;
 
1656
  MYSQL_ROW row;
 
1657
  unsigned long long counter;
 
1658
  DBUG_ENTER("generate_primary_key_list");
 
1659
 
 
1660
  /* 
 
1661
    Blackhole is a special case, this allows us to test the upper end 
1624
1662
    of the server during load runs.
1625
1663
  */
1626
 
  if (opt_only_print || (engine_stmt &&
 
1664
  if (opt_only_print || (engine_stmt && 
1627
1665
                         strstr(engine_stmt->string, "blackhole")))
1628
1666
  {
1629
1667
    primary_keys_number_of= 1;
1630
 
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1631
 
                                            primary_keys_number_of),
1632
 
                                     MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1668
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
 
1669
                                            primary_keys_number_of), 
 
1670
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1633
1671
    /* Yes, we strdup a const string to simplify the interface */
1634
 
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
 
1672
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0)); 
1635
1673
  }
1636
1674
  else
1637
1675
  {
1638
 
    if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
 
1676
    if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
1639
1677
    {
1640
1678
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1641
 
              drizzle_error(drizzle));
 
1679
              mysql_error(mysql));
1642
1680
      exit(1);
1643
1681
    }
1644
1682
 
1645
 
    result= drizzle_store_result(drizzle);
1646
 
    primary_keys_number_of= drizzle_num_rows(result);
 
1683
    result= mysql_store_result(mysql);
 
1684
    primary_keys_number_of= mysql_num_rows(result);
1647
1685
 
1648
1686
    /* So why check this? Blackhole :) */
1649
1687
    if (primary_keys_number_of)
1651
1689
      /*
1652
1690
        We create the structure and loop and create the items.
1653
1691
      */
1654
 
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1655
 
                                              primary_keys_number_of),
 
1692
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
 
1693
                                              primary_keys_number_of), 
1656
1694
                                       MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1657
 
      row= drizzle_fetch_row(result);
1658
 
      for (counter= 0; counter < primary_keys_number_of;
1659
 
           counter++, row= drizzle_fetch_row(result))
 
1695
      row= mysql_fetch_row(result);
 
1696
      for (counter= 0; counter < primary_keys_number_of; 
 
1697
           counter++, row= mysql_fetch_row(result))
1660
1698
        primary_keys[counter]= my_strdup(row[0], MYF(0));
1661
1699
    }
1662
1700
 
1663
 
    drizzle_free_result(result);
 
1701
    mysql_free_result(result);
1664
1702
  }
1665
1703
 
1666
 
  return(0);
 
1704
  DBUG_RETURN(0);
1667
1705
}
1668
1706
 
1669
1707
static int
1670
1708
drop_primary_key_list(void)
1671
1709
{
1672
 
  uint64_t counter;
 
1710
  unsigned long long counter;
1673
1711
 
1674
1712
  if (primary_keys_number_of)
1675
1713
  {
1676
1714
    for (counter= 0; counter < primary_keys_number_of; counter++)
1677
 
      free(primary_keys[counter]);
 
1715
      my_free(primary_keys[counter], MYF(0));
1678
1716
 
1679
 
    free(primary_keys);
 
1717
    my_free(primary_keys, MYF(0));
1680
1718
  }
1681
1719
 
1682
1720
  return 0;
1683
1721
}
1684
1722
 
1685
1723
static int
1686
 
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
 
1724
create_schema(MYSQL *mysql, const char *db, statement *stmt, 
1687
1725
              option_string *engine_stmt, stats *sptr)
1688
1726
{
1689
1727
  char query[HUGE_STRING_LENGTH];
1690
1728
  statement *ptr;
1691
1729
  statement *after_create;
1692
1730
  int len;
1693
 
  uint64_t count;
 
1731
  ulonglong count;
1694
1732
  struct timeval start_time, end_time;
1695
 
 
 
1733
  DBUG_ENTER("create_schema");
1696
1734
 
1697
1735
  gettimeofday(&start_time, NULL);
1698
1736
 
1701
1739
  if (verbose >= 2)
1702
1740
    printf("Loading Pre-data\n");
1703
1741
 
1704
 
  if (run_query(drizzle, query, len))
 
1742
  if (run_query(mysql, query, len))
1705
1743
  {
1706
1744
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1707
 
            drizzle_error(drizzle));
 
1745
            mysql_error(mysql));
1708
1746
    exit(1);
1709
1747
  }
1710
1748
  else
1721
1759
    if (verbose >= 3)
1722
1760
      printf("%s;\n", query);
1723
1761
 
1724
 
    if (drizzle_select_db(drizzle,  db))
 
1762
    if (mysql_select_db(mysql,  db))
1725
1763
    {
1726
1764
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1727
 
              drizzle_error(drizzle));
 
1765
              mysql_error(mysql));
1728
1766
      exit(1);
1729
1767
    }
1730
1768
    sptr->create_count++;
1734
1772
  {
1735
1773
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1736
1774
                  engine_stmt->string);
1737
 
    if (run_query(drizzle, query, len))
 
1775
    if (run_query(mysql, query, len))
1738
1776
    {
1739
1777
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1740
 
              drizzle_error(drizzle));
 
1778
              mysql_error(mysql));
1741
1779
      exit(1);
1742
1780
    }
1743
1781
    sptr->create_count++;
1756
1794
    {
1757
1795
      char buffer[HUGE_STRING_LENGTH];
1758
1796
 
1759
 
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
 
1797
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string, 
1760
1798
               engine_stmt->option);
1761
 
      if (run_query(drizzle, buffer, strlen(buffer)))
 
1799
      if (run_query(mysql, buffer, strlen(buffer)))
1762
1800
      {
1763
1801
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1764
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1802
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1765
1803
        if (!opt_ignore_sql_errors)
1766
1804
          exit(1);
1767
1805
      }
1769
1807
    }
1770
1808
    else
1771
1809
    {
1772
 
      if (run_query(drizzle, ptr->string, ptr->length))
 
1810
      if (run_query(mysql, ptr->string, ptr->length))
1773
1811
      {
1774
1812
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1775
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1813
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1776
1814
        if (!opt_ignore_sql_errors)
1777
1815
          exit(1);
1778
1816
      }
1791
1829
 
1792
1830
  sptr->create_timing= timedif(end_time, start_time);
1793
1831
 
1794
 
  return(0);
 
1832
  DBUG_RETURN(0);
1795
1833
}
1796
1834
 
1797
1835
static int
1798
 
drop_schema(DRIZZLE *drizzle, const char *db)
 
1836
drop_schema(MYSQL *mysql, const char *db)
1799
1837
{
1800
1838
  char query[HUGE_STRING_LENGTH];
1801
1839
  int len;
1802
 
 
 
1840
  DBUG_ENTER("drop_schema");
1803
1841
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1804
1842
 
1805
 
  if (run_query(drizzle, query, len))
 
1843
  if (run_query(mysql, query, len))
1806
1844
  {
1807
1845
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1808
 
            my_progname, db, drizzle_error(drizzle));
 
1846
            my_progname, db, mysql_error(mysql));
1809
1847
    exit(1);
1810
1848
  }
1811
1849
 
1812
1850
 
1813
1851
 
1814
 
  return(0);
 
1852
  DBUG_RETURN(0);
1815
1853
}
1816
1854
 
1817
1855
static int
1818
 
run_statements(DRIZZLE *drizzle, statement *stmt)
 
1856
run_statements(MYSQL *mysql, statement *stmt) 
1819
1857
{
1820
1858
  statement *ptr;
1821
 
  DRIZZLE_RES *result;
1822
 
 
 
1859
  MYSQL_RES *result;
 
1860
  DBUG_ENTER("run_statements");
1823
1861
 
1824
1862
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
1825
1863
  {
1826
 
    if (run_query(drizzle, ptr->string, ptr->length))
 
1864
    if (run_query(mysql, ptr->string, ptr->length))
1827
1865
    {
1828
1866
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1829
 
              my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1867
              my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1830
1868
      exit(1);
1831
1869
    }
1832
1870
    if (!opt_only_print)
1833
1871
    {
1834
 
      if (drizzle_field_count(drizzle))
 
1872
      if (mysql_field_count(mysql))
1835
1873
      {
1836
 
        result= drizzle_store_result(drizzle);
1837
 
        drizzle_free_result(result);
 
1874
        result= mysql_store_result(mysql);
 
1875
        mysql_free_result(result);
1838
1876
      }
1839
1877
    }
1840
1878
  }
1841
1879
 
1842
 
  return(0);
 
1880
  DBUG_RETURN(0);
1843
1881
}
1844
1882
 
1845
1883
static int
1846
 
run_scheduler(stats *sptr, statement **stmts, uint concur, uint64_t limit)
 
1884
run_scheduler(stats *sptr, statement **stmts, uint concur, ulonglong limit)
1847
1885
{
1848
1886
  uint x;
1849
1887
  uint y;
1853
1891
  thread_context *con;
1854
1892
  pthread_t mainthread;            /* Thread descriptor */
1855
1893
  pthread_attr_t attr;          /* Thread attributes */
1856
 
 
 
1894
  DBUG_ENTER("run_scheduler");
1857
1895
 
1858
1896
  pthread_attr_init(&attr);
1859
1897
  pthread_attr_setdetachstate(&attr,
1860
 
                              PTHREAD_CREATE_DETACHED);
 
1898
                  PTHREAD_CREATE_DETACHED);
1861
1899
 
1862
1900
  pthread_mutex_lock(&counter_mutex);
1863
1901
  thread_counter= 0;
1868
1906
 
1869
1907
  real_concurrency= 0;
1870
1908
 
1871
 
  for (y= 0, sql_type= query_options;
1872
 
       y < query_statements_count;
 
1909
  for (y= 0, sql_type= query_options; 
 
1910
       y < query_statements_count; 
1873
1911
       y++, sql_type= sql_type->next)
1874
1912
  {
1875
1913
    unsigned int options_loop= 1;
1876
1914
 
1877
1915
    if (sql_type->option)
1878
1916
    {
1879
 
      options_loop= strtol(sql_type->option,
 
1917
      options_loop= strtol(sql_type->option, 
1880
1918
                           (char **)NULL, 10);
1881
1919
      options_loop= options_loop ? options_loop : 1;
1882
1920
    }
1890
1928
 
1891
1929
        real_concurrency++;
1892
1930
        /* now you create the thread */
1893
 
        if (pthread_create(&mainthread, &attr, run_task,
 
1931
        if (pthread_create(&mainthread, &attr, run_task, 
1894
1932
                           (void *)con) != 0)
1895
1933
        {
1896
1934
          fprintf(stderr,"%s: Could not create thread\n", my_progname);
1900
1938
      }
1901
1939
  }
1902
1940
 
1903
 
  /*
1904
 
    The timer_thread belongs to all threads so it too obeys the wakeup
 
1941
  /* 
 
1942
    The timer_thread belongs to all threads so it too obeys the wakeup 
1905
1943
    call that run tasks obey.
1906
1944
  */
1907
1945
  if (opt_timer_length)
1908
1946
  {
1909
1947
    pthread_mutex_lock(&timer_alarm_mutex);
1910
 
    timer_alarm= true;
 
1948
    timer_alarm= TRUE;
1911
1949
    pthread_mutex_unlock(&timer_alarm_mutex);
1912
1950
 
1913
 
    if (pthread_create(&mainthread, &attr, timer_thread,
 
1951
    if (pthread_create(&mainthread, &attr, timer_thread, 
1914
1952
                       (void *)&opt_timer_length) != 0)
1915
1953
    {
1916
1954
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
1949
1987
  sptr->real_users= real_concurrency;
1950
1988
  sptr->rows= limit;
1951
1989
 
1952
 
  return(0);
 
1990
  DBUG_RETURN(0);
1953
1991
}
1954
1992
 
1955
1993
 
1958
1996
  uint *timer_length= (uint *)p;
1959
1997
  struct timespec abstime;
1960
1998
 
1961
 
 
1962
 
  /*
1963
 
    We lock around the initial call in case were we in a loop. This
 
1999
  DBUG_ENTER("timer_thread");
 
2000
 
 
2001
  if (mysql_thread_init())
 
2002
  {
 
2003
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
2004
            my_progname);
 
2005
    exit(1);
 
2006
  }
 
2007
 
 
2008
  /* 
 
2009
    We lock around the initial call in case were we in a loop. This 
1964
2010
    also keeps the value properly syncronized across call threads.
1965
2011
  */
1966
2012
  pthread_mutex_lock(&sleeper_mutex);
1977
2023
  pthread_mutex_unlock(&timer_alarm_mutex);
1978
2024
 
1979
2025
  pthread_mutex_lock(&timer_alarm_mutex);
1980
 
  timer_alarm= false;
 
2026
  timer_alarm= FALSE;
1981
2027
  pthread_mutex_unlock(&timer_alarm_mutex);
1982
2028
 
1983
 
  return(0);
 
2029
  mysql_thread_end();
 
2030
  DBUG_RETURN(0);
1984
2031
}
1985
2032
 
1986
2033
pthread_handler_t run_task(void *p)
1987
2034
{
1988
 
  uint64_t counter= 0, queries;
1989
 
  uint64_t detach_counter;
 
2035
  ulonglong counter= 0, queries;
 
2036
  ulonglong detach_counter;
1990
2037
  unsigned int commit_counter;
1991
 
  DRIZZLE drizzle;
1992
 
  DRIZZLE_RES *result;
1993
 
  DRIZZLE_ROW row;
 
2038
  MYSQL mysql;
 
2039
  MYSQL_RES *result;
 
2040
  MYSQL_ROW row;
1994
2041
  statement *ptr;
1995
2042
  thread_context *con= (thread_context *)p;
1996
2043
 
 
2044
  DBUG_ENTER("run_task");
 
2045
 
 
2046
  if (mysql_thread_init())
 
2047
  {
 
2048
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
2049
            my_progname);
 
2050
    exit(1);
 
2051
  }
 
2052
 
 
2053
  DBUG_PRINT("info", ("task script \"%s\"", con->stmt ? con->stmt->string : ""));
 
2054
 
1997
2055
  pthread_mutex_lock(&sleeper_mutex);
1998
2056
  while (master_wakeup)
1999
2057
  {
2001
2059
  }
2002
2060
  pthread_mutex_unlock(&sleeper_mutex);
2003
2061
 
2004
 
  slap_connect(&drizzle, true);
2005
 
 
 
2062
  DBUG_PRINT("info", ("trying to connect to host %s as user %s", host, user));
 
2063
 
 
2064
  slap_connect(&mysql, TRUE);
 
2065
 
 
2066
  DBUG_PRINT("info", ("connected."));
2006
2067
  if (verbose >= 3)
2007
2068
    printf("connected!\n");
2008
2069
  queries= 0;
2009
2070
 
2010
2071
  commit_counter= 0;
2011
2072
  if (commit_rate)
2012
 
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
2073
    run_query(&mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2013
2074
 
2014
2075
limit_not_met:
2015
 
  for (ptr= con->stmt, detach_counter= 0;
2016
 
       ptr && ptr->length;
2017
 
       ptr= ptr->next, detach_counter++)
2018
 
  {
2019
 
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2020
 
    {
2021
 
      slap_close(&drizzle);
2022
 
      slap_connect(&drizzle, true);
2023
 
    }
2024
 
 
2025
 
    /*
2026
 
      We have to execute differently based on query type. This should become a function.
2027
 
    */
2028
 
    if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
2029
 
        (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
2030
 
    {
2031
 
      int length;
2032
 
      unsigned int key_val;
2033
 
      char *key;
2034
 
      char buffer[HUGE_STRING_LENGTH];
2035
 
 
2036
 
      /*
2037
 
        This should only happen if some sort of new engine was
2038
 
        implemented that didn't properly handle UPDATEs.
2039
 
 
2040
 
        Just in case someone runs this under an experimental engine we don't
2041
 
        want a crash so the if() is placed here.
 
2076
    for (ptr= con->stmt, detach_counter= 0; 
 
2077
         ptr && ptr->length; 
 
2078
         ptr= ptr->next, detach_counter++)
 
2079
    {
 
2080
      if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
2081
      {
 
2082
        slap_close(&mysql);
 
2083
        slap_connect(&mysql, TRUE);
 
2084
      }
 
2085
 
 
2086
      /* 
 
2087
        We have to execute differently based on query type. This should become a function.
2042
2088
      */
2043
 
      assert(primary_keys_number_of);
2044
 
      if (primary_keys_number_of)
2045
 
      {
2046
 
        key_val= (unsigned int)(random() % primary_keys_number_of);
2047
 
        key= primary_keys[key_val];
2048
 
 
2049
 
        assert(key);
2050
 
 
2051
 
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2052
 
                         (int)ptr->length, ptr->string, key);
2053
 
 
2054
 
        if (run_query(&drizzle, buffer, length))
 
2089
      if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
2090
          (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
 
2091
      {
 
2092
        int length;
 
2093
        unsigned int key_val;
 
2094
        char *key;
 
2095
        char buffer[HUGE_STRING_LENGTH];
 
2096
 
 
2097
        /* 
 
2098
          This should only happen if some sort of new engine was
 
2099
          implemented that didn't properly handle UPDATEs.
 
2100
 
 
2101
          Just in case someone runs this under an experimental engine we don't
 
2102
          want a crash so the if() is placed here.
 
2103
        */
 
2104
        DBUG_ASSERT(primary_keys_number_of);
 
2105
        if (primary_keys_number_of)
 
2106
        {
 
2107
          key_val= (unsigned int)(random() % primary_keys_number_of);
 
2108
          key= primary_keys[key_val];
 
2109
 
 
2110
          DBUG_ASSERT(key);
 
2111
 
 
2112
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'", 
 
2113
                           (int)ptr->length, ptr->string, key);
 
2114
 
 
2115
          if (run_query(&mysql, buffer, length))
 
2116
          {
 
2117
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2118
                    my_progname, (uint)length, buffer, mysql_error(&mysql));
 
2119
            exit(1);
 
2120
          }
 
2121
        }
 
2122
      }
 
2123
      else
 
2124
      {
 
2125
        if (run_query(&mysql, ptr->string, ptr->length))
2055
2126
        {
2056
2127
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2057
 
                  my_progname, (uint)length, buffer, drizzle_error(&drizzle));
 
2128
                  my_progname, (uint)ptr->length, ptr->string, mysql_error(&mysql));
2058
2129
          exit(1);
2059
2130
        }
2060
2131
      }
2061
 
    }
2062
 
    else
2063
 
    {
2064
 
      if (run_query(&drizzle, ptr->string, ptr->length))
2065
 
      {
2066
 
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2067
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
2068
 
        exit(1);
2069
 
      }
2070
 
    }
2071
2132
 
2072
 
    if (!opt_only_print)
2073
 
    {
2074
 
      do
 
2133
      if (!opt_only_print)
2075
2134
      {
2076
 
        if (drizzle_field_count(&drizzle))
 
2135
        do
2077
2136
        {
2078
 
          result= drizzle_store_result(&drizzle);
2079
 
          while ((row = drizzle_fetch_row(result)))
2080
 
            counter++;
2081
 
          drizzle_free_result(result);
2082
 
        }
2083
 
      } while(drizzle_next_result(&drizzle) == 0);
2084
 
    }
2085
 
    queries++;
2086
 
 
2087
 
    if (commit_rate && (++commit_counter == commit_rate))
2088
 
    {
2089
 
      commit_counter= 0;
2090
 
      run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2091
 
    }
2092
 
 
2093
 
    /* If the timer is set, and the alarm is not active then end */
2094
 
    if (opt_timer_length && timer_alarm == false)
2095
 
      goto end;
2096
 
 
2097
 
    /* If limit has been reached, and we are not in a timer_alarm just end */
2098
 
    if (con->limit && queries == con->limit && timer_alarm == false)
2099
 
      goto end;
2100
 
  }
2101
 
 
2102
 
  if (opt_timer_length && timer_alarm == true)
2103
 
    goto limit_not_met;
2104
 
 
2105
 
  if (con->limit && queries < con->limit)
2106
 
    goto limit_not_met;
 
2137
          if (mysql_field_count(&mysql))
 
2138
          {
 
2139
            result= mysql_store_result(&mysql);
 
2140
            while ((row = mysql_fetch_row(result)))
 
2141
              counter++;
 
2142
            mysql_free_result(result);
 
2143
          }
 
2144
        } while(mysql_next_result(&mysql) == 0);
 
2145
      }
 
2146
      queries++;
 
2147
 
 
2148
      if (commit_rate && (++commit_counter == commit_rate))
 
2149
      {
 
2150
        commit_counter= 0;
 
2151
        run_query(&mysql, "COMMIT", strlen("COMMIT"));
 
2152
      }
 
2153
 
 
2154
      /* If the timer is set, and the alarm is not active then end */
 
2155
      if (opt_timer_length && timer_alarm == FALSE)
 
2156
        goto end;
 
2157
 
 
2158
      /* If limit has been reached, and we are not in a timer_alarm just end */
 
2159
      if (con->limit && queries == con->limit && timer_alarm == FALSE)
 
2160
        goto end;
 
2161
    }
 
2162
 
 
2163
    if (opt_timer_length && timer_alarm == TRUE)
 
2164
      goto limit_not_met;
 
2165
 
 
2166
    if (con->limit && queries < con->limit)
 
2167
      goto limit_not_met;
2107
2168
 
2108
2169
 
2109
2170
end:
2110
2171
  if (commit_rate)
2111
 
    run_query(&drizzle, "COMMIT", strlen("COMMIT"));
 
2172
    run_query(&mysql, "COMMIT", strlen("COMMIT"));
2112
2173
 
2113
 
  slap_close(&drizzle);
 
2174
  slap_close(&mysql);
2114
2175
 
2115
2176
  pthread_mutex_lock(&counter_mutex);
2116
2177
  thread_counter--;
2117
2178
  pthread_cond_signal(&count_threshhold);
2118
2179
  pthread_mutex_unlock(&counter_mutex);
2119
2180
 
2120
 
  free(con);
 
2181
  my_free(con, MYF(0));
2121
2182
 
2122
 
  return(0);
 
2183
  mysql_thread_end();
 
2184
  DBUG_RETURN(0);
2123
2185
}
2124
2186
 
2125
2187
/*
2149
2211
    char buffer[HUGE_STRING_LENGTH];
2150
2212
    char *buffer_ptr;
2151
2213
 
2152
 
    memset(buffer, 0, HUGE_STRING_LENGTH);
 
2214
    bzero(buffer, HUGE_STRING_LENGTH);
2153
2215
 
2154
 
    string= strchr(begin_ptr, delm);
 
2216
    string= strchr(begin_ptr, delm); 
2155
2217
 
2156
2218
    if (string)
2157
2219
    {
2210
2272
 
2211
2273
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2212
2274
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2213
 
       (retstr= strchr(ptr, delm));
 
2275
       (retstr= strchr(ptr, delm)); 
2214
2276
       tmp->next=  (statement *)my_malloc(sizeof(statement),
2215
2277
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2216
 
         tmp= tmp->next)
 
2278
       tmp= tmp->next)
2217
2279
  {
2218
2280
    count++;
2219
2281
    tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2225
2287
 
2226
2288
  if (ptr != script+length)
2227
2289
  {
2228
 
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2229
 
                            MYF(MY_FAE));
 
2290
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr), 
 
2291
                                       MYF(MY_FAE));
2230
2292
    tmp->length= (size_t)((script + length) - ptr);
2231
2293
    count++;
2232
2294
  }
2250
2312
 
2251
2313
  for (;*ptr; ptr++)
2252
2314
    if (*ptr == ',') count++;
2253
 
 
 
2315
  
2254
2316
  /* One extra spot for the NULL */
2255
 
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
 
2317
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1), 
2256
2318
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2257
2319
 
2258
2320
  ptr= (char *)string;
2272
2334
{
2273
2335
  printf("Benchmark\n");
2274
2336
  if (con->engine)
2275
 
    printf("\tRunning for engine %s\n", con->engine);
 
2337
      printf("\tRunning for engine %s\n", con->engine);
2276
2338
  if (opt_label || opt_auto_generate_sql_type)
2277
2339
  {
2278
2340
    const char *ptr= opt_auto_generate_sql_type ? opt_auto_generate_sql_type : "query";
2286
2348
         con->min_timing / 1000, con->min_timing % 1000);
2287
2349
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2288
2350
         con->max_timing / 1000, con->max_timing % 1000);
2289
 
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
 
2351
  printf("\tTotal time for tests: %ld.%03ld seconds\n", 
2290
2352
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2291
2353
  printf("\tStandard Deviation: %ld.%03ld\n", con->std_dev / 1000, con->std_dev % 1000);
2292
 
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->create_count);
2293
 
  printf("\tNumber of clients running queries: %u/%u\n",
 
2354
  printf("\tNumber of queries in create queries: %llu\n", con->create_count);
 
2355
  printf("\tNumber of clients running queries: %u/%u\n", 
2294
2356
         con->users, con->real_users);
2295
2357
  printf("\tNumber of times test was run: %u\n", iterations);
2296
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->avg_rows);
 
2358
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows); 
2297
2359
  printf("\n");
2298
2360
}
2299
2361
 
2305
2367
  char label_buffer[HUGE_STRING_LENGTH];
2306
2368
  size_t string_len;
2307
2369
 
2308
 
  memset(label_buffer, 0, HUGE_STRING_LENGTH);
 
2370
  bzero(label_buffer, HUGE_STRING_LENGTH);
2309
2371
 
2310
2372
  if (opt_label)
2311
2373
  {
2318
2380
      else
2319
2381
        label_buffer[x]= opt_label[x] ;
2320
2382
    }
2321
 
  }
 
2383
  } 
2322
2384
  else if (opt_auto_generate_sql_type)
2323
2385
  {
2324
2386
    string_len= strlen(opt_auto_generate_sql_type);
2334
2396
  else
2335
2397
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
2336
2398
 
2337
 
  snprintf(buffer, HUGE_STRING_LENGTH,
2338
 
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2339
 
           "%u,%u,%u,%"PRIu64"\n",
 
2399
  snprintf(buffer, HUGE_STRING_LENGTH, 
 
2400
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%u,%u,%u,%llu\n",
2340
2401
           con->engine ? con->engine : "", /* Storage engine we ran against */
2341
2402
           label_buffer, /* Load type */
2342
2403
           con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
2348
2409
           con->users, /* Children used max_timing */
2349
2410
           con->real_users, /* Children used max_timing */
2350
2411
           con->avg_rows  /* Queries run */
2351
 
           );
2352
 
  my_write(csv_file, (unsigned char*) buffer, (uint)strlen(buffer), MYF(0));
 
2412
          );
 
2413
  my_write(csv_file, (uchar*) buffer, (uint)strlen(buffer), MYF(0));
2353
2414
}
2354
2415
 
2355
2416
void
2358
2419
  stats *ptr;
2359
2420
  unsigned int x;
2360
2421
 
2361
 
  con->min_timing= sptr->timing;
 
2422
  con->min_timing= sptr->timing; 
2362
2423
  con->max_timing= sptr->timing;
2363
2424
  con->min_rows= sptr->rows;
2364
2425
  con->max_rows= sptr->rows;
2365
 
 
 
2426
  
2366
2427
  /* At the moment we assume uniform */
2367
2428
  con->users= sptr->users;
2368
2429
  con->real_users= sptr->real_users;
2369
2430
  con->avg_rows= sptr->rows;
2370
 
 
 
2431
  
2371
2432
  /* With no next, we know it is the last element that was malloced */
2372
2433
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2373
2434
  {
2389
2450
  standard_deviation(con, sptr);
2390
2451
 
2391
2452
  /* Now we do the create time operations */
2392
 
  con->create_min_timing= sptr->create_timing;
 
2453
  con->create_min_timing= sptr->create_timing; 
2393
2454
  con->create_max_timing= sptr->create_timing;
2394
 
 
 
2455
  
2395
2456
  /* At the moment we assume uniform */
2396
2457
  con->create_count= sptr->create_count;
2397
 
 
 
2458
  
2398
2459
  /* With no next, we know it is the last element that was malloced */
2399
2460
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2400
2461
  {
2419
2480
  {
2420
2481
    nptr= ptr->next;
2421
2482
    if (ptr->string)
2422
 
      free(ptr->string);
 
2483
      my_free(ptr->string, MYF(0)); 
2423
2484
    if (ptr->option)
2424
 
      free(ptr->option);
2425
 
    free(ptr);
 
2485
      my_free(ptr->option, MYF(0)); 
 
2486
    my_free(ptr, MYF(0));
2426
2487
  }
2427
2488
}
2428
2489
 
2437
2498
  {
2438
2499
    nptr= ptr->next;
2439
2500
    if (ptr->string)
2440
 
      free(ptr->string);
2441
 
    free(ptr);
 
2501
      my_free(ptr->string, MYF(0)); 
 
2502
    my_free(ptr, MYF(0));
2442
2503
  }
2443
2504
}
2444
2505
 
2445
 
void
2446
 
slap_close(DRIZZLE *drizzle)
 
2506
void 
 
2507
slap_close(MYSQL *mysql)
2447
2508
{
2448
 
  if (opt_only_print)
 
2509
  if (opt_only_print) 
2449
2510
    return;
2450
2511
 
2451
 
  drizzle_close(drizzle);
 
2512
  mysql_close(mysql);
2452
2513
}
2453
2514
 
2454
 
void
2455
 
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
 
2515
void 
 
2516
slap_connect(MYSQL *mysql, my_bool connect_to_schema)
2456
2517
{
2457
2518
  /* Connect to server */
2458
 
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
 
2519
  static ulong connection_retry_sleep= 100000; /* Microseconds */
2459
2520
  int x, connect_error= 1;
2460
2521
 
2461
 
  if (opt_only_print)
 
2522
  if (opt_only_print) 
2462
2523
    return;
2463
2524
 
2464
2525
  if (opt_delayed_start)
2465
2526
    my_sleep(random()%opt_delayed_start);
2466
2527
 
2467
 
  drizzle_create(drizzle);
 
2528
  mysql_init(mysql);
2468
2529
 
2469
2530
  if (opt_compress)
2470
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
2531
    mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
 
2532
  /* We always do opt_protocol to TCP/IP */
 
2533
  mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
2534
  mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
2471
2535
 
2472
2536
  for (x= 0; x < 10; x++)
2473
2537
  {
2474
2538
 
2475
2539
 
2476
 
    if (drizzle_connect(drizzle, host, user, opt_password,
2477
 
                        connect_to_schema ? create_schema_string : NULL,
2478
 
                        opt_drizzle_port,
2479
 
                        opt_drizzle_unix_port,
2480
 
                        connect_flags))
 
2540
    if (mysql_real_connect(mysql, host, user, opt_password,
 
2541
                           connect_to_schema ? create_schema_string : NULL,
 
2542
                           opt_mysql_port,
 
2543
                           opt_mysql_unix_port,
 
2544
                           connect_flags))
2481
2545
    {
2482
2546
      /* Connect suceeded */
2483
2547
      connect_error= 0;
2488
2552
  if (connect_error)
2489
2553
  {
2490
2554
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2491
 
            my_progname, drizzle_errno(drizzle), drizzle_error(drizzle));
 
2555
            my_progname, mysql_errno(mysql), mysql_error(mysql));
2492
2556
    exit(1);
2493
2557
  }
2494
2558
 
2495
2559
  return;
2496
2560
}
2497
2561
 
2498
 
void
 
2562
void 
2499
2563
standard_deviation (conclusions *con, stats *sptr)
2500
2564
{
2501
2565
  unsigned int x;
2502
2566
  long int sum_of_squares;
2503
 
  double the_catch;
 
2567
  double catch;
2504
2568
  stats *ptr;
2505
2569
 
2506
2570
  if (iterations == 1 || iterations == 0)
2517
2581
    sum_of_squares+= deviation*deviation;
2518
2582
  }
2519
2583
 
2520
 
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2521
 
  con->std_dev= (long int)the_catch;
 
2584
  catch= sqrt((double)(sum_of_squares/(iterations -1)));
 
2585
  con->std_dev= (long int)catch;
2522
2586
}