~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

  • Committer: Jay Pipes
  • Date: 2008-07-21 17:52:33 UTC
  • mto: (201.2.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: jay@mysql.com-20080721175233-mtyz298j8xl3v63y
cleanup of FAQ file

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
 
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
122
static bool opt_preserve= true;
125
123
static bool debug_info_flag= 0, debug_check_flag= 0;
127
125
static bool opt_burnin= false;
128
126
static bool opt_ignore_sql_errors= false;
129
127
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;
 
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;
 
160
static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
162
161
static uint64_t actual_queries= 0;
163
162
static uint64_t auto_actual_queries;
164
163
static uint64_t auto_generate_sql_unique_write_number;
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;
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
277
static statement * build_select_string(bool key);
277
 
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
 
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
static int run_scheduler(stats *sptr, statement **stmts, uint concur, 
282
283
                         uint64_t 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, 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;
451
455
      data in the table.
452
456
    */
453
457
    if (opt_preserve == false)
454
 
      drop_schema(drizzle, create_schema_string);
 
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
    (char**) &auto_generate_selected_columns_opt, 
 
521
    (char**) &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
    (char**) &auto_generate_sql, (char**) &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
    (char**) &auto_generate_sql_autoincrement, 
 
530
    (char**) &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
    (char**) &auto_actual_queries, (char**) &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
    (char**) &auto_generate_sql_guid_primary, 
 
539
    (char**) &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
    (char**) &opt_auto_generate_sql_type, (char**) &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
    (char**) &auto_generate_sql_secondary_indexes, 
 
549
    (char**) &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
    (char**) &auto_generate_sql_unique_query_number, 
 
555
    (char**) &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
    (char**) &auto_generate_sql_unique_write_number, 
 
561
    (char**) &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
    (char**) &auto_generate_sql_number, (char**) &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
    (char**) &opt_burnin, (char**) &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
    (char**) &opt_ignore_sql_errors, 
 
573
    (char**) &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
    (char**) &commit_rate, (char**) &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
    (char**) &opt_compress, (char**) &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
    (char**) &concurrency_str, (char**) &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
    (char**) &create_string, (char**) &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
    (char**) &create_schema_string, (char**) &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
    (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR, 
 
594
    OPT_ARG, 0, 0, 0, 0, 0, 0},
591
595
  {"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},
 
596
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
597
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
594
598
  {"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},
 
599
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
600
  {"delayed-start", OPT_SLAP_DELAYED_START, 
 
601
    "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
 
602
    (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT, 
 
603
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
600
604
  {"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},
 
605
    "Delimiter to use in SQL statements supplied in file or command line.",
 
606
    (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
 
607
    0, 0, 0, 0, 0, 0},
604
608
  {"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},
 
609
    "Detach (close and reopen) connections after X number of requests.",
 
610
    (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG, 
 
611
    0, 0, 0, 0, 0, 0},
608
612
  {"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},
 
613
    (char**) &default_engine, (char**) &default_engine, 0,
 
614
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
611
615
  {"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
612
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
616
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
613
617
  {"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},
 
618
    (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
615
619
  {"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},
 
620
    (char**) &opt_label, (char**) &opt_label, 0,
 
621
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
622
  {"number-blob-cols", OPT_SLAP_BLOB_COL, 
 
623
    "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
 
624
    (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
625
    0, 0, 0, 0, 0, 0},
 
626
  {"number-char-cols", 'x', 
 
627
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
 
628
    (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
629
    0, 0, 0, 0, 0, 0},
 
630
  {"number-int-cols", 'y', 
 
631
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
 
632
    (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG, 
 
633
    0, 0, 0, 0, 0, 0},
 
634
  {"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY, 
 
635
    "Limit each client to this number of queries (this is not exact).",
 
636
    (char**) &num_of_query, (char**) &num_of_query, 0,
 
637
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
638
  {"only-print", OPT_MYSQL_ONLY_PRINT,
 
639
    "This causes mysqlslap to not connect to the databases, but instead print "
 
640
      "out what it would have done instead.",
 
641
    (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
 
642
    0, 0, 0, 0, 0, 0},
639
643
  {"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},
 
644
    "Password to use when connecting to server. If password is not given it's "
 
645
      "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
646
  {"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
 
647
    (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
 
648
    0},
645
649
  {"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},
 
650
    "Query to run or file containing query to execute after tests have completed.",
 
651
    (char**) &user_supplied_post_statements, 
 
652
    (char**) &user_supplied_post_statements,
 
653
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
650
654
  {"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},
 
655
    "system() string to execute after tests have completed.",
 
656
    (char**) &post_system, 
 
657
    (char**) &post_system,
 
658
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
659
  {"pre-query", OPT_SLAP_PRE_QUERY, 
 
660
    "Query to run or file containing query to execute before running tests.",
 
661
    (char**) &user_supplied_pre_statements, 
 
662
    (char**) &user_supplied_pre_statements,
 
663
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
664
  {"pre-system", OPT_SLAP_PRE_SYSTEM, 
 
665
    "system() string to execute before running tests.",
 
666
    (char**) &pre_system, 
 
667
    (char**) &pre_system,
 
668
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
669
  {"protocol", OPT_MYSQL_PROTOCOL,
 
670
    "The protocol of connection (tcp,socket,pipe,memory).",
 
671
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
668
672
  {"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},
 
673
    (char**) &user_supplied_query, (char**) &user_supplied_query,
 
674
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
675
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED, 
 
676
    "Seed for random number generator (srandom(3))",
 
677
    (char**)&opt_set_random_seed,
 
678
    (char**)&opt_set_random_seed,0,
 
679
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
676
680
  {"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},
 
681
    (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
 
682
    0, 0, 0, 0, 0, 0},
679
683
  {"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},
 
684
    (char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR,
 
685
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
686
  {"timer-length", OPT_SLAP_TIMER_LENGTH, 
 
687
    "Require mysqlslap to run each specific test a certain amount of time in seconds.", 
 
688
    (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT, 
 
689
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
686
690
#ifndef DONT_ALLOW_USER_CHANGE
687
691
  {"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},
 
692
    (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
689
693
#endif
690
694
  {"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},
 
695
    "More verbose output; you can use this multiple times to get even more "
 
696
      "verbose output.", (char**) &verbose, (char**) &verbose, 0, 
 
697
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
694
698
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
695
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
699
    NO_ARG, 0, 0, 0, 0, 0, 0},
696
700
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
697
701
};
698
702
 
699
703
 
 
704
#include <help_start.h>
 
705
 
700
706
static void print_version(void)
701
707
{
702
708
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
703
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
709
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
704
710
}
705
711
 
706
712
 
707
713
static void usage(void)
708
714
{
709
715
  print_version();
710
 
  puts("Copyright (C) 2005 DRIZZLE AB");
 
716
  puts("Copyright (C) 2005 MySQL AB");
711
717
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
712
718
       \nand you are welcome to modify and redistribute it under the GPL \
713
719
       license\n");
717
723
  my_print_help(my_long_options);
718
724
}
719
725
 
 
726
#include <help_end.h>
 
727
 
720
728
static bool
721
729
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
722
730
               char *argument)
730
738
    if (argument)
731
739
    {
732
740
      char *start= argument;
733
 
      free(opt_password);
 
741
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
734
742
      opt_password= my_strdup(argument,MYF(MY_FAE));
735
 
      while (*argument) *argument++= 'x';    /* Destroy argument */
 
743
      while (*argument) *argument++= 'x';               /* Destroy argument */
736
744
      if (*start)
737
 
        start[1]= 0;        /* Cut length of argument */
 
745
        start[1]= 0;                            /* Cut length of argument */
738
746
      tty_password= 0;
739
747
    }
740
748
    else
745
753
    exit(0);
746
754
    break;
747
755
  case '?':
748
 
  case 'I':          /* Info */
 
756
  case 'I':                                     /* Info */
749
757
    usage();
750
758
    exit(0);
751
759
  }
777
785
  char       buf[HUGE_STRING_LENGTH];
778
786
  unsigned int        col_count;
779
787
  statement *ptr;
780
 
  string table_string;
781
 
 
782
 
  table_string.reserve(HUGE_STRING_LENGTH);
783
 
 
784
 
  table_string= "CREATE TABLE `t1` (";
 
788
  DYNAMIC_STRING table_string;
 
789
 
 
790
  init_dynamic_string(&table_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
791
 
 
792
  dynstr_append(&table_string, "CREATE TABLE `t1` (");
785
793
 
786
794
  if (auto_generate_sql_autoincrement)
787
795
  {
788
 
    table_string.append("id serial");
 
796
    dynstr_append(&table_string, "id serial");
789
797
 
790
798
    if (num_int_cols || num_char_cols)
791
 
      table_string.append(",");
 
799
      dynstr_append(&table_string, ",");
792
800
  }
793
801
 
794
802
  if (auto_generate_sql_guid_primary)
795
803
  {
796
 
    table_string.append("id varchar(128) primary key");
 
804
    dynstr_append(&table_string, "id varchar(128) primary key");
797
805
 
798
806
    if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
799
 
      table_string.append(",");
 
807
      dynstr_append(&table_string, ",");
800
808
  }
801
809
 
802
810
  if (auto_generate_sql_secondary_indexes)
806
814
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
807
815
    {
808
816
      if (count) /* Except for the first pass we add a comma */
809
 
        table_string.append(",");
 
817
        dynstr_append(&table_string, ",");
810
818
 
811
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
 
819
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count) 
812
820
          > HUGE_STRING_LENGTH)
813
821
      {
814
822
        fprintf(stderr, "Memory Allocation error in create table\n");
815
823
        exit(1);
816
824
      }
817
 
      table_string.append(buf);
 
825
      dynstr_append(&table_string, buf);
818
826
    }
819
827
 
820
828
    if (num_int_cols || num_char_cols)
821
 
      table_string.append(",");
 
829
      dynstr_append(&table_string, ",");
822
830
  }
823
831
 
824
832
  if (num_int_cols)
826
834
    {
827
835
      if (num_int_cols_index)
828
836
      {
829
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT, INDEX(intcol%d)",
 
837
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32), INDEX(intcol%d)", 
830
838
                     col_count, col_count) > HUGE_STRING_LENGTH)
831
839
        {
832
840
          fprintf(stderr, "Memory Allocation error in create table\n");
835
843
      }
836
844
      else
837
845
      {
838
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT ", col_count)
 
846
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32) ", col_count) 
839
847
            > HUGE_STRING_LENGTH)
840
848
        {
841
849
          fprintf(stderr, "Memory Allocation error in create table\n");
842
850
          exit(1);
843
851
        }
844
852
      }
845
 
      table_string.append(buf);
 
853
      dynstr_append(&table_string, buf);
846
854
 
847
855
      if (col_count < num_int_cols || num_char_cols > 0)
848
 
        table_string.append(",");
 
856
        dynstr_append(&table_string, ",");
849
857
    }
850
858
 
851
859
  if (num_char_cols)
853
861
    {
854
862
      if (num_char_cols_index)
855
863
      {
856
 
        if (snprintf(buf, HUGE_STRING_LENGTH,
857
 
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ",
 
864
        if (snprintf(buf, HUGE_STRING_LENGTH, 
 
865
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ", 
858
866
                     col_count, col_count) > HUGE_STRING_LENGTH)
859
867
        {
860
868
          fprintf(stderr, "Memory Allocation error in creating table\n");
863
871
      }
864
872
      else
865
873
      {
866
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)",
 
874
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)", 
867
875
                     col_count) > HUGE_STRING_LENGTH)
868
876
        {
869
877
          fprintf(stderr, "Memory Allocation error in creating table\n");
870
878
          exit(1);
871
879
        }
872
880
      }
873
 
      table_string.append(buf);
 
881
      dynstr_append(&table_string, buf);
874
882
 
875
883
      if (col_count < num_char_cols || num_blob_cols > 0)
876
 
        table_string.append(",");
 
884
        dynstr_append(&table_string, ",");
877
885
    }
878
886
 
879
887
  if (num_blob_cols)
880
888
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
881
889
    {
882
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob",
 
890
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob", 
883
891
                   col_count) > HUGE_STRING_LENGTH)
884
892
      {
885
893
        fprintf(stderr, "Memory Allocation error in creating table\n");
886
894
        exit(1);
887
895
      }
888
 
      table_string.append(buf);
 
896
      dynstr_append(&table_string, buf);
889
897
 
890
898
      if (col_count < num_blob_cols)
891
 
        table_string.append(",");
 
899
        dynstr_append(&table_string, ",");
892
900
    }
893
901
 
894
 
  table_string.append(")");
895
 
  ptr= (statement *)my_malloc(sizeof(statement),
 
902
  dynstr_append(&table_string, ")");
 
903
  ptr= (statement *)my_malloc(sizeof(statement), 
896
904
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
897
 
  ptr->string = (char *)my_malloc(table_string.length()+1,
 
905
  ptr->string = (char *)my_malloc(table_string.length+1,
898
906
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
899
 
  ptr->length= table_string.length()+1;
 
907
  ptr->length= table_string.length+1;
900
908
  ptr->type= CREATE_TABLE_TYPE;
901
 
  my_stpcpy(ptr->string, table_string.c_str());
 
909
  strmov(ptr->string, table_string.str);
 
910
  dynstr_free(&table_string);
902
911
  return(ptr);
903
912
}
904
913
 
914
923
  char       buf[HUGE_STRING_LENGTH];
915
924
  unsigned int        col_count;
916
925
  statement *ptr;
917
 
  string update_string;
918
 
 
919
 
  update_string.reserve(HUGE_STRING_LENGTH);
920
 
 
921
 
  update_string= "UPDATE t1 SET ";
 
926
  DYNAMIC_STRING update_string;
 
927
 
 
928
 
 
929
  init_dynamic_string(&update_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
930
 
 
931
  dynstr_append(&update_string, "UPDATE t1 SET ");
922
932
 
923
933
  if (num_int_cols)
924
934
    for (col_count= 1; col_count <= num_int_cols; col_count++)
925
935
    {
926
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count,
 
936
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count, 
927
937
                   random()) > HUGE_STRING_LENGTH)
928
938
      {
929
939
        fprintf(stderr, "Memory Allocation error in creating update\n");
930
940
        exit(1);
931
941
      }
932
 
      update_string.append(buf);
 
942
      dynstr_append(&update_string, buf);
933
943
 
934
944
      if (col_count < num_int_cols || num_char_cols > 0)
935
 
        update_string.append(",", 1);
 
945
        dynstr_append_mem(&update_string, ",", 1);
936
946
    }
937
947
 
938
948
  if (num_char_cols)
941
951
      char rand_buffer[RAND_STRING_SIZE];
942
952
      int buf_len= get_random_string(rand_buffer, RAND_STRING_SIZE);
943
953
 
944
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count,
945
 
                   buf_len, rand_buffer)
 
954
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count, 
 
955
                   buf_len, rand_buffer) 
946
956
          > HUGE_STRING_LENGTH)
947
957
      {
948
958
        fprintf(stderr, "Memory Allocation error in creating update\n");
949
959
        exit(1);
950
960
      }
951
 
      update_string.append(buf);
 
961
      dynstr_append(&update_string, buf);
952
962
 
953
963
      if (col_count < num_char_cols)
954
 
        update_string.append(",", 1);
 
964
        dynstr_append_mem(&update_string, ",", 1);
955
965
    }
956
966
 
957
967
  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),
 
968
    dynstr_append(&update_string, " WHERE id = ");
 
969
 
 
970
 
 
971
  ptr= (statement *)my_malloc(sizeof(statement), 
962
972
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
963
973
 
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;
 
974
  ptr->string= (char *)my_malloc(update_string.length + 1,
 
975
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
976
  ptr->length= update_string.length+1;
967
977
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
968
978
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
969
979
  else
970
980
    ptr->type= UPDATE_TYPE;
971
 
  my_stpcpy(ptr->string, update_string.c_str());
 
981
  strmov(ptr->string, update_string.str);
 
982
  dynstr_free(&update_string);
972
983
  return(ptr);
973
984
}
974
985
 
985
996
  char       buf[HUGE_STRING_LENGTH];
986
997
  unsigned int        col_count;
987
998
  statement *ptr;
988
 
  string insert_string;
989
 
 
990
 
  insert_string.reserve(HUGE_STRING_LENGTH);
991
 
 
992
 
  insert_string= "INSERT INTO t1 VALUES (";
 
999
  DYNAMIC_STRING insert_string;
 
1000
 
 
1001
 
 
1002
  init_dynamic_string(&insert_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
1003
 
 
1004
  dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
993
1005
 
994
1006
  if (auto_generate_sql_autoincrement)
995
1007
  {
996
 
    insert_string.append("NULL");
 
1008
    dynstr_append(&insert_string, "NULL");
997
1009
 
998
1010
    if (num_int_cols || num_char_cols)
999
 
      insert_string.append(",");
 
1011
      dynstr_append(&insert_string, ",");
1000
1012
  }
1001
1013
 
1002
1014
  if (auto_generate_sql_guid_primary)
1003
1015
  {
1004
 
    insert_string.append("uuid()");
 
1016
    dynstr_append(&insert_string, "uuid()");
1005
1017
 
1006
1018
    if (num_int_cols || num_char_cols)
1007
 
      insert_string.append(",");
 
1019
      dynstr_append(&insert_string, ",");
1008
1020
  }
1009
1021
 
1010
1022
  if (auto_generate_sql_secondary_indexes)
1014
1026
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1015
1027
    {
1016
1028
      if (count) /* Except for the first pass we add a comma */
1017
 
        insert_string.append(",");
 
1029
        dynstr_append(&insert_string, ",");
1018
1030
 
1019
 
      insert_string.append("uuid()");
 
1031
      dynstr_append(&insert_string, "uuid()");
1020
1032
    }
1021
1033
 
1022
1034
    if (num_int_cols || num_char_cols)
1023
 
      insert_string.append(",");
 
1035
      dynstr_append(&insert_string, ",");
1024
1036
  }
1025
1037
 
1026
1038
  if (num_int_cols)
1031
1043
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1032
1044
        exit(1);
1033
1045
      }
1034
 
      insert_string.append(buf);
 
1046
      dynstr_append(&insert_string, buf);
1035
1047
 
1036
1048
      if (col_count < num_int_cols || num_char_cols > 0)
1037
 
        insert_string.append(",");
 
1049
        dynstr_append_mem(&insert_string, ",", 1);
1038
1050
    }
1039
1051
 
1040
1052
  if (num_char_cols)
1041
1053
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1042
1054
    {
1043
1055
      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);
 
1056
      dynstr_append_mem(&insert_string, "'", 1);
 
1057
      dynstr_append_mem(&insert_string, buf, buf_len);
 
1058
      dynstr_append_mem(&insert_string, "'", 1);
1047
1059
 
1048
1060
      if (col_count < num_char_cols || num_blob_cols > 0)
1049
 
        insert_string.append(",", 1);
 
1061
        dynstr_append_mem(&insert_string, ",", 1);
1050
1062
    }
1051
1063
 
1052
1064
  if (num_blob_cols)
1056
1068
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1057
1069
    {
1058
1070
      blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
1059
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1071
                             MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1060
1072
      if (!blob_ptr)
1061
1073
      {
1062
1074
        fprintf(stderr, "Memory Allocation error in creating select\n");
1074
1086
      unsigned int size;
1075
1087
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1076
1088
 
1077
 
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1078
 
        num_blob_cols_size;
 
1089
      size= difference ? (num_blob_cols_size_min + (random() % difference)) : 
 
1090
                          num_blob_cols_size;
1079
1091
 
1080
1092
      buf_len= get_random_string(blob_ptr, size);
1081
1093
 
1082
 
      insert_string.append("'", 1);
1083
 
      insert_string.append(blob_ptr, buf_len);
1084
 
      insert_string.append("'", 1);
 
1094
      dynstr_append_mem(&insert_string, "'", 1);
 
1095
      dynstr_append_mem(&insert_string, blob_ptr, buf_len);
 
1096
      dynstr_append_mem(&insert_string, "'", 1);
1085
1097
 
1086
1098
      if (col_count < num_blob_cols)
1087
 
        insert_string.append(",", 1);
 
1099
        dynstr_append_mem(&insert_string, ",", 1);
1088
1100
    }
1089
1101
 
1090
1102
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1091
 
      free(blob_ptr);
 
1103
      my_free(blob_ptr, MYF(0));
1092
1104
  }
1093
1105
 
1094
 
  insert_string.append(")", 1);
 
1106
  dynstr_append_mem(&insert_string, ")", 1);
1095
1107
 
1096
1108
  if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1097
1109
  {
1098
1110
    fprintf(stderr, "Memory Allocation error in creating select\n");
1099
1111
    exit(1);
1100
1112
  }
1101
 
  if (!(ptr->string= (char *)my_malloc(insert_string.length() + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
 
1113
  if (!(ptr->string= (char *)my_malloc(insert_string.length + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1102
1114
  {
1103
1115
    fprintf(stderr, "Memory Allocation error in creating select\n");
1104
1116
    exit(1);
1105
1117
  }
1106
 
  ptr->length= insert_string.length()+1;
 
1118
  ptr->length= insert_string.length+1;
1107
1119
  ptr->type= INSERT_TYPE;
1108
 
  my_stpcpy(ptr->string, insert_string.c_str());
 
1120
  strmov(ptr->string, insert_string.str);
 
1121
  dynstr_free(&insert_string);
 
1122
 
1109
1123
  return(ptr);
1110
1124
}
1111
1125
 
1122
1136
  char       buf[HUGE_STRING_LENGTH];
1123
1137
  unsigned int        col_count;
1124
1138
  statement *ptr;
1125
 
  string query_string;
1126
 
 
1127
 
  query_string.reserve(HUGE_STRING_LENGTH);
1128
 
 
1129
 
  query_string.append("SELECT ", 7);
 
1139
  static DYNAMIC_STRING query_string;
 
1140
 
 
1141
 
 
1142
  init_dynamic_string(&query_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
1143
 
 
1144
  dynstr_append_mem(&query_string, "SELECT ", 7);
1130
1145
  if (auto_generate_selected_columns_opt)
1131
1146
  {
1132
 
    query_string.append(auto_generate_selected_columns_opt);
 
1147
    dynstr_append(&query_string, auto_generate_selected_columns_opt);
1133
1148
  }
1134
1149
  else
1135
1150
  {
1136
1151
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1137
1152
    {
1138
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count)
 
1153
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count) 
1139
1154
          > HUGE_STRING_LENGTH)
1140
1155
      {
1141
1156
        fprintf(stderr, "Memory Allocation error in creating select\n");
1142
1157
        exit(1);
1143
1158
      }
1144
 
      query_string.append(buf);
 
1159
      dynstr_append(&query_string, buf);
1145
1160
 
1146
1161
      if (col_count < num_int_cols || num_char_cols > 0)
1147
 
        query_string.append(",", 1);
 
1162
        dynstr_append_mem(&query_string, ",", 1);
1148
1163
 
1149
1164
    }
1150
1165
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1155
1170
        fprintf(stderr, "Memory Allocation error in creating select\n");
1156
1171
        exit(1);
1157
1172
      }
1158
 
      query_string.append(buf);
 
1173
      dynstr_append(&query_string, buf);
1159
1174
 
1160
1175
      if (col_count < num_char_cols || num_blob_cols > 0)
1161
 
        query_string.append(",", 1);
 
1176
        dynstr_append_mem(&query_string, ",", 1);
1162
1177
 
1163
1178
    }
1164
1179
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1169
1184
        fprintf(stderr, "Memory Allocation error in creating select\n");
1170
1185
        exit(1);
1171
1186
      }
1172
 
      query_string.append(buf);
 
1187
      dynstr_append(&query_string, buf);
1173
1188
 
1174
1189
      if (col_count < num_blob_cols)
1175
 
        query_string.append(",", 1);
 
1190
        dynstr_append_mem(&query_string, ",", 1);
1176
1191
    }
1177
1192
  }
1178
 
  query_string.append(" FROM t1");
 
1193
  dynstr_append(&query_string, " FROM t1");
1179
1194
 
1180
 
  if ((key) &&
 
1195
  if ((key) && 
1181
1196
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1182
 
    query_string.append(" WHERE id = ");
 
1197
    dynstr_append(&query_string, " WHERE id = ");
1183
1198
 
1184
1199
  ptr= (statement *)my_malloc(sizeof(statement),
1185
1200
                              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) &&
 
1201
  ptr->string= (char *)my_malloc(query_string.length + 1,
 
1202
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1203
  ptr->length= query_string.length+1;
 
1204
  if ((key) && 
1190
1205
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1191
1206
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1192
1207
  else
1193
1208
    ptr->type= SELECT_TYPE;
1194
 
  my_stpcpy(ptr->string, query_string.c_str());
 
1209
  strmov(ptr->string, query_string.str);
 
1210
  dynstr_free(&query_string);
1195
1211
  return(ptr);
1196
1212
}
1197
1213
 
1221
1237
 
1222
1238
  if (auto_generate_sql && (create_string || user_supplied_query))
1223
1239
  {
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);
 
1240
      fprintf(stderr,
 
1241
              "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
 
1242
              my_progname);
 
1243
      exit(1);
1228
1244
  }
1229
1245
 
1230
 
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
 
1246
  if (auto_generate_sql && auto_generate_sql_guid_primary && 
1231
1247
      auto_generate_sql_autoincrement)
1232
1248
  {
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);
 
1249
      fprintf(stderr,
 
1250
              "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
 
1251
              my_progname);
 
1252
      exit(1);
1237
1253
  }
1238
1254
 
1239
1255
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1240
1256
  {
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);
 
1257
      fprintf(stderr,
 
1258
              "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
 
1259
              my_progname);
 
1260
      exit(1);
1245
1261
  }
1246
1262
 
1247
1263
  parse_comma(concurrency_str ? concurrency_str : "1", &concurrency);
1249
1265
  if (opt_csv_str)
1250
1266
  {
1251
1267
    opt_silent= true;
1252
 
 
 
1268
    
1253
1269
    if (opt_csv_str[0] == '-')
1254
1270
    {
1255
1271
      csv_file= fileno(stdout);
1321
1337
 
1322
1338
  if (auto_generate_sql)
1323
1339
  {
1324
 
    uint64_t x= 0;
 
1340
    unsigned long long x= 0;
1325
1341
    statement *ptr_statement;
1326
1342
 
1327
1343
    if (verbose >= 2)
1328
1344
      printf("Building Create Statements for Auto\n");
1329
1345
 
1330
1346
    create_statements= build_table_string();
1331
 
    /*
1332
 
      Pre-populate table
 
1347
    /* 
 
1348
      Pre-populate table 
1333
1349
    */
1334
 
    for (ptr_statement= create_statements, x= 0;
1335
 
         x < auto_generate_sql_unique_write_number;
 
1350
    for (ptr_statement= create_statements, x= 0; 
 
1351
         x < auto_generate_sql_unique_write_number; 
1336
1352
         x++, ptr_statement= ptr_statement->next)
1337
1353
    {
1338
1354
      ptr_statement->next= build_insert_string();
1344
1360
    if (!opt_auto_generate_sql_type)
1345
1361
      opt_auto_generate_sql_type= "mixed";
1346
1362
 
1347
 
    query_statements_count=
 
1363
    query_statements_count= 
1348
1364
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1349
1365
 
1350
1366
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1359
1375
          printf("Generating SELECT Statements for Auto\n");
1360
1376
 
1361
1377
        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;
 
1378
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1379
             x < auto_generate_sql_unique_query_number; 
1364
1380
             x++, ptr_statement= ptr_statement->next)
1365
1381
        {
1366
1382
          ptr_statement->next= build_select_string(false);
1381
1397
        }
1382
1398
 
1383
1399
        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;
 
1400
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1401
             x < auto_generate_sql_unique_query_number; 
1386
1402
             x++, ptr_statement= ptr_statement->next)
1387
1403
        {
1388
1404
          ptr_statement->next= build_select_string(true);
1391
1407
      else if (sql_type->string[0] == 'w')
1392
1408
      {
1393
1409
        /*
1394
 
          We generate a number of strings in case the engine is
 
1410
          We generate a number of strings in case the engine is 
1395
1411
          Archive (since strings which were identical one after another
1396
1412
          would be too easily optimized).
1397
1413
        */
1398
1414
        if (verbose >= 2)
1399
1415
          printf("Generating INSERT Statements for Auto\n");
1400
1416
        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;
 
1417
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1418
             x < auto_generate_sql_unique_query_number; 
1403
1419
             x++, ptr_statement= ptr_statement->next)
1404
1420
        {
1405
1421
          ptr_statement->next= build_insert_string();
1417
1433
        }
1418
1434
 
1419
1435
        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;
 
1436
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1437
             x < auto_generate_sql_unique_query_number; 
1422
1438
             x++, ptr_statement= ptr_statement->next)
1423
1439
        {
1424
1440
          ptr_statement->next= build_update_string();
1429
1445
        int coin= 0;
1430
1446
 
1431
1447
        query_statements[sql_type_count]= build_insert_string();
1432
 
        /*
 
1448
        /* 
1433
1449
          This logic should be extended to do a more mixed load,
1434
1450
          at the moment it results in "every other".
1435
1451
        */
1436
 
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1437
 
             x < auto_generate_sql_unique_query_number;
 
1452
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
 
1453
             x < auto_generate_sql_unique_query_number; 
1438
1454
             x++, ptr_statement= ptr_statement->next)
1439
1455
        {
1440
1456
          if (coin)
1457
1473
    if (create_string && !stat(create_string, &sbuf))
1458
1474
    {
1459
1475
      File data_file;
1460
 
      if (!S_ISREG(sbuf.st_mode))
 
1476
      if (!MY_S_ISREG(sbuf.st_mode))
1461
1477
      {
1462
1478
        fprintf(stderr,"%s: Create file was not a regular file\n",
1463
1479
                my_progname);
1469
1485
        exit(1);
1470
1486
      }
1471
1487
      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));
 
1488
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1489
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1474
1490
      tmp_string[sbuf.st_size]= '\0';
1475
1491
      my_close(data_file,MYF(0));
1476
1492
      parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1477
 
      free(tmp_string);
 
1493
      my_free(tmp_string, MYF(0));
1478
1494
    }
1479
1495
    else if (create_string)
1480
1496
    {
1481
 
      parse_delimiter(create_string, &create_statements, delimiter[0]);
 
1497
        parse_delimiter(create_string, &create_statements, delimiter[0]);
1482
1498
    }
1483
1499
 
1484
1500
    /* Set this up till we fully support options on user generated queries */
1485
1501
    if (user_supplied_query)
1486
1502
    {
1487
 
      query_statements_count=
 
1503
      query_statements_count= 
1488
1504
        parse_option("default", &query_options, ',');
1489
1505
 
1490
1506
      query_statements= (statement **)my_malloc(sizeof(statement *),
1494
1510
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1495
1511
    {
1496
1512
      File data_file;
1497
 
      if (!S_ISREG(sbuf.st_mode))
 
1513
      if (!MY_S_ISREG(sbuf.st_mode))
1498
1514
      {
1499
1515
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1500
1516
                my_progname);
1507
1523
      }
1508
1524
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1509
1525
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1510
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1526
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1511
1527
      tmp_string[sbuf.st_size]= '\0';
1512
1528
      my_close(data_file,MYF(0));
1513
1529
      if (user_supplied_query)
1514
1530
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1515
1531
                                        delimiter[0]);
1516
 
      free(tmp_string);
1517
 
    }
 
1532
      my_free(tmp_string, MYF(0));
 
1533
    } 
1518
1534
    else if (user_supplied_query)
1519
1535
    {
1520
1536
      actual_queries= parse_delimiter(user_supplied_query, &query_statements[0],
1526
1542
      && !stat(user_supplied_pre_statements, &sbuf))
1527
1543
  {
1528
1544
    File data_file;
1529
 
    if (!S_ISREG(sbuf.st_mode))
 
1545
    if (!MY_S_ISREG(sbuf.st_mode))
1530
1546
    {
1531
1547
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1532
1548
              my_progname);
1539
1555
    }
1540
1556
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1541
1557
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1542
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1558
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1543
1559
    tmp_string[sbuf.st_size]= '\0';
1544
1560
    my_close(data_file,MYF(0));
1545
1561
    if (user_supplied_pre_statements)
1546
1562
      (void)parse_delimiter(tmp_string, &pre_statements,
1547
1563
                            delimiter[0]);
1548
 
    free(tmp_string);
1549
 
  }
 
1564
    my_free(tmp_string, MYF(0));
 
1565
  } 
1550
1566
  else if (user_supplied_pre_statements)
1551
1567
  {
1552
1568
    (void)parse_delimiter(user_supplied_pre_statements,
1558
1574
      && !stat(user_supplied_post_statements, &sbuf))
1559
1575
  {
1560
1576
    File data_file;
1561
 
    if (!S_ISREG(sbuf.st_mode))
 
1577
    if (!MY_S_ISREG(sbuf.st_mode))
1562
1578
    {
1563
1579
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1564
1580
              my_progname);
1571
1587
    }
1572
1588
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1573
1589
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1574
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1590
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1575
1591
    tmp_string[sbuf.st_size]= '\0';
1576
1592
    my_close(data_file,MYF(0));
1577
1593
    if (user_supplied_post_statements)
1578
1594
      (void)parse_delimiter(tmp_string, &post_statements,
1579
1595
                            delimiter[0]);
1580
 
    free(tmp_string);
1581
 
  }
 
1596
    my_free(tmp_string, MYF(0));
 
1597
  } 
1582
1598
  else if (user_supplied_post_statements)
1583
1599
  {
1584
1600
    (void)parse_delimiter(user_supplied_post_statements, &post_statements,
1592
1608
    parse_option(default_engine, &engine_options, ',');
1593
1609
 
1594
1610
  if (tty_password)
1595
 
    opt_password= get_tty_password(NULL);
 
1611
    opt_password= get_tty_password(NullS);
1596
1612
  return(0);
1597
1613
}
1598
1614
 
1599
1615
 
1600
 
static int run_query(DRIZZLE *drizzle, const char *query, int len)
 
1616
static int run_query(MYSQL *mysql, const char *query, int len)
1601
1617
{
1602
1618
  if (opt_only_print)
1603
1619
  {
1607
1623
 
1608
1624
  if (verbose >= 3)
1609
1625
    printf("%.*s;\n", len, query);
1610
 
  return drizzle_real_query(drizzle, query, len);
 
1626
  return mysql_real_query(mysql, query, len);
1611
1627
}
1612
1628
 
1613
1629
 
1614
1630
static int
1615
 
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
 
1631
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
1616
1632
{
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
 
1633
  MYSQL_RES *result;
 
1634
  MYSQL_ROW row;
 
1635
  unsigned long long counter;
 
1636
 
 
1637
 
 
1638
  /* 
 
1639
    Blackhole is a special case, this allows us to test the upper end 
1624
1640
    of the server during load runs.
1625
1641
  */
1626
 
  if (opt_only_print || (engine_stmt &&
 
1642
  if (opt_only_print || (engine_stmt && 
1627
1643
                         strstr(engine_stmt->string, "blackhole")))
1628
1644
  {
1629
1645
    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));
 
1646
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
 
1647
                                            primary_keys_number_of), 
 
1648
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1633
1649
    /* Yes, we strdup a const string to simplify the interface */
1634
 
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
 
1650
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0)); 
1635
1651
  }
1636
1652
  else
1637
1653
  {
1638
 
    if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
 
1654
    if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
1639
1655
    {
1640
1656
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1641
 
              drizzle_error(drizzle));
 
1657
              mysql_error(mysql));
1642
1658
      exit(1);
1643
1659
    }
1644
1660
 
1645
 
    result= drizzle_store_result(drizzle);
1646
 
    primary_keys_number_of= drizzle_num_rows(result);
 
1661
    result= mysql_store_result(mysql);
 
1662
    primary_keys_number_of= mysql_num_rows(result);
1647
1663
 
1648
1664
    /* So why check this? Blackhole :) */
1649
1665
    if (primary_keys_number_of)
1651
1667
      /*
1652
1668
        We create the structure and loop and create the items.
1653
1669
      */
1654
 
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1655
 
                                              primary_keys_number_of),
 
1670
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
 
1671
                                              primary_keys_number_of), 
1656
1672
                                       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))
 
1673
      row= mysql_fetch_row(result);
 
1674
      for (counter= 0; counter < primary_keys_number_of; 
 
1675
           counter++, row= mysql_fetch_row(result))
1660
1676
        primary_keys[counter]= my_strdup(row[0], MYF(0));
1661
1677
    }
1662
1678
 
1663
 
    drizzle_free_result(result);
 
1679
    mysql_free_result(result);
1664
1680
  }
1665
1681
 
1666
1682
  return(0);
1669
1685
static int
1670
1686
drop_primary_key_list(void)
1671
1687
{
1672
 
  uint64_t counter;
 
1688
  unsigned long long counter;
1673
1689
 
1674
1690
  if (primary_keys_number_of)
1675
1691
  {
1676
1692
    for (counter= 0; counter < primary_keys_number_of; counter++)
1677
 
      free(primary_keys[counter]);
 
1693
      my_free(primary_keys[counter], MYF(0));
1678
1694
 
1679
 
    free(primary_keys);
 
1695
    my_free(primary_keys, MYF(0));
1680
1696
  }
1681
1697
 
1682
1698
  return 0;
1683
1699
}
1684
1700
 
1685
1701
static int
1686
 
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
 
1702
create_schema(MYSQL *mysql, const char *db, statement *stmt, 
1687
1703
              option_string *engine_stmt, stats *sptr)
1688
1704
{
1689
1705
  char query[HUGE_STRING_LENGTH];
1701
1717
  if (verbose >= 2)
1702
1718
    printf("Loading Pre-data\n");
1703
1719
 
1704
 
  if (run_query(drizzle, query, len))
 
1720
  if (run_query(mysql, query, len))
1705
1721
  {
1706
1722
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1707
 
            drizzle_error(drizzle));
 
1723
            mysql_error(mysql));
1708
1724
    exit(1);
1709
1725
  }
1710
1726
  else
1721
1737
    if (verbose >= 3)
1722
1738
      printf("%s;\n", query);
1723
1739
 
1724
 
    if (drizzle_select_db(drizzle,  db))
 
1740
    if (mysql_select_db(mysql,  db))
1725
1741
    {
1726
1742
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1727
 
              drizzle_error(drizzle));
 
1743
              mysql_error(mysql));
1728
1744
      exit(1);
1729
1745
    }
1730
1746
    sptr->create_count++;
1734
1750
  {
1735
1751
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1736
1752
                  engine_stmt->string);
1737
 
    if (run_query(drizzle, query, len))
 
1753
    if (run_query(mysql, query, len))
1738
1754
    {
1739
1755
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1740
 
              drizzle_error(drizzle));
 
1756
              mysql_error(mysql));
1741
1757
      exit(1);
1742
1758
    }
1743
1759
    sptr->create_count++;
1756
1772
    {
1757
1773
      char buffer[HUGE_STRING_LENGTH];
1758
1774
 
1759
 
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
 
1775
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string, 
1760
1776
               engine_stmt->option);
1761
 
      if (run_query(drizzle, buffer, strlen(buffer)))
 
1777
      if (run_query(mysql, buffer, strlen(buffer)))
1762
1778
      {
1763
1779
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1764
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1780
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1765
1781
        if (!opt_ignore_sql_errors)
1766
1782
          exit(1);
1767
1783
      }
1769
1785
    }
1770
1786
    else
1771
1787
    {
1772
 
      if (run_query(drizzle, ptr->string, ptr->length))
 
1788
      if (run_query(mysql, ptr->string, ptr->length))
1773
1789
      {
1774
1790
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1775
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1791
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1776
1792
        if (!opt_ignore_sql_errors)
1777
1793
          exit(1);
1778
1794
      }
1795
1811
}
1796
1812
 
1797
1813
static int
1798
 
drop_schema(DRIZZLE *drizzle, const char *db)
 
1814
drop_schema(MYSQL *mysql, const char *db)
1799
1815
{
1800
1816
  char query[HUGE_STRING_LENGTH];
1801
1817
  int len;
1802
1818
 
1803
1819
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1804
1820
 
1805
 
  if (run_query(drizzle, query, len))
 
1821
  if (run_query(mysql, query, len))
1806
1822
  {
1807
1823
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1808
 
            my_progname, db, drizzle_error(drizzle));
 
1824
            my_progname, db, mysql_error(mysql));
1809
1825
    exit(1);
1810
1826
  }
1811
1827
 
1815
1831
}
1816
1832
 
1817
1833
static int
1818
 
run_statements(DRIZZLE *drizzle, statement *stmt)
 
1834
run_statements(MYSQL *mysql, statement *stmt) 
1819
1835
{
1820
1836
  statement *ptr;
1821
 
  DRIZZLE_RES *result;
 
1837
  MYSQL_RES *result;
1822
1838
 
1823
1839
 
1824
1840
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
1825
1841
  {
1826
 
    if (run_query(drizzle, ptr->string, ptr->length))
 
1842
    if (run_query(mysql, ptr->string, ptr->length))
1827
1843
    {
1828
1844
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1829
 
              my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1845
              my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
1830
1846
      exit(1);
1831
1847
    }
1832
1848
    if (!opt_only_print)
1833
1849
    {
1834
 
      if (drizzle_field_count(drizzle))
 
1850
      if (mysql_field_count(mysql))
1835
1851
      {
1836
 
        result= drizzle_store_result(drizzle);
1837
 
        drizzle_free_result(result);
 
1852
        result= mysql_store_result(mysql);
 
1853
        mysql_free_result(result);
1838
1854
      }
1839
1855
    }
1840
1856
  }
1857
1873
 
1858
1874
  pthread_attr_init(&attr);
1859
1875
  pthread_attr_setdetachstate(&attr,
1860
 
                              PTHREAD_CREATE_DETACHED);
 
1876
                  PTHREAD_CREATE_DETACHED);
1861
1877
 
1862
1878
  pthread_mutex_lock(&counter_mutex);
1863
1879
  thread_counter= 0;
1868
1884
 
1869
1885
  real_concurrency= 0;
1870
1886
 
1871
 
  for (y= 0, sql_type= query_options;
1872
 
       y < query_statements_count;
 
1887
  for (y= 0, sql_type= query_options; 
 
1888
       y < query_statements_count; 
1873
1889
       y++, sql_type= sql_type->next)
1874
1890
  {
1875
1891
    unsigned int options_loop= 1;
1876
1892
 
1877
1893
    if (sql_type->option)
1878
1894
    {
1879
 
      options_loop= strtol(sql_type->option,
 
1895
      options_loop= strtol(sql_type->option, 
1880
1896
                           (char **)NULL, 10);
1881
1897
      options_loop= options_loop ? options_loop : 1;
1882
1898
    }
1890
1906
 
1891
1907
        real_concurrency++;
1892
1908
        /* now you create the thread */
1893
 
        if (pthread_create(&mainthread, &attr, run_task,
 
1909
        if (pthread_create(&mainthread, &attr, run_task, 
1894
1910
                           (void *)con) != 0)
1895
1911
        {
1896
1912
          fprintf(stderr,"%s: Could not create thread\n", my_progname);
1900
1916
      }
1901
1917
  }
1902
1918
 
1903
 
  /*
1904
 
    The timer_thread belongs to all threads so it too obeys the wakeup
 
1919
  /* 
 
1920
    The timer_thread belongs to all threads so it too obeys the wakeup 
1905
1921
    call that run tasks obey.
1906
1922
  */
1907
1923
  if (opt_timer_length)
1910
1926
    timer_alarm= true;
1911
1927
    pthread_mutex_unlock(&timer_alarm_mutex);
1912
1928
 
1913
 
    if (pthread_create(&mainthread, &attr, timer_thread,
 
1929
    if (pthread_create(&mainthread, &attr, timer_thread, 
1914
1930
                       (void *)&opt_timer_length) != 0)
1915
1931
    {
1916
1932
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
1959
1975
  struct timespec abstime;
1960
1976
 
1961
1977
 
1962
 
  /*
1963
 
    We lock around the initial call in case were we in a loop. This
 
1978
 
 
1979
  if (mysql_thread_init())
 
1980
  {
 
1981
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
1982
            my_progname);
 
1983
    exit(1);
 
1984
  }
 
1985
 
 
1986
  /* 
 
1987
    We lock around the initial call in case were we in a loop. This 
1964
1988
    also keeps the value properly syncronized across call threads.
1965
1989
  */
1966
1990
  pthread_mutex_lock(&sleeper_mutex);
1980
2004
  timer_alarm= false;
1981
2005
  pthread_mutex_unlock(&timer_alarm_mutex);
1982
2006
 
 
2007
  mysql_thread_end();
1983
2008
  return(0);
1984
2009
}
1985
2010
 
1988
2013
  uint64_t counter= 0, queries;
1989
2014
  uint64_t detach_counter;
1990
2015
  unsigned int commit_counter;
1991
 
  DRIZZLE drizzle;
1992
 
  DRIZZLE_RES *result;
1993
 
  DRIZZLE_ROW row;
 
2016
  MYSQL mysql;
 
2017
  MYSQL_RES *result;
 
2018
  MYSQL_ROW row;
1994
2019
  statement *ptr;
1995
2020
  thread_context *con= (thread_context *)p;
1996
2021
 
 
2022
  if (mysql_thread_init())
 
2023
  {
 
2024
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
2025
            my_progname);
 
2026
    exit(1);
 
2027
  }
 
2028
 
1997
2029
  pthread_mutex_lock(&sleeper_mutex);
1998
2030
  while (master_wakeup)
1999
2031
  {
2001
2033
  }
2002
2034
  pthread_mutex_unlock(&sleeper_mutex);
2003
2035
 
2004
 
  slap_connect(&drizzle, true);
 
2036
  slap_connect(&mysql, true);
2005
2037
 
2006
2038
  if (verbose >= 3)
2007
2039
    printf("connected!\n");
2009
2041
 
2010
2042
  commit_counter= 0;
2011
2043
  if (commit_rate)
2012
 
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
2044
    run_query(&mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2013
2045
 
2014
2046
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.
 
2047
    for (ptr= con->stmt, detach_counter= 0; 
 
2048
         ptr && ptr->length; 
 
2049
         ptr= ptr->next, detach_counter++)
 
2050
    {
 
2051
      if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
2052
      {
 
2053
        slap_close(&mysql);
 
2054
        slap_connect(&mysql, true);
 
2055
      }
 
2056
 
 
2057
      /* 
 
2058
        We have to execute differently based on query type. This should become a function.
2042
2059
      */
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))
 
2060
      if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
2061
          (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
 
2062
      {
 
2063
        int length;
 
2064
        unsigned int key_val;
 
2065
        char *key;
 
2066
        char buffer[HUGE_STRING_LENGTH];
 
2067
 
 
2068
        /* 
 
2069
          This should only happen if some sort of new engine was
 
2070
          implemented that didn't properly handle UPDATEs.
 
2071
 
 
2072
          Just in case someone runs this under an experimental engine we don't
 
2073
          want a crash so the if() is placed here.
 
2074
        */
 
2075
        assert(primary_keys_number_of);
 
2076
        if (primary_keys_number_of)
 
2077
        {
 
2078
          key_val= (unsigned int)(random() % primary_keys_number_of);
 
2079
          key= primary_keys[key_val];
 
2080
 
 
2081
          assert(key);
 
2082
 
 
2083
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'", 
 
2084
                           (int)ptr->length, ptr->string, key);
 
2085
 
 
2086
          if (run_query(&mysql, buffer, length))
 
2087
          {
 
2088
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2089
                    my_progname, (uint)length, buffer, mysql_error(&mysql));
 
2090
            exit(1);
 
2091
          }
 
2092
        }
 
2093
      }
 
2094
      else
 
2095
      {
 
2096
        if (run_query(&mysql, ptr->string, ptr->length))
2055
2097
        {
2056
2098
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2057
 
                  my_progname, (uint)length, buffer, drizzle_error(&drizzle));
 
2099
                  my_progname, (uint)ptr->length, ptr->string, mysql_error(&mysql));
2058
2100
          exit(1);
2059
2101
        }
2060
2102
      }
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
2103
 
2072
 
    if (!opt_only_print)
2073
 
    {
2074
 
      do
 
2104
      if (!opt_only_print)
2075
2105
      {
2076
 
        if (drizzle_field_count(&drizzle))
 
2106
        do
2077
2107
        {
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;
 
2108
          if (mysql_field_count(&mysql))
 
2109
          {
 
2110
            result= mysql_store_result(&mysql);
 
2111
            while ((row = mysql_fetch_row(result)))
 
2112
              counter++;
 
2113
            mysql_free_result(result);
 
2114
          }
 
2115
        } while(mysql_next_result(&mysql) == 0);
 
2116
      }
 
2117
      queries++;
 
2118
 
 
2119
      if (commit_rate && (++commit_counter == commit_rate))
 
2120
      {
 
2121
        commit_counter= 0;
 
2122
        run_query(&mysql, "COMMIT", strlen("COMMIT"));
 
2123
      }
 
2124
 
 
2125
      /* If the timer is set, and the alarm is not active then end */
 
2126
      if (opt_timer_length && timer_alarm == false)
 
2127
        goto end;
 
2128
 
 
2129
      /* If limit has been reached, and we are not in a timer_alarm just end */
 
2130
      if (con->limit && queries == con->limit && timer_alarm == false)
 
2131
        goto end;
 
2132
    }
 
2133
 
 
2134
    if (opt_timer_length && timer_alarm == true)
 
2135
      goto limit_not_met;
 
2136
 
 
2137
    if (con->limit && queries < con->limit)
 
2138
      goto limit_not_met;
2107
2139
 
2108
2140
 
2109
2141
end:
2110
2142
  if (commit_rate)
2111
 
    run_query(&drizzle, "COMMIT", strlen("COMMIT"));
 
2143
    run_query(&mysql, "COMMIT", strlen("COMMIT"));
2112
2144
 
2113
 
  slap_close(&drizzle);
 
2145
  slap_close(&mysql);
2114
2146
 
2115
2147
  pthread_mutex_lock(&counter_mutex);
2116
2148
  thread_counter--;
2117
2149
  pthread_cond_signal(&count_threshhold);
2118
2150
  pthread_mutex_unlock(&counter_mutex);
2119
2151
 
2120
 
  free(con);
 
2152
  my_free(con, MYF(0));
2121
2153
 
 
2154
  mysql_thread_end();
2122
2155
  return(0);
2123
2156
}
2124
2157
 
2149
2182
    char buffer[HUGE_STRING_LENGTH];
2150
2183
    char *buffer_ptr;
2151
2184
 
2152
 
    memset(buffer, 0, HUGE_STRING_LENGTH);
 
2185
    bzero(buffer, HUGE_STRING_LENGTH);
2153
2186
 
2154
 
    string= strchr(begin_ptr, delm);
 
2187
    string= strchr(begin_ptr, delm); 
2155
2188
 
2156
2189
    if (string)
2157
2190
    {
2210
2243
 
2211
2244
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2212
2245
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2213
 
       (retstr= strchr(ptr, delm));
 
2246
       (retstr= strchr(ptr, delm)); 
2214
2247
       tmp->next=  (statement *)my_malloc(sizeof(statement),
2215
2248
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2216
 
         tmp= tmp->next)
 
2249
       tmp= tmp->next)
2217
2250
  {
2218
2251
    count++;
2219
2252
    tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2225
2258
 
2226
2259
  if (ptr != script+length)
2227
2260
  {
2228
 
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2229
 
                            MYF(MY_FAE));
 
2261
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr), 
 
2262
                                       MYF(MY_FAE));
2230
2263
    tmp->length= (size_t)((script + length) - ptr);
2231
2264
    count++;
2232
2265
  }
2250
2283
 
2251
2284
  for (;*ptr; ptr++)
2252
2285
    if (*ptr == ',') count++;
2253
 
 
 
2286
  
2254
2287
  /* One extra spot for the NULL */
2255
 
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
 
2288
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1), 
2256
2289
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2257
2290
 
2258
2291
  ptr= (char *)string;
2272
2305
{
2273
2306
  printf("Benchmark\n");
2274
2307
  if (con->engine)
2275
 
    printf("\tRunning for engine %s\n", con->engine);
 
2308
      printf("\tRunning for engine %s\n", con->engine);
2276
2309
  if (opt_label || opt_auto_generate_sql_type)
2277
2310
  {
2278
2311
    const char *ptr= opt_auto_generate_sql_type ? opt_auto_generate_sql_type : "query";
2286
2319
         con->min_timing / 1000, con->min_timing % 1000);
2287
2320
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2288
2321
         con->max_timing / 1000, con->max_timing % 1000);
2289
 
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
 
2322
  printf("\tTotal time for tests: %ld.%03ld seconds\n", 
2290
2323
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2291
2324
  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",
 
2325
  printf("\tNumber of queries in create queries: %llu\n", con->create_count);
 
2326
  printf("\tNumber of clients running queries: %u/%u\n", 
2294
2327
         con->users, con->real_users);
2295
2328
  printf("\tNumber of times test was run: %u\n", iterations);
2296
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->avg_rows);
 
2329
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows); 
2297
2330
  printf("\n");
2298
2331
}
2299
2332
 
2305
2338
  char label_buffer[HUGE_STRING_LENGTH];
2306
2339
  size_t string_len;
2307
2340
 
2308
 
  memset(label_buffer, 0, HUGE_STRING_LENGTH);
 
2341
  bzero(label_buffer, HUGE_STRING_LENGTH);
2309
2342
 
2310
2343
  if (opt_label)
2311
2344
  {
2318
2351
      else
2319
2352
        label_buffer[x]= opt_label[x] ;
2320
2353
    }
2321
 
  }
 
2354
  } 
2322
2355
  else if (opt_auto_generate_sql_type)
2323
2356
  {
2324
2357
    string_len= strlen(opt_auto_generate_sql_type);
2334
2367
  else
2335
2368
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
2336
2369
 
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",
 
2370
  snprintf(buffer, HUGE_STRING_LENGTH, 
 
2371
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%u,%u,%u,%llu\n",
2340
2372
           con->engine ? con->engine : "", /* Storage engine we ran against */
2341
2373
           label_buffer, /* Load type */
2342
2374
           con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
2348
2380
           con->users, /* Children used max_timing */
2349
2381
           con->real_users, /* Children used max_timing */
2350
2382
           con->avg_rows  /* Queries run */
2351
 
           );
2352
 
  my_write(csv_file, (unsigned char*) buffer, (uint)strlen(buffer), MYF(0));
 
2383
          );
 
2384
  my_write(csv_file, (uchar*) buffer, (uint)strlen(buffer), MYF(0));
2353
2385
}
2354
2386
 
2355
2387
void
2358
2390
  stats *ptr;
2359
2391
  unsigned int x;
2360
2392
 
2361
 
  con->min_timing= sptr->timing;
 
2393
  con->min_timing= sptr->timing; 
2362
2394
  con->max_timing= sptr->timing;
2363
2395
  con->min_rows= sptr->rows;
2364
2396
  con->max_rows= sptr->rows;
2365
 
 
 
2397
  
2366
2398
  /* At the moment we assume uniform */
2367
2399
  con->users= sptr->users;
2368
2400
  con->real_users= sptr->real_users;
2369
2401
  con->avg_rows= sptr->rows;
2370
 
 
 
2402
  
2371
2403
  /* With no next, we know it is the last element that was malloced */
2372
2404
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2373
2405
  {
2389
2421
  standard_deviation(con, sptr);
2390
2422
 
2391
2423
  /* Now we do the create time operations */
2392
 
  con->create_min_timing= sptr->create_timing;
 
2424
  con->create_min_timing= sptr->create_timing; 
2393
2425
  con->create_max_timing= sptr->create_timing;
2394
 
 
 
2426
  
2395
2427
  /* At the moment we assume uniform */
2396
2428
  con->create_count= sptr->create_count;
2397
 
 
 
2429
  
2398
2430
  /* With no next, we know it is the last element that was malloced */
2399
2431
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2400
2432
  {
2419
2451
  {
2420
2452
    nptr= ptr->next;
2421
2453
    if (ptr->string)
2422
 
      free(ptr->string);
 
2454
      my_free(ptr->string, MYF(0)); 
2423
2455
    if (ptr->option)
2424
 
      free(ptr->option);
2425
 
    free(ptr);
 
2456
      my_free(ptr->option, MYF(0)); 
 
2457
    my_free(ptr, MYF(0));
2426
2458
  }
2427
2459
}
2428
2460
 
2437
2469
  {
2438
2470
    nptr= ptr->next;
2439
2471
    if (ptr->string)
2440
 
      free(ptr->string);
2441
 
    free(ptr);
 
2472
      my_free(ptr->string, MYF(0)); 
 
2473
    my_free(ptr, MYF(0));
2442
2474
  }
2443
2475
}
2444
2476
 
2445
 
void
2446
 
slap_close(DRIZZLE *drizzle)
 
2477
void 
 
2478
slap_close(MYSQL *mysql)
2447
2479
{
2448
 
  if (opt_only_print)
 
2480
  if (opt_only_print) 
2449
2481
    return;
2450
2482
 
2451
 
  drizzle_close(drizzle);
 
2483
  mysql_close(mysql);
2452
2484
}
2453
2485
 
2454
 
void
2455
 
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
 
2486
void 
 
2487
slap_connect(MYSQL *mysql, bool connect_to_schema)
2456
2488
{
2457
2489
  /* Connect to server */
2458
 
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
 
2490
  static ulong connection_retry_sleep= 100000; /* Microseconds */
2459
2491
  int x, connect_error= 1;
2460
2492
 
2461
 
  if (opt_only_print)
 
2493
  if (opt_only_print) 
2462
2494
    return;
2463
2495
 
2464
2496
  if (opt_delayed_start)
2465
2497
    my_sleep(random()%opt_delayed_start);
2466
2498
 
2467
 
  drizzle_create(drizzle);
 
2499
  mysql_init(mysql);
2468
2500
 
2469
2501
  if (opt_compress)
2470
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
2502
    mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
 
2503
  /* We always do opt_protocol to TCP/IP */
 
2504
  mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
2505
  mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
2471
2506
 
2472
2507
  for (x= 0; x < 10; x++)
2473
2508
  {
2474
2509
 
2475
2510
 
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))
 
2511
    if (mysql_real_connect(mysql, host, user, opt_password,
 
2512
                           connect_to_schema ? create_schema_string : NULL,
 
2513
                           opt_mysql_port,
 
2514
                           opt_mysql_unix_port,
 
2515
                           connect_flags))
2481
2516
    {
2482
2517
      /* Connect suceeded */
2483
2518
      connect_error= 0;
2488
2523
  if (connect_error)
2489
2524
  {
2490
2525
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2491
 
            my_progname, drizzle_errno(drizzle), drizzle_error(drizzle));
 
2526
            my_progname, mysql_errno(mysql), mysql_error(mysql));
2492
2527
    exit(1);
2493
2528
  }
2494
2529
 
2495
2530
  return;
2496
2531
}
2497
2532
 
2498
 
void
 
2533
void 
2499
2534
standard_deviation (conclusions *con, stats *sptr)
2500
2535
{
2501
2536
  unsigned int x;
2502
2537
  long int sum_of_squares;
2503
 
  double the_catch;
 
2538
  double catch;
2504
2539
  stats *ptr;
2505
2540
 
2506
2541
  if (iterations == 1 || iterations == 0)
2517
2552
    sum_of_squares+= deviation*deviation;
2518
2553
  }
2519
2554
 
2520
 
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2521
 
  con->std_dev= (long int)the_catch;
 
2555
  catch= sqrt((double)(sum_of_squares/(iterations -1)));
 
2556
  con->std_dev= (long int)catch;
2522
2557
}