~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

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) 2008 Drizzle Open Source Development Team
 
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
/*
27
26
 
28
27
  Drizzle 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
 
36
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
    drizzleslap --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
    drizzleslap --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
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
    drizzleslap --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.
82
81
#include <sys/types.h>
83
82
#include <sys/wait.h>
84
83
#include <ctype.h>
85
 
#include <string>
86
 
 
87
 
/* Added this for string translation. */
88
 
#include <drizzled/gettext.h>
89
 
 
90
 
#include CMATH_H
91
 
 
92
 
#if defined(CMATH_NAMESPACE)
93
 
using namespace CMATH_NAMESPACE;
94
 
#endif
95
 
 
96
 
using namespace std;
97
84
 
98
85
#ifdef HAVE_SMEM
99
86
static char *shared_memory_base_name=0;
115
102
static char **defaults_argv;
116
103
 
117
104
char **primary_keys;
118
 
uint64_t primary_keys_number_of;
 
105
unsigned long long primary_keys_number_of;
119
106
 
120
107
static char *host= NULL, *opt_password= NULL, *user= NULL,
121
 
  *user_supplied_query= NULL,
122
 
  *user_supplied_pre_statements= NULL,
123
 
  *user_supplied_post_statements= NULL,
124
 
  *default_engine= NULL,
125
 
  *pre_system= NULL,
126
 
  *post_system= NULL,
127
 
  *opt_drizzle_unix_port= NULL;
 
108
            *user_supplied_query= NULL,
 
109
            *user_supplied_pre_statements= NULL,
 
110
            *user_supplied_post_statements= NULL,
 
111
            *default_engine= NULL,
 
112
            *pre_system= NULL,
 
113
            *post_system= NULL,
 
114
            *opt_drizzle_unix_port= NULL;
128
115
 
129
116
const char *delimiter= "\n";
130
117
 
131
 
const char *create_schema_string= "drizzleslap";
 
118
const char *create_schema_string= "mysqlslap";
132
119
 
133
120
static bool opt_preserve= true;
134
 
static bool debug_info_flag= false, debug_check_flag= false;
 
121
static bool debug_info_flag= 0, debug_check_flag= 0;
135
122
static bool opt_only_print= false;
136
123
static bool opt_burnin= false;
137
124
static bool opt_ignore_sql_errors= false;
138
125
static bool opt_compress= false, tty_password= false,
139
 
  opt_silent= false,
140
 
  auto_generate_sql_autoincrement= false,
141
 
  auto_generate_sql_guid_primary= false,
142
 
  auto_generate_sql= false;
 
126
               opt_silent= false,
 
127
               auto_generate_sql_autoincrement= false,
 
128
               auto_generate_sql_guid_primary= false,
 
129
               auto_generate_sql= false;
143
130
const char *opt_auto_generate_sql_type= "mixed";
144
131
 
145
132
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
146
 
  CLIENT_MULTI_STATEMENTS;
 
133
                                    CLIENT_MULTI_STATEMENTS;
147
134
 
148
135
static int verbose, delimiter_length;
149
136
static uint commit_rate;
168
155
static unsigned int num_char_cols_index= 0;
169
156
static unsigned int iterations;
170
157
static uint my_end_arg= 0;
 
158
static char *default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
171
159
static uint64_t actual_queries= 0;
172
160
static uint64_t auto_actual_queries;
173
161
static uint64_t auto_generate_sql_unique_write_number;
179
167
static char *create_string;
180
168
uint *concurrency;
181
169
 
182
 
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
 
170
const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
183
171
const char *opt_csv_str;
184
172
File csv_file;
185
173
 
 
174
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
175
 
186
176
static int get_options(int *argc,char ***argv);
187
 
static uint32_t opt_drizzle_port= 0;
 
177
static uint opt_drizzle_port= 0;
188
178
 
189
 
static const char *load_default_groups[]= { "drizzleslap","client",0 };
 
179
static const char *load_default_groups[]= { "mysqlslap","client",0 };
190
180
 
191
181
/* Types */
192
182
typedef enum {
226
216
  long int timing;
227
217
  uint users;
228
218
  uint real_users;
229
 
  uint64_t rows;
 
219
  unsigned long long rows;
230
220
  long int create_timing;
231
 
  uint64_t create_count;
 
221
  unsigned long long create_count;
232
222
};
233
223
 
234
224
typedef struct thread_context thread_context;
247
237
  long int min_timing;
248
238
  uint users;
249
239
  uint real_users;
250
 
  uint64_t avg_rows;
 
240
  unsigned long long avg_rows;
251
241
  long int sum_of_time;
252
242
  long int std_dev;
253
243
  /* These are just for create time stats */
254
244
  long int create_avg_timing;
255
245
  long int create_max_timing;
256
246
  long int create_min_timing;
257
 
  uint64_t create_count;
 
247
  unsigned long long create_count;
258
248
  /* The following are not used yet */
259
 
  uint64_t max_rows;
260
 
  uint64_t min_rows;
 
249
  unsigned long long max_rows;
 
250
  unsigned long long min_rows;
261
251
};
262
252
 
263
253
static option_string *engine_options= NULL;
301
291
void standard_deviation (conclusions *con, stats *sptr);
302
292
 
303
293
static const char ALPHANUMERICS[]=
304
 
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
 
294
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
305
295
 
306
296
#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
307
297
 
308
298
 
309
299
static long int timedif(struct timeval a, struct timeval b)
310
300
{
311
 
  register int us, s;
 
301
    register int us, s;
312
302
 
313
 
  us = a.tv_usec - b.tv_usec;
314
 
  us /= 1000;
315
 
  s = a.tv_sec - b.tv_sec;
316
 
  s *= 1000;
317
 
  return s + us;
 
303
    us = a.tv_usec - b.tv_usec;
 
304
    us /= 1000;
 
305
    s = a.tv_sec - b.tv_sec;
 
306
    s *= 1000;
 
307
    return s + us;
318
308
}
319
309
 
320
310
int main(int argc, char **argv)
327
317
 
328
318
  MY_INIT(argv[0]);
329
319
 
330
 
  load_defaults("drizzle",load_default_groups,&argc,&argv);
 
320
  if (!(drizzle_thread_safe()))
 
321
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
 
322
 
 
323
  load_defaults("my",load_default_groups,&argc,&argv);
331
324
  defaults_argv=argv;
332
325
  if (get_options(&argc,&argv))
333
326
  {
357
350
 
358
351
  slap_connect(&drizzle, false);
359
352
 
360
 
  pthread_mutex_init(&counter_mutex, NULL);
361
 
  pthread_cond_init(&count_threshhold, NULL);
362
 
  pthread_mutex_init(&sleeper_mutex, NULL);
363
 
  pthread_cond_init(&sleep_threshhold, NULL);
364
 
  pthread_mutex_init(&timer_alarm_mutex, NULL);
365
 
  pthread_cond_init(&timer_alarm_threshold, NULL);
 
353
  VOID(pthread_mutex_init(&counter_mutex, NULL));
 
354
  VOID(pthread_cond_init(&count_threshhold, NULL));
 
355
  VOID(pthread_mutex_init(&sleeper_mutex, NULL));
 
356
  VOID(pthread_cond_init(&sleep_threshhold, NULL));
 
357
  VOID(pthread_mutex_init(&timer_alarm_mutex, NULL));
 
358
  VOID(pthread_cond_init(&timer_alarm_threshold, NULL));
366
359
 
367
360
 
368
361
  /* Main iterations loop */
394
387
      drop_schema(&drizzle, create_schema_string);
395
388
 
396
389
  } while (eptr ? (eptr= eptr->next) : 0);
397
 
 
 
390
 
398
391
  if (opt_burnin)
399
392
    goto burnin;
400
393
 
401
 
  pthread_mutex_destroy(&counter_mutex);
402
 
  pthread_cond_destroy(&count_threshhold);
403
 
  pthread_mutex_destroy(&sleeper_mutex);
404
 
  pthread_cond_destroy(&sleep_threshhold);
405
 
  pthread_mutex_destroy(&timer_alarm_mutex);
406
 
  pthread_cond_destroy(&timer_alarm_threshold);
 
394
  VOID(pthread_mutex_destroy(&counter_mutex));
 
395
  VOID(pthread_cond_destroy(&count_threshhold));
 
396
  VOID(pthread_mutex_destroy(&sleeper_mutex));
 
397
  VOID(pthread_cond_destroy(&sleep_threshhold));
 
398
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
 
399
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
407
400
 
408
401
  slap_close(&drizzle);
409
402
 
410
403
  /* now free all the strings we created */
411
404
  if (opt_password)
412
 
    free(opt_password);
 
405
    my_free(opt_password, MYF(0));
413
406
 
414
 
  free(concurrency);
 
407
  my_free(concurrency, MYF(0));
415
408
 
416
409
  statement_cleanup(create_statements);
417
410
  for (x= 0; x < query_statements_count; x++)
418
411
    statement_cleanup(query_statements[x]);
419
 
  free(query_statements);
 
412
  my_free(query_statements, MYF(0));
420
413
  statement_cleanup(pre_statements);
421
414
  statement_cleanup(post_statements);
422
415
  option_cleanup(engine_options);
424
417
 
425
418
#ifdef HAVE_SMEM
426
419
  if (shared_memory_base_name)
427
 
    free(shared_memory_base_name);
 
420
    my_free(shared_memory_base_name, MYF(MY_ALLOW_ZERO_PTR));
428
421
#endif
429
422
  free_defaults(defaults_argv);
430
423
  my_end(my_end_arg);
438
431
  stats *head_sptr;
439
432
  stats *sptr;
440
433
  conclusions conclusion;
441
 
  uint64_t client_limit;
 
434
  unsigned long long client_limit;
442
435
 
443
 
  head_sptr= (stats *)malloc(sizeof(stats) * iterations);
444
 
  if (head_sptr == NULL)
445
 
  {
446
 
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
447
 
    exit(1);
448
 
  }
449
 
  memset(head_sptr, 0, sizeof(stats) * iterations);
 
436
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
 
437
                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
450
438
 
451
439
  memset(&conclusion, 0, sizeof(conclusions));
452
440
 
484
472
      run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
485
473
 
486
474
    if (pre_system)
487
 
      assert(system(pre_system)!=-1);
 
475
      system(pre_system);
488
476
 
489
477
    /*
490
478
      Pre statements are always run after all other logic so they can
494
482
      run_statements(drizzle, pre_statements);
495
483
 
496
484
    run_scheduler(sptr, query_statements, current, client_limit);
497
 
 
 
485
   
498
486
    if (post_statements)
499
487
      run_statements(drizzle, post_statements);
500
488
 
501
489
    if (post_system)
502
 
      assert(system(post_system)!=-1);
 
490
      system(post_system);
503
491
 
504
492
    /* We are finished with this run */
505
493
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
516
504
  if (opt_csv_str)
517
505
    print_conclusions_csv(&conclusion);
518
506
 
519
 
  free(head_sptr);
 
507
  my_free(head_sptr, MYF(0));
520
508
 
521
509
}
522
510
 
524
512
static struct my_option my_long_options[] =
525
513
{
526
514
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
527
 
   0, 0, 0, 0, 0, 0},
 
515
    0, 0, 0, 0, 0, 0},
528
516
  {"auto-generate-sql-select-columns", OPT_SLAP_AUTO_GENERATE_SELECT_COLUMNS,
529
 
   "Provide a string to use for the select fields used in auto tests.",
530
 
   (char**) &auto_generate_selected_columns_opt,
531
 
   (char**) &auto_generate_selected_columns_opt,
532
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
517
    "Provide a string to use for the select fields used in auto tests.",
 
518
    (char**) &auto_generate_selected_columns_opt,
 
519
    (char**) &auto_generate_selected_columns_opt,
 
520
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
533
521
  {"auto-generate-sql", 'a',
534
 
   "Generate SQL where not supplied by file or command line.",
535
 
   (char**) &auto_generate_sql, (char**) &auto_generate_sql,
536
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
522
    "Generate SQL where not supplied by file or command line.",
 
523
    (char**) &auto_generate_sql, (char**) &auto_generate_sql,
 
524
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
537
525
  {"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
538
 
   "Add an AUTO_INCREMENT column to auto-generated tables.",
539
 
   (char**) &auto_generate_sql_autoincrement,
540
 
   (char**) &auto_generate_sql_autoincrement,
541
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
526
    "Add an AUTO_INCREMENT column to auto-generated tables.",
 
527
    (char**) &auto_generate_sql_autoincrement,
 
528
    (char**) &auto_generate_sql_autoincrement,
 
529
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
542
530
  {"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
543
 
   "Set this number to generate a set number of queries to run.",
544
 
   (char**) &auto_actual_queries, (char**) &auto_actual_queries,
545
 
   0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
531
    "Set this number to generate a set number of queries to run.",
 
532
    (char**) &auto_actual_queries, (char**) &auto_actual_queries,
 
533
    0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
546
534
  {"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
547
 
   "Add GUID based primary keys to auto-generated tables.",
548
 
   (char**) &auto_generate_sql_guid_primary,
549
 
   (char**) &auto_generate_sql_guid_primary,
550
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
535
    "Add GUID based primary keys to auto-generated tables.",
 
536
    (char**) &auto_generate_sql_guid_primary,
 
537
    (char**) &auto_generate_sql_guid_primary,
 
538
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
551
539
  {"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
552
 
   "Specify test load type: mixed, update, write, key, or read; default is mixed.",
553
 
   (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
554
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
540
    "Specify test load type: mixed, update, write, key, or read; default is mixed.",
 
541
    (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
 
542
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
555
543
  {"auto-generate-sql-secondary-indexes",
556
 
   OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
557
 
   "Number of secondary indexes to add to auto-generated tables.",
558
 
   (char**) &auto_generate_sql_secondary_indexes,
559
 
   (char**) &auto_generate_sql_secondary_indexes, 0,
560
 
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
544
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
 
545
    "Number of secondary indexes to add to auto-generated tables.",
 
546
    (char**) &auto_generate_sql_secondary_indexes,
 
547
    (char**) &auto_generate_sql_secondary_indexes, 0,
 
548
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
561
549
  {"auto-generate-sql-unique-query-number",
562
 
   OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
563
 
   "Number of unique queries to generate for automatic tests.",
564
 
   (char**) &auto_generate_sql_unique_query_number,
565
 
   (char**) &auto_generate_sql_unique_query_number,
566
 
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
550
    OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
 
551
    "Number of unique queries to generate for automatic tests.",
 
552
    (char**) &auto_generate_sql_unique_query_number,
 
553
    (char**) &auto_generate_sql_unique_query_number,
 
554
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
567
555
  {"auto-generate-sql-unique-write-number",
568
 
   OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
569
 
   "Number of unique queries to generate for auto-generate-sql-write-number.",
570
 
   (char**) &auto_generate_sql_unique_write_number,
571
 
   (char**) &auto_generate_sql_unique_write_number,
572
 
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
556
    OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
 
557
    "Number of unique queries to generate for auto-generate-sql-write-number.",
 
558
    (char**) &auto_generate_sql_unique_write_number,
 
559
    (char**) &auto_generate_sql_unique_write_number,
 
560
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
573
561
  {"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
574
 
   "Number of row inserts to perform for each thread (default is 100).",
575
 
   (char**) &auto_generate_sql_number, (char**) &auto_generate_sql_number,
576
 
   0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
 
562
    "Number of row inserts to perform for each thread (default is 100).",
 
563
    (char**) &auto_generate_sql_number, (char**) &auto_generate_sql_number,
 
564
    0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
577
565
  {"burnin", OPT_SLAP_BURNIN, "Run full test case in infinite loop.",
578
 
   (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
579
 
   0, 0, 0},
 
566
    (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
567
    0, 0, 0},
580
568
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS,
581
 
   "Ignore SQL erros in query run.",
582
 
   (char**) &opt_ignore_sql_errors,
583
 
   (char**) &opt_ignore_sql_errors,
584
 
   0, GET_BOOL, NO_ARG, 0, 0, 0,
585
 
   0, 0, 0},
 
569
    "Ignore SQL erros in query run.",
 
570
    (char**) &opt_ignore_sql_errors,
 
571
    (char**) &opt_ignore_sql_errors,
 
572
    0, GET_BOOL, NO_ARG, 0, 0, 0,
 
573
    0, 0, 0},
586
574
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
587
 
   (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
588
 
   0, 0, 0, 0, 0, 0},
 
575
    (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
 
576
    0, 0, 0, 0, 0, 0},
589
577
  {"compress", 'C', "Use compression in server/client protocol.",
590
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
591
 
   0, 0, 0},
 
578
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
579
    0, 0, 0},
592
580
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
593
 
   (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
594
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
581
    (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
 
582
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
595
583
  {"create", OPT_SLAP_CREATE_STRING, "File or string to use create tables.",
596
 
   (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
597
 
   0, 0, 0, 0, 0, 0},
 
584
    (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
 
585
    0, 0, 0, 0, 0, 0},
598
586
  {"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
599
 
   (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
600
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
587
    (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
 
588
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
601
589
  {"csv", OPT_SLAP_CSV,
602
 
   "Generate CSV output to named file or to stdout if no file is named.",
603
 
   (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
604
 
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
590
  "Generate CSV output to named file or to stdout if no file is named.",
 
591
    (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
 
592
    OPT_ARG, 0, 0, 0, 0, 0, 0},
605
593
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
606
 
    (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
607
 
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
594
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
595
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
608
596
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
609
 
    (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
597
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
610
598
  {"delayed-start", OPT_SLAP_DELAYED_START,
611
 
   "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
612
 
   (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
613
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
599
    "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
 
600
    (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
 
601
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
614
602
  {"delimiter", 'F',
615
 
   "Delimiter to use in SQL statements supplied in file or command line.",
616
 
   (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
617
 
   0, 0, 0, 0, 0, 0},
 
603
    "Delimiter to use in SQL statements supplied in file or command line.",
 
604
    (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
 
605
    0, 0, 0, 0, 0, 0},
618
606
  {"detach", OPT_SLAP_DETACH,
619
 
   "Detach (close and reopen) connections after X number of requests.",
620
 
   (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
621
 
   0, 0, 0, 0, 0, 0},
 
607
    "Detach (close and reopen) connections after X number of requests.",
 
608
    (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
 
609
    0, 0, 0, 0, 0, 0},
622
610
  {"engine", 'e', "Storage engine to use for creating the table.",
623
 
   (char**) &default_engine, (char**) &default_engine, 0,
624
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
611
    (char**) &default_engine, (char**) &default_engine, 0,
 
612
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
625
613
  {"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
626
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
614
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
627
615
  {"iterations", 'i', "Number of times to run the tests.", (char**) &iterations,
628
 
   (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
 
616
    (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
629
617
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
630
 
   (char**) &opt_label, (char**) &opt_label, 0,
631
 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
618
    (char**) &opt_label, (char**) &opt_label, 0,
 
619
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
632
620
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
633
 
   "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. ",
634
 
   (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
635
 
   0, 0, 0, 0, 0, 0},
 
621
    "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
 
622
    (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
623
    0, 0, 0, 0, 0, 0},
636
624
  {"number-char-cols", 'x',
637
 
   "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
638
 
   (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
639
 
   0, 0, 0, 0, 0, 0},
 
625
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
 
626
    (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
627
    0, 0, 0, 0, 0, 0},
640
628
  {"number-int-cols", 'y',
641
 
   "Number of INT columns to create in table if specifying --auto-generate-sql.",
642
 
   (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
643
 
   0, 0, 0, 0, 0, 0},
 
629
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
 
630
    (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
631
    0, 0, 0, 0, 0, 0},
644
632
  {"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
645
 
   "Limit each client to this number of queries (this is not exact).",
646
 
   (char**) &num_of_query, (char**) &num_of_query, 0,
647
 
   GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
633
    "Limit each client to this number of queries (this is not exact).",
 
634
    (char**) &num_of_query, (char**) &num_of_query, 0,
 
635
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
648
636
  {"only-print", OPT_DRIZZLE_ONLY_PRINT,
649
 
   "This causes drizzleslap to not connect to the databases, but instead print "
650
 
   "out what it would have done instead.",
651
 
   (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
652
 
   0, 0, 0, 0, 0, 0},
653
 
  {"password", 'P',
654
 
   "Password to use when connecting to server. If password is not given it's "
655
 
   "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
656
 
  {"port", 'p', "Port number to use for connection.",
657
 
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
637
    "This causes drizzleslap to not connect to the databases, but instead print "
 
638
      "out what it would have done instead.",
 
639
    (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
 
640
    0, 0, 0, 0, 0, 0},
 
641
  {"password", 'p',
 
642
    "Password to use when connecting to server. If password is not given it's "
 
643
      "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
644
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
 
645
    (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
 
646
    0},
658
647
  {"post-query", OPT_SLAP_POST_QUERY,
659
 
   "Query to run or file containing query to execute after tests have completed.",
660
 
   (char**) &user_supplied_post_statements,
661
 
   (char**) &user_supplied_post_statements,
662
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
648
    "Query to run or file containing query to execute after tests have completed.",
 
649
    (char**) &user_supplied_post_statements,
 
650
    (char**) &user_supplied_post_statements,
 
651
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
663
652
  {"post-system", OPT_SLAP_POST_SYSTEM,
664
 
   "system() string to execute after tests have completed.",
665
 
   (char**) &post_system,
666
 
   (char**) &post_system,
667
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
653
    "system() string to execute after tests have completed.",
 
654
    (char**) &post_system,
 
655
    (char**) &post_system,
 
656
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
668
657
  {"pre-query", OPT_SLAP_PRE_QUERY,
669
 
   "Query to run or file containing query to execute before running tests.",
670
 
   (char**) &user_supplied_pre_statements,
671
 
   (char**) &user_supplied_pre_statements,
672
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
658
    "Query to run or file containing query to execute before running tests.",
 
659
    (char**) &user_supplied_pre_statements,
 
660
    (char**) &user_supplied_pre_statements,
 
661
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
673
662
  {"pre-system", OPT_SLAP_PRE_SYSTEM,
674
 
   "system() string to execute before running tests.",
675
 
   (char**) &pre_system,
676
 
   (char**) &pre_system,
677
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
663
    "system() string to execute before running tests.",
 
664
    (char**) &pre_system,
 
665
    (char**) &pre_system,
 
666
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
678
667
  {"protocol", OPT_DRIZZLE_PROTOCOL,
679
 
   "The protocol of connection (tcp,socket,pipe,memory).",
680
 
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
668
    "The protocol of connection (tcp,socket,pipe,memory).",
 
669
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
681
670
  {"query", 'q', "Query to run or file containing query to run.",
682
 
   (char**) &user_supplied_query, (char**) &user_supplied_query,
683
 
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
671
    (char**) &user_supplied_query, (char**) &user_supplied_query,
 
672
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
684
673
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
685
 
   "Seed for random number generator (srandom(3))",
686
 
   (char**)&opt_set_random_seed,
687
 
   (char**)&opt_set_random_seed,0,
688
 
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
674
    "Seed for random number generator (srandom(3))",
 
675
    (char**)&opt_set_random_seed,
 
676
    (char**)&opt_set_random_seed,0,
 
677
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
689
678
  {"silent", 's', "Run program in silent mode - no output.",
690
 
   (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
691
 
   0, 0, 0, 0, 0, 0},
 
679
    (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
 
680
    0, 0, 0, 0, 0, 0},
692
681
  {"socket", 'S', "Socket file to use for connection.",
693
 
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
694
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
682
    (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
 
683
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
695
684
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
696
 
   "Require drizzleslap to run each specific test a certain amount of time in seconds.",
697
 
   (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
698
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
685
    "Require drizzleslap to run each specific test a certain amount of time in seconds.",
 
686
    (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
 
687
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
699
688
#ifndef DONT_ALLOW_USER_CHANGE
700
689
  {"user", 'u', "User for login if not current user.", (char**) &user,
701
 
   (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
690
    (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
702
691
#endif
703
692
  {"verbose", 'v',
704
 
   "More verbose output; you can use this multiple times to get even more "
705
 
   "verbose output.", (char**) &verbose, (char**) &verbose, 0,
706
 
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
693
    "More verbose output; you can use this multiple times to get even more "
 
694
      "verbose output.", (char**) &verbose, (char**) &verbose, 0,
 
695
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
707
696
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
708
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
697
    NO_ARG, 0, 0, 0, 0, 0, 0},
709
698
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
710
699
};
711
700
 
720
709
static void usage(void)
721
710
{
722
711
  print_version();
723
 
  puts("Copyright (C) 2008 Sun Microsystems");
 
712
  puts("Copyright (C) 2005 DRIZZLE AB");
724
713
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
725
714
       \nand you are welcome to modify and redistribute it under the GPL \
726
715
       license\n");
727
716
  puts("Run a query multiple times against the server\n");
728
717
  printf("Usage: %s [OPTIONS]\n",my_progname);
729
 
  print_defaults("drizzle",load_default_groups);
 
718
  print_defaults("my",load_default_groups);
730
719
  my_print_help(my_long_options);
731
720
}
732
721
 
733
722
static bool
734
 
get_one_option(int optid, const struct my_option *, char *argument)
 
723
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
 
724
               char *argument)
735
725
{
736
 
  char *endchar= NULL;
737
 
  uint64_t temp_drizzle_port= 0;
738
726
 
739
727
  switch(optid) {
740
728
  case 'v':
741
729
    verbose++;
742
730
    break;
743
731
  case 'p':
744
 
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
745
 
    /* if there is an alpha character this is not a valid port */
746
 
    if (strlen(endchar) != 0)
747
 
    {
748
 
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
749
 
      exit(1);
750
 
    }
751
 
    /* If the port number is > 65535 it is not a valid port
752
 
       This also helps with potential data loss casting unsigned long to a
753
 
       uint32_t. */
754
 
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
755
 
    {
756
 
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
757
 
      exit(1);
758
 
    }
759
 
    else
760
 
    {
761
 
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
762
 
    }
763
 
    break;
764
 
  case 'P':
765
732
    if (argument)
766
733
    {
767
734
      char *start= argument;
768
 
      if (opt_password)
769
 
        free(opt_password);
770
 
      opt_password = strdup(argument);
771
 
      if (opt_password == NULL)
772
 
      {
773
 
        fprintf(stderr, "Memory allocation error while copying password. "
774
 
                        "Aborting.\n");
775
 
        exit(ENOMEM);
776
 
      }
777
 
      while (*argument)
778
 
      {
779
 
        /* Overwriting password with 'x' */
780
 
        *argument++= 'x';
781
 
      }
 
735
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
 
736
      opt_password= my_strdup(argument,MYF(MY_FAE));
 
737
      while (*argument) *argument++= 'x';    /* Destroy argument */
782
738
      if (*start)
783
 
      {
784
 
        /* Cut length of argument */
785
 
        start[1]= 0;
786
 
      }
 
739
        start[1]= 0;        /* Cut length of argument */
787
740
      tty_password= 0;
788
741
    }
789
742
    else
826
779
  char       buf[HUGE_STRING_LENGTH];
827
780
  unsigned int        col_count;
828
781
  statement *ptr;
829
 
  string table_string;
830
 
 
831
 
  table_string.reserve(HUGE_STRING_LENGTH);
832
 
 
833
 
  table_string= "CREATE TABLE `t1` (";
 
782
  DYNAMIC_STRING table_string;
 
783
 
 
784
  init_dynamic_string(&table_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
785
 
 
786
  dynstr_append(&table_string, "CREATE TABLE `t1` (");
834
787
 
835
788
  if (auto_generate_sql_autoincrement)
836
789
  {
837
 
    table_string.append("id serial");
 
790
    dynstr_append(&table_string, "id serial");
838
791
 
839
792
    if (num_int_cols || num_char_cols)
840
 
      table_string.append(",");
 
793
      dynstr_append(&table_string, ",");
841
794
  }
842
795
 
843
796
  if (auto_generate_sql_guid_primary)
844
797
  {
845
 
    table_string.append("id varchar(128) primary key");
 
798
    dynstr_append(&table_string, "id varchar(128) primary key");
846
799
 
847
800
    if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
848
 
      table_string.append(",");
 
801
      dynstr_append(&table_string, ",");
849
802
  }
850
803
 
851
804
  if (auto_generate_sql_secondary_indexes)
855
808
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
856
809
    {
857
810
      if (count) /* Except for the first pass we add a comma */
858
 
        table_string.append(",");
 
811
        dynstr_append(&table_string, ",");
859
812
 
860
813
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
861
814
          > HUGE_STRING_LENGTH)
863
816
        fprintf(stderr, "Memory Allocation error in create table\n");
864
817
        exit(1);
865
818
      }
866
 
      table_string.append(buf);
 
819
      dynstr_append(&table_string, buf);
867
820
    }
868
821
 
869
822
    if (num_int_cols || num_char_cols)
870
 
      table_string.append(",");
 
823
      dynstr_append(&table_string, ",");
871
824
  }
872
825
 
873
826
  if (num_int_cols)
891
844
          exit(1);
892
845
        }
893
846
      }
894
 
      table_string.append(buf);
 
847
      dynstr_append(&table_string, buf);
895
848
 
896
849
      if (col_count < num_int_cols || num_char_cols > 0)
897
 
        table_string.append(",");
 
850
        dynstr_append(&table_string, ",");
898
851
    }
899
852
 
900
853
  if (num_char_cols)
919
872
          exit(1);
920
873
        }
921
874
      }
922
 
      table_string.append(buf);
 
875
      dynstr_append(&table_string, buf);
923
876
 
924
877
      if (col_count < num_char_cols || num_blob_cols > 0)
925
 
        table_string.append(",");
 
878
        dynstr_append(&table_string, ",");
926
879
    }
927
880
 
928
881
  if (num_blob_cols)
934
887
        fprintf(stderr, "Memory Allocation error in creating table\n");
935
888
        exit(1);
936
889
      }
937
 
      table_string.append(buf);
 
890
      dynstr_append(&table_string, buf);
938
891
 
939
892
      if (col_count < num_blob_cols)
940
 
        table_string.append(",");
 
893
        dynstr_append(&table_string, ",");
941
894
    }
942
895
 
943
 
  table_string.append(")");
944
 
  ptr= (statement *)malloc(sizeof(statement));
945
 
  if (ptr == NULL)
946
 
  {
947
 
    fprintf(stderr, "Memory Allocation error in creating table\n");
948
 
    exit(1);
949
 
  }
950
 
  memset(ptr, 0, sizeof(statement));
951
 
  ptr->string = (char *)malloc(table_string.length()+1);
952
 
  if (ptr->string == NULL)
953
 
  {
954
 
    fprintf(stderr, "Memory Allocation error in creating table\n");
955
 
    exit(1);
956
 
  }
957
 
  memset(ptr->string, 0, table_string.length()+1);
958
 
  ptr->length= table_string.length()+1;
 
896
  dynstr_append(&table_string, ")");
 
897
  ptr= (statement *)my_malloc(sizeof(statement),
 
898
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
899
  ptr->string = (char *)my_malloc(table_string.length+1,
 
900
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
901
  ptr->length= table_string.length+1;
959
902
  ptr->type= CREATE_TABLE_TYPE;
960
 
  strcpy(ptr->string, table_string.c_str());
 
903
  stpcpy(ptr->string, table_string.str);
 
904
  dynstr_free(&table_string);
961
905
  return(ptr);
962
906
}
963
907
 
973
917
  char       buf[HUGE_STRING_LENGTH];
974
918
  unsigned int        col_count;
975
919
  statement *ptr;
976
 
  string update_string;
977
 
 
978
 
  update_string.reserve(HUGE_STRING_LENGTH);
979
 
 
980
 
  update_string= "UPDATE t1 SET ";
 
920
  DYNAMIC_STRING update_string;
 
921
 
 
922
 
 
923
  init_dynamic_string(&update_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
924
 
 
925
  dynstr_append(&update_string, "UPDATE t1 SET ");
981
926
 
982
927
  if (num_int_cols)
983
928
    for (col_count= 1; col_count <= num_int_cols; col_count++)
988
933
        fprintf(stderr, "Memory Allocation error in creating update\n");
989
934
        exit(1);
990
935
      }
991
 
      update_string.append(buf);
 
936
      dynstr_append(&update_string, buf);
992
937
 
993
938
      if (col_count < num_int_cols || num_char_cols > 0)
994
 
        update_string.append(",", 1);
 
939
        dynstr_append_mem(&update_string, ",", 1);
995
940
    }
996
941
 
997
942
  if (num_char_cols)
1007
952
        fprintf(stderr, "Memory Allocation error in creating update\n");
1008
953
        exit(1);
1009
954
      }
1010
 
      update_string.append(buf);
 
955
      dynstr_append(&update_string, buf);
1011
956
 
1012
957
      if (col_count < num_char_cols)
1013
 
        update_string.append(",", 1);
 
958
        dynstr_append_mem(&update_string, ",", 1);
1014
959
    }
1015
960
 
1016
961
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1017
 
    update_string.append(" WHERE id = ");
1018
 
 
1019
 
 
1020
 
  ptr= (statement *)malloc(sizeof(statement));
1021
 
  if (ptr == NULL)
1022
 
  {
1023
 
    fprintf(stderr, "Memory Allocation error in creating update\n");
1024
 
    exit(1);
1025
 
  }
1026
 
  memset(ptr, 0, sizeof(statement));
1027
 
 
1028
 
  ptr->length= update_string.length()+1;
1029
 
  ptr->string= (char *)malloc(ptr->length);
1030
 
  if (ptr->string == NULL)
1031
 
  {
1032
 
    fprintf(stderr, "Memory Allocation error in creating update\n");
1033
 
    exit(1);
1034
 
  }
1035
 
  memset(ptr->string, 0, ptr->length);
 
962
    dynstr_append(&update_string, " WHERE id = ");
 
963
 
 
964
 
 
965
  ptr= (statement *)my_malloc(sizeof(statement),
 
966
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
967
 
 
968
  ptr->string= (char *)my_malloc(update_string.length + 1,
 
969
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
970
  ptr->length= update_string.length+1;
1036
971
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1037
972
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
1038
973
  else
1039
974
    ptr->type= UPDATE_TYPE;
1040
 
  strncpy(ptr->string, update_string.c_str(), ptr->length);
 
975
  stpcpy(ptr->string, update_string.str);
 
976
  dynstr_free(&update_string);
1041
977
  return(ptr);
1042
978
}
1043
979
 
1054
990
  char       buf[HUGE_STRING_LENGTH];
1055
991
  unsigned int        col_count;
1056
992
  statement *ptr;
1057
 
  string insert_string;
1058
 
 
1059
 
  insert_string.reserve(HUGE_STRING_LENGTH);
1060
 
 
1061
 
  insert_string= "INSERT INTO t1 VALUES (";
 
993
  DYNAMIC_STRING insert_string;
 
994
 
 
995
 
 
996
  init_dynamic_string(&insert_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
997
 
 
998
  dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
1062
999
 
1063
1000
  if (auto_generate_sql_autoincrement)
1064
1001
  {
1065
 
    insert_string.append("NULL");
 
1002
    dynstr_append(&insert_string, "NULL");
1066
1003
 
1067
1004
    if (num_int_cols || num_char_cols)
1068
 
      insert_string.append(",");
 
1005
      dynstr_append(&insert_string, ",");
1069
1006
  }
1070
1007
 
1071
1008
  if (auto_generate_sql_guid_primary)
1072
1009
  {
1073
 
    insert_string.append("uuid()");
 
1010
    dynstr_append(&insert_string, "uuid()");
1074
1011
 
1075
1012
    if (num_int_cols || num_char_cols)
1076
 
      insert_string.append(",");
 
1013
      dynstr_append(&insert_string, ",");
1077
1014
  }
1078
1015
 
1079
1016
  if (auto_generate_sql_secondary_indexes)
1083
1020
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1084
1021
    {
1085
1022
      if (count) /* Except for the first pass we add a comma */
1086
 
        insert_string.append(",");
 
1023
        dynstr_append(&insert_string, ",");
1087
1024
 
1088
 
      insert_string.append("uuid()");
 
1025
      dynstr_append(&insert_string, "uuid()");
1089
1026
    }
1090
1027
 
1091
1028
    if (num_int_cols || num_char_cols)
1092
 
      insert_string.append(",");
 
1029
      dynstr_append(&insert_string, ",");
1093
1030
  }
1094
1031
 
1095
1032
  if (num_int_cols)
1100
1037
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1101
1038
        exit(1);
1102
1039
      }
1103
 
      insert_string.append(buf);
 
1040
      dynstr_append(&insert_string, buf);
1104
1041
 
1105
1042
      if (col_count < num_int_cols || num_char_cols > 0)
1106
 
        insert_string.append(",");
 
1043
        dynstr_append_mem(&insert_string, ",", 1);
1107
1044
    }
1108
1045
 
1109
1046
  if (num_char_cols)
1110
1047
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1111
1048
    {
1112
1049
      int buf_len= get_random_string(buf, RAND_STRING_SIZE);
1113
 
      insert_string.append("'", 1);
1114
 
      insert_string.append(buf, buf_len);
1115
 
      insert_string.append("'", 1);
 
1050
      dynstr_append_mem(&insert_string, "'", 1);
 
1051
      dynstr_append_mem(&insert_string, buf, buf_len);
 
1052
      dynstr_append_mem(&insert_string, "'", 1);
1116
1053
 
1117
1054
      if (col_count < num_char_cols || num_blob_cols > 0)
1118
 
        insert_string.append(",", 1);
 
1055
        dynstr_append_mem(&insert_string, ",", 1);
1119
1056
    }
1120
1057
 
1121
1058
  if (num_blob_cols)
1124
1061
 
1125
1062
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1126
1063
    {
1127
 
      blob_ptr= (char *)malloc(sizeof(char)*num_blob_cols_size);
 
1064
      blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
 
1065
                             MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1128
1066
      if (!blob_ptr)
1129
1067
      {
1130
1068
        fprintf(stderr, "Memory Allocation error in creating select\n");
1131
1069
        exit(1);
1132
1070
      }
1133
 
      memset(blob_ptr, 0, sizeof(char)*num_blob_cols_size);
1134
1071
    }
1135
1072
    else
1136
1073
    {
1144
1081
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1145
1082
 
1146
1083
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1147
 
        num_blob_cols_size;
 
1084
                          num_blob_cols_size;
1148
1085
 
1149
1086
      buf_len= get_random_string(blob_ptr, size);
1150
1087
 
1151
 
      insert_string.append("'", 1);
1152
 
      insert_string.append(blob_ptr, buf_len);
1153
 
      insert_string.append("'", 1);
 
1088
      dynstr_append_mem(&insert_string, "'", 1);
 
1089
      dynstr_append_mem(&insert_string, blob_ptr, buf_len);
 
1090
      dynstr_append_mem(&insert_string, "'", 1);
1154
1091
 
1155
1092
      if (col_count < num_blob_cols)
1156
 
        insert_string.append(",", 1);
 
1093
        dynstr_append_mem(&insert_string, ",", 1);
1157
1094
    }
1158
1095
 
1159
1096
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1160
 
      free(blob_ptr);
1161
 
  }
1162
 
 
1163
 
  insert_string.append(")", 1);
1164
 
 
1165
 
  if (!(ptr= (statement *)malloc(sizeof(statement))))
1166
 
  {
1167
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1168
 
    exit(1);
1169
 
  }
1170
 
  memset(ptr, 0, sizeof(statement));
1171
 
  ptr->length= insert_string.length()+1;
1172
 
  if (!(ptr->string= (char *)malloc(ptr->length)))
1173
 
  {
1174
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1175
 
    exit(1);
1176
 
  }
1177
 
  memset(ptr->string, 0, ptr->length);
 
1097
      my_free(blob_ptr, MYF(0));
 
1098
  }
 
1099
 
 
1100
  dynstr_append_mem(&insert_string, ")", 1);
 
1101
 
 
1102
  if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
 
1103
  {
 
1104
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1105
    exit(1);
 
1106
  }
 
1107
  if (!(ptr->string= (char *)my_malloc(insert_string.length + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
 
1108
  {
 
1109
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1110
    exit(1);
 
1111
  }
 
1112
  ptr->length= insert_string.length+1;
1178
1113
  ptr->type= INSERT_TYPE;
1179
 
  strcpy(ptr->string, insert_string.c_str());
 
1114
  stpcpy(ptr->string, insert_string.str);
 
1115
  dynstr_free(&insert_string);
 
1116
 
1180
1117
  return(ptr);
1181
1118
}
1182
1119
 
1193
1130
  char       buf[HUGE_STRING_LENGTH];
1194
1131
  unsigned int        col_count;
1195
1132
  statement *ptr;
1196
 
  string query_string;
1197
 
 
1198
 
  query_string.reserve(HUGE_STRING_LENGTH);
1199
 
 
1200
 
  query_string.append("SELECT ", 7);
 
1133
  static DYNAMIC_STRING query_string;
 
1134
 
 
1135
 
 
1136
  init_dynamic_string(&query_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
 
1137
 
 
1138
  dynstr_append_mem(&query_string, "SELECT ", 7);
1201
1139
  if (auto_generate_selected_columns_opt)
1202
1140
  {
1203
 
    query_string.append(auto_generate_selected_columns_opt);
 
1141
    dynstr_append(&query_string, auto_generate_selected_columns_opt);
1204
1142
  }
1205
1143
  else
1206
1144
  {
1212
1150
        fprintf(stderr, "Memory Allocation error in creating select\n");
1213
1151
        exit(1);
1214
1152
      }
1215
 
      query_string.append(buf);
 
1153
      dynstr_append(&query_string, buf);
1216
1154
 
1217
1155
      if (col_count < num_int_cols || num_char_cols > 0)
1218
 
        query_string.append(",", 1);
 
1156
        dynstr_append_mem(&query_string, ",", 1);
1219
1157
 
1220
1158
    }
1221
1159
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1226
1164
        fprintf(stderr, "Memory Allocation error in creating select\n");
1227
1165
        exit(1);
1228
1166
      }
1229
 
      query_string.append(buf);
 
1167
      dynstr_append(&query_string, buf);
1230
1168
 
1231
1169
      if (col_count < num_char_cols || num_blob_cols > 0)
1232
 
        query_string.append(",", 1);
 
1170
        dynstr_append_mem(&query_string, ",", 1);
1233
1171
 
1234
1172
    }
1235
1173
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1240
1178
        fprintf(stderr, "Memory Allocation error in creating select\n");
1241
1179
        exit(1);
1242
1180
      }
1243
 
      query_string.append(buf);
 
1181
      dynstr_append(&query_string, buf);
1244
1182
 
1245
1183
      if (col_count < num_blob_cols)
1246
 
        query_string.append(",", 1);
 
1184
        dynstr_append_mem(&query_string, ",", 1);
1247
1185
    }
1248
1186
  }
1249
 
  query_string.append(" FROM t1");
 
1187
  dynstr_append(&query_string, " FROM t1");
1250
1188
 
1251
1189
  if ((key) &&
1252
1190
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1253
 
    query_string.append(" WHERE id = ");
 
1191
    dynstr_append(&query_string, " WHERE id = ");
1254
1192
 
1255
 
  ptr= (statement *)malloc(sizeof(statement));
1256
 
  if (ptr == NULL)
1257
 
  {
1258
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1259
 
    exit(1);
1260
 
  }
1261
 
  memset(ptr, 0, sizeof(statement));
1262
 
  ptr->length= query_string.length()+1;
1263
 
  ptr->string= (char *)malloc(ptr->length);
1264
 
  if (ptr->string == NULL)
1265
 
  {
1266
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1267
 
    exit(1);
1268
 
  }
1269
 
  memset(ptr->string, 0, ptr->length);
 
1193
  ptr= (statement *)my_malloc(sizeof(statement),
 
1194
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1195
  ptr->string= (char *)my_malloc(query_string.length + 1,
 
1196
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1197
  ptr->length= query_string.length+1;
1270
1198
  if ((key) &&
1271
1199
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1272
1200
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1273
1201
  else
1274
1202
    ptr->type= SELECT_TYPE;
1275
 
  strcpy(ptr->string, query_string.c_str());
 
1203
  stpcpy(ptr->string, query_string.str);
 
1204
  dynstr_free(&query_string);
1276
1205
  return(ptr);
1277
1206
}
1278
1207
 
1302
1231
 
1303
1232
  if (auto_generate_sql && (create_string || user_supplied_query))
1304
1233
  {
1305
 
    fprintf(stderr,
1306
 
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1307
 
            my_progname);
1308
 
    exit(1);
 
1234
      fprintf(stderr,
 
1235
              "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
 
1236
              my_progname);
 
1237
      exit(1);
1309
1238
  }
1310
1239
 
1311
1240
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1312
1241
      auto_generate_sql_autoincrement)
1313
1242
  {
1314
 
    fprintf(stderr,
1315
 
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1316
 
            my_progname);
1317
 
    exit(1);
 
1243
      fprintf(stderr,
 
1244
              "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
 
1245
              my_progname);
 
1246
      exit(1);
1318
1247
  }
1319
1248
 
1320
1249
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1321
1250
  {
1322
 
    fprintf(stderr,
1323
 
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1324
 
            my_progname);
1325
 
    exit(1);
 
1251
      fprintf(stderr,
 
1252
              "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
 
1253
              my_progname);
 
1254
      exit(1);
1326
1255
  }
1327
1256
 
1328
1257
  parse_comma(concurrency_str ? concurrency_str : "1", &concurrency);
1330
1259
  if (opt_csv_str)
1331
1260
  {
1332
1261
    opt_silent= true;
1333
 
 
 
1262
   
1334
1263
    if (opt_csv_str[0] == '-')
1335
1264
    {
1336
1265
      csv_file= fileno(stdout);
1402
1331
 
1403
1332
  if (auto_generate_sql)
1404
1333
  {
1405
 
    uint64_t x= 0;
 
1334
    unsigned long long x= 0;
1406
1335
    statement *ptr_statement;
1407
1336
 
1408
1337
    if (verbose >= 2)
1428
1357
    query_statements_count=
1429
1358
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1430
1359
 
1431
 
    query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
1432
 
    if (query_statements == NULL)
1433
 
    {
1434
 
      fprintf(stderr, "Memory Allocation error in Building Query Statements\n");
1435
 
      exit(1);
1436
 
    }
1437
 
    memset(query_statements, 0, sizeof(statement *) * query_statements_count);
 
1360
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
 
1361
                                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1438
1362
 
1439
1363
    sql_type= query_options;
1440
1364
    do
1554
1478
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1555
1479
        exit(1);
1556
1480
      }
1557
 
      tmp_string= (char *)malloc(sbuf.st_size + 1);
1558
 
      if (tmp_string == NULL)
1559
 
      {
1560
 
        fprintf(stderr, "Memory Allocation error in option processing\n");
1561
 
        exit(1);
1562
 
      }
1563
 
      memset(tmp_string, 0, sbuf.st_size + 1);
1564
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1481
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
 
1482
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1483
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1565
1484
      tmp_string[sbuf.st_size]= '\0';
1566
1485
      my_close(data_file,MYF(0));
1567
1486
      parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1568
 
      free(tmp_string);
 
1487
      my_free(tmp_string, MYF(0));
1569
1488
    }
1570
1489
    else if (create_string)
1571
1490
    {
1572
 
      parse_delimiter(create_string, &create_statements, delimiter[0]);
 
1491
        parse_delimiter(create_string, &create_statements, delimiter[0]);
1573
1492
    }
1574
1493
 
1575
1494
    /* Set this up till we fully support options on user generated queries */
1578
1497
      query_statements_count=
1579
1498
        parse_option("default", &query_options, ',');
1580
1499
 
1581
 
      query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
1582
 
      if (query_statements == NULL)
1583
 
      {
1584
 
        fprintf(stderr, "Memory Allocation error in option processing\n");
1585
 
        exit(1);
1586
 
      }
1587
 
      memset(query_statements, 0, sizeof(statement *) * query_statements_count); 
 
1500
      query_statements= (statement **)my_malloc(sizeof(statement *),
 
1501
                                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1588
1502
    }
1589
1503
 
1590
1504
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1601
1515
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1602
1516
        exit(1);
1603
1517
      }
1604
 
      tmp_string= (char *)malloc(sbuf.st_size + 1);
1605
 
      if (tmp_string == NULL)
1606
 
      {
1607
 
        fprintf(stderr, "Memory Allocation error in option processing\n");
1608
 
        exit(1);
1609
 
      }
1610
 
      memset(tmp_string, 0, sbuf.st_size + 1);
1611
 
      my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1518
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
 
1519
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1520
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1612
1521
      tmp_string[sbuf.st_size]= '\0';
1613
1522
      my_close(data_file,MYF(0));
1614
1523
      if (user_supplied_query)
1615
1524
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1616
1525
                                        delimiter[0]);
1617
 
      free(tmp_string);
 
1526
      my_free(tmp_string, MYF(0));
1618
1527
    }
1619
1528
    else if (user_supplied_query)
1620
1529
    {
1638
1547
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1639
1548
      exit(1);
1640
1549
    }
1641
 
    tmp_string= (char *)malloc(sbuf.st_size + 1);
1642
 
    if (tmp_string == NULL)
1643
 
    {
1644
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
1645
 
      exit(1);
1646
 
    }
1647
 
    memset(tmp_string, 0, sbuf.st_size + 1);
1648
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1550
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
 
1551
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1552
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1649
1553
    tmp_string[sbuf.st_size]= '\0';
1650
1554
    my_close(data_file,MYF(0));
1651
1555
    if (user_supplied_pre_statements)
1652
1556
      (void)parse_delimiter(tmp_string, &pre_statements,
1653
1557
                            delimiter[0]);
1654
 
    free(tmp_string);
 
1558
    my_free(tmp_string, MYF(0));
1655
1559
  }
1656
1560
  else if (user_supplied_pre_statements)
1657
1561
  {
1675
1579
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1676
1580
      exit(1);
1677
1581
    }
1678
 
    tmp_string= (char *)malloc(sbuf.st_size + 1);
1679
 
    if (tmp_string == NULL)
1680
 
    {
1681
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
1682
 
      exit(1);
1683
 
    }
1684
 
    memset(tmp_string, 0, sbuf.st_size+1);
1685
 
    my_read(data_file, (unsigned char*) tmp_string, sbuf.st_size, MYF(0));
 
1582
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
 
1583
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1584
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
1686
1585
    tmp_string[sbuf.st_size]= '\0';
1687
1586
    my_close(data_file,MYF(0));
1688
1587
    if (user_supplied_post_statements)
1689
1588
      (void)parse_delimiter(tmp_string, &post_statements,
1690
1589
                            delimiter[0]);
1691
 
    free(tmp_string);
 
1590
    my_free(tmp_string, MYF(0));
1692
1591
  }
1693
1592
  else if (user_supplied_post_statements)
1694
1593
  {
1703
1602
    parse_option(default_engine, &engine_options, ',');
1704
1603
 
1705
1604
  if (tty_password)
1706
 
    opt_password= get_tty_password(NULL);
 
1605
    opt_password= get_tty_password(NullS);
1707
1606
  return(0);
1708
1607
}
1709
1608
 
1727
1626
{
1728
1627
  DRIZZLE_RES *result;
1729
1628
  DRIZZLE_ROW row;
1730
 
  uint64_t counter;
 
1629
  unsigned long long counter;
1731
1630
 
1732
1631
 
1733
1632
  /*
1738
1637
                         strstr(engine_stmt->string, "blackhole")))
1739
1638
  {
1740
1639
    primary_keys_number_of= 1;
1741
 
    primary_keys= (char **)malloc((sizeof(char *) *
1742
 
                                  primary_keys_number_of));
1743
 
    if (primary_keys == NULL)
1744
 
    {
1745
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
1746
 
      exit(1);
1747
 
    }
1748
 
    
1749
 
    memset(primary_keys, 0, (sizeof(char *) * primary_keys_number_of));
 
1640
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
 
1641
                                            primary_keys_number_of),
 
1642
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1750
1643
    /* Yes, we strdup a const string to simplify the interface */
1751
 
    primary_keys[0]= strdup("796c4422-1d94-102a-9d6d-00e0812d");
1752
 
    if (primary_keys[0] == NULL)
1753
 
    {
1754
 
      fprintf(stderr, "Memory Allocation error in option processing\n");
1755
 
      exit(1);
1756
 
    }
 
1644
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1757
1645
  }
1758
1646
  else
1759
1647
  {
1773
1661
      /*
1774
1662
        We create the structure and loop and create the items.
1775
1663
      */
1776
 
      primary_keys= (char **)malloc(sizeof(char *) *
1777
 
                                    primary_keys_number_of);
1778
 
      if (primary_keys == NULL)
1779
 
      {
1780
 
        fprintf(stderr, "Memory Allocation error in option processing\n");
1781
 
        exit(1);
1782
 
      }
1783
 
      memset(primary_keys, 0, sizeof(char *) * primary_keys_number_of);
 
1664
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
 
1665
                                              primary_keys_number_of),
 
1666
                                       MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1784
1667
      row= drizzle_fetch_row(result);
1785
1668
      for (counter= 0; counter < primary_keys_number_of;
1786
1669
           counter++, row= drizzle_fetch_row(result))
1787
 
      {
1788
 
        primary_keys[counter]= strdup(row[0]);
1789
 
        if (primary_keys[counter] == NULL)
1790
 
        {
1791
 
          fprintf(stderr, "Memory Allocation error in option processing\n");
1792
 
          exit(1);
1793
 
        }
1794
 
      }
 
1670
        primary_keys[counter]= my_strdup(row[0], MYF(0));
1795
1671
    }
1796
1672
 
1797
1673
    drizzle_free_result(result);
1803
1679
static int
1804
1680
drop_primary_key_list(void)
1805
1681
{
1806
 
  uint64_t counter;
 
1682
  unsigned long long counter;
1807
1683
 
1808
1684
  if (primary_keys_number_of)
1809
1685
  {
1810
1686
    for (counter= 0; counter < primary_keys_number_of; counter++)
1811
 
      free(primary_keys[counter]);
 
1687
      my_free(primary_keys[counter], MYF(0));
1812
1688
 
1813
 
    free(primary_keys);
 
1689
    my_free(primary_keys, MYF(0));
1814
1690
  }
1815
1691
 
1816
1692
  return 0;
1991
1867
 
1992
1868
  pthread_attr_init(&attr);
1993
1869
  pthread_attr_setdetachstate(&attr,
1994
 
                              PTHREAD_CREATE_DETACHED);
 
1870
      PTHREAD_CREATE_DETACHED);
1995
1871
 
1996
1872
  pthread_mutex_lock(&counter_mutex);
1997
1873
  thread_counter= 0;
2018
1894
    while (options_loop--)
2019
1895
      for (x= 0; x < concur; x++)
2020
1896
      {
2021
 
        con= (thread_context *)malloc(sizeof(thread_context));
2022
 
        if (con == NULL)
2023
 
        {
2024
 
          fprintf(stderr, "Memory Allocation error in scheduler\n");
2025
 
          exit(1);
2026
 
        }
 
1897
        con= (thread_context *)my_malloc(sizeof(thread_context), MYF(0));
2027
1898
        con->stmt= stmts[y];
2028
1899
        con->limit= limit;
2029
1900
 
2098
1969
  struct timespec abstime;
2099
1970
 
2100
1971
 
 
1972
 
 
1973
  if (drizzle_thread_init())
 
1974
  {
 
1975
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
 
1976
            my_progname);
 
1977
    exit(1);
 
1978
  }
 
1979
 
2101
1980
  /*
2102
1981
    We lock around the initial call in case were we in a loop. This
2103
1982
    also keeps the value properly syncronized across call threads.
2119
1998
  timer_alarm= false;
2120
1999
  pthread_mutex_unlock(&timer_alarm_mutex);
2121
2000
 
 
2001
  drizzle_thread_end();
2122
2002
  return(0);
2123
2003
}
2124
2004
 
2133
2013
  statement *ptr;
2134
2014
  thread_context *con= (thread_context *)p;
2135
2015
 
 
2016
  if (drizzle_thread_init())
 
2017
  {
 
2018
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
 
2019
            my_progname);
 
2020
    exit(1);
 
2021
  }
 
2022
 
2136
2023
  pthread_mutex_lock(&sleeper_mutex);
2137
2024
  while (master_wakeup)
2138
2025
  {
2151
2038
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2152
2039
 
2153
2040
limit_not_met:
2154
 
  for (ptr= con->stmt, detach_counter= 0;
2155
 
       ptr && ptr->length;
2156
 
       ptr= ptr->next, detach_counter++)
2157
 
  {
2158
 
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2159
 
    {
2160
 
      slap_close(&drizzle);
2161
 
      slap_connect(&drizzle, true);
2162
 
    }
2163
 
 
2164
 
    /*
2165
 
      We have to execute differently based on query type. This should become a function.
2166
 
    */
2167
 
    if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
2168
 
        (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
2169
 
    {
2170
 
      int length;
2171
 
      unsigned int key_val;
2172
 
      char *key;
2173
 
      char buffer[HUGE_STRING_LENGTH];
 
2041
    for (ptr= con->stmt, detach_counter= 0;
 
2042
         ptr && ptr->length;
 
2043
         ptr= ptr->next, detach_counter++)
 
2044
    {
 
2045
      if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
2046
      {
 
2047
        slap_close(&drizzle);
 
2048
        slap_connect(&drizzle, true);
 
2049
      }
2174
2050
 
2175
2051
      /*
2176
 
        This should only happen if some sort of new engine was
2177
 
        implemented that didn't properly handle UPDATEs.
2178
 
 
2179
 
        Just in case someone runs this under an experimental engine we don't
2180
 
        want a crash so the if() is placed here.
 
2052
        We have to execute differently based on query type. This should become a function.
2181
2053
      */
2182
 
      assert(primary_keys_number_of);
2183
 
      if (primary_keys_number_of)
2184
 
      {
2185
 
        key_val= (unsigned int)(random() % primary_keys_number_of);
2186
 
        key= primary_keys[key_val];
2187
 
 
2188
 
        assert(key);
2189
 
 
2190
 
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2191
 
                         (int)ptr->length, ptr->string, key);
2192
 
 
2193
 
        if (run_query(&drizzle, buffer, length))
 
2054
      if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
2055
          (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
 
2056
      {
 
2057
        int length;
 
2058
        unsigned int key_val;
 
2059
        char *key;
 
2060
        char buffer[HUGE_STRING_LENGTH];
 
2061
 
 
2062
        /*
 
2063
          This should only happen if some sort of new engine was
 
2064
          implemented that didn't properly handle UPDATEs.
 
2065
 
 
2066
          Just in case someone runs this under an experimental engine we don't
 
2067
          want a crash so the if() is placed here.
 
2068
        */
 
2069
        assert(primary_keys_number_of);
 
2070
        if (primary_keys_number_of)
 
2071
        {
 
2072
          key_val= (unsigned int)(random() % primary_keys_number_of);
 
2073
          key= primary_keys[key_val];
 
2074
 
 
2075
          assert(key);
 
2076
 
 
2077
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
 
2078
                           (int)ptr->length, ptr->string, key);
 
2079
 
 
2080
          if (run_query(&drizzle, buffer, length))
 
2081
          {
 
2082
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2083
                    my_progname, (uint)length, buffer, drizzle_error(&drizzle));
 
2084
            exit(1);
 
2085
          }
 
2086
        }
 
2087
      }
 
2088
      else
 
2089
      {
 
2090
        if (run_query(&drizzle, ptr->string, ptr->length))
2194
2091
        {
2195
2092
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2196
 
                  my_progname, (uint)length, buffer, drizzle_error(&drizzle));
 
2093
                  my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
2197
2094
          exit(1);
2198
2095
        }
2199
2096
      }
2200
 
    }
2201
 
    else
2202
 
    {
2203
 
      if (run_query(&drizzle, ptr->string, ptr->length))
2204
 
      {
2205
 
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2206
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
2207
 
        exit(1);
2208
 
      }
2209
 
    }
2210
2097
 
2211
 
    if (!opt_only_print)
2212
 
    {
2213
 
      do
 
2098
      if (!opt_only_print)
2214
2099
      {
2215
 
        if (drizzle_field_count(&drizzle))
 
2100
        do
2216
2101
        {
2217
 
          result= drizzle_store_result(&drizzle);
2218
 
          while ((row = drizzle_fetch_row(result)))
2219
 
            counter++;
2220
 
          drizzle_free_result(result);
2221
 
        }
2222
 
      } while(drizzle_next_result(&drizzle) == 0);
2223
 
    }
2224
 
    queries++;
2225
 
 
2226
 
    if (commit_rate && (++commit_counter == commit_rate))
2227
 
    {
2228
 
      commit_counter= 0;
2229
 
      run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2230
 
    }
2231
 
 
2232
 
    /* If the timer is set, and the alarm is not active then end */
2233
 
    if (opt_timer_length && timer_alarm == false)
2234
 
      goto end;
2235
 
 
2236
 
    /* If limit has been reached, and we are not in a timer_alarm just end */
2237
 
    if (con->limit && queries == con->limit && timer_alarm == false)
2238
 
      goto end;
2239
 
  }
2240
 
 
2241
 
  if (opt_timer_length && timer_alarm == true)
2242
 
    goto limit_not_met;
2243
 
 
2244
 
  if (con->limit && queries < con->limit)
2245
 
    goto limit_not_met;
 
2102
          if (drizzle_field_count(&drizzle))
 
2103
          {
 
2104
            result= drizzle_store_result(&drizzle);
 
2105
            while ((row = drizzle_fetch_row(result)))
 
2106
              counter++;
 
2107
            drizzle_free_result(result);
 
2108
          }
 
2109
        } while(drizzle_next_result(&drizzle) == 0);
 
2110
      }
 
2111
      queries++;
 
2112
 
 
2113
      if (commit_rate && (++commit_counter == commit_rate))
 
2114
      {
 
2115
        commit_counter= 0;
 
2116
        run_query(&drizzle, "COMMIT", strlen("COMMIT"));
 
2117
      }
 
2118
 
 
2119
      /* If the timer is set, and the alarm is not active then end */
 
2120
      if (opt_timer_length && timer_alarm == false)
 
2121
        goto end;
 
2122
 
 
2123
      /* If limit has been reached, and we are not in a timer_alarm just end */
 
2124
      if (con->limit && queries == con->limit && timer_alarm == false)
 
2125
        goto end;
 
2126
    }
 
2127
 
 
2128
    if (opt_timer_length && timer_alarm == true)
 
2129
      goto limit_not_met;
 
2130
 
 
2131
    if (con->limit && queries < con->limit)
 
2132
      goto limit_not_met;
2246
2133
 
2247
2134
 
2248
2135
end:
2256
2143
  pthread_cond_signal(&count_threshhold);
2257
2144
  pthread_mutex_unlock(&counter_mutex);
2258
2145
 
2259
 
  free(con);
 
2146
  my_free(con, MYF(0));
2260
2147
 
 
2148
  drizzle_thread_end();
2261
2149
  return(0);
2262
2150
}
2263
2151
 
2278
2166
 
2279
2167
  end_ptr= (char *)origin + length;
2280
2168
 
2281
 
  tmp= *sptr= (option_string *)malloc(sizeof(option_string));
2282
 
  if (tmp == NULL)
2283
 
  {
2284
 
    fprintf(stderr,"Error allocating memory while parsing options\n");
2285
 
    exit(1);
2286
 
  }
2287
 
  memset(tmp, 0, sizeof(option_string));
 
2169
  tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
 
2170
                                         MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2288
2171
 
2289
2172
  for (begin_ptr= (char *)origin;
2290
2173
       begin_ptr != end_ptr;
2317
2200
 
2318
2201
      /* Move past the : and the first string */
2319
2202
      tmp->option_length= strlen(buffer_ptr);
2320
 
      tmp->option= (char *)malloc(tmp->option_length + 1);
2321
 
      if (tmp->option == NULL)
2322
 
      {
2323
 
        fprintf(stderr,"Error allocating memory while parsing options\n");
2324
 
        exit(1);
2325
 
      }
2326
 
      memcpy(tmp->option, buffer_ptr, tmp->option_length);
2327
 
      tmp->option[tmp->option_length]= 0; 
 
2203
      tmp->option= my_strndup(buffer_ptr, (uint)tmp->option_length,
 
2204
                              MYF(MY_FAE));
2328
2205
    }
2329
2206
 
 
2207
    tmp->string= my_strndup(buffer, strlen(buffer), MYF(MY_FAE));
2330
2208
    tmp->length= strlen(buffer);
2331
 
    tmp->string= strdup(buffer);
2332
 
    if (tmp->string == NULL)
2333
 
    {
2334
 
      fprintf(stderr,"Error allocating memory while parsing options\n");
2335
 
      exit(1);
2336
 
    }
2337
2209
 
2338
2210
    if (isspace(*begin_ptr))
2339
2211
      begin_ptr++;
2341
2213
    count++;
2342
2214
 
2343
2215
    if (begin_ptr != end_ptr)
2344
 
    {
2345
 
      tmp->next= (option_string *)malloc(sizeof(option_string));
2346
 
      if (tmp->next == NULL)
2347
 
      {
2348
 
        fprintf(stderr,"Error allocating memory while parsing options\n");
2349
 
        exit(1);
2350
 
      }
2351
 
      memset(tmp->next, 0, sizeof(option_string));
2352
 
    }
2353
 
    
 
2216
      tmp->next= (option_string *)my_malloc(sizeof(option_string),
 
2217
                                            MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2354
2218
  }
2355
2219
 
2356
2220
  return count;
2371
2235
  uint length= strlen(script);
2372
2236
  uint count= 0; /* We know that there is always one */
2373
2237
 
2374
 
  for (tmp= *sptr= (statement *)malloc(sizeof(statement));
 
2238
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
 
2239
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2375
2240
       (retstr= strchr(ptr, delm));
2376
 
       tmp->next=  (statement *)malloc(sizeof(statement)),
 
2241
       tmp->next=  (statement *)my_malloc(sizeof(statement),
 
2242
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2377
2243
       tmp= tmp->next)
2378
2244
  {
2379
 
    memset(tmp, 0, sizeof(statement));
2380
2245
    count++;
 
2246
    tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2381
2247
    tmp->length= (size_t)(retstr - ptr);
2382
 
    tmp->string= (char *)malloc(tmp->length + 1);
2383
 
    if (tmp->string == NULL)
2384
 
    {
2385
 
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2386
 
      exit(1);
2387
 
    }
2388
 
    memcpy(tmp->string, ptr, tmp->length);
2389
 
    tmp->string[tmp->length]= 0;
2390
2248
    ptr+= retstr - ptr + 1;
2391
2249
    if (isspace(*ptr))
2392
2250
      ptr++;
2394
2252
 
2395
2253
  if (ptr != script+length)
2396
2254
  {
 
2255
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
 
2256
                                       MYF(MY_FAE));
2397
2257
    tmp->length= (size_t)((script + length) - ptr);
2398
 
    tmp->string= (char *)malloc(tmp->length + 1);
2399
 
    if (tmp->string == NULL)
2400
 
    {
2401
 
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2402
 
      exit(1);
2403
 
    }
2404
 
    memcpy(tmp->string, ptr, tmp->length);
2405
 
    tmp->string[tmp->length]= 0;
2406
2258
    count++;
2407
2259
  }
2408
2260
 
2418
2270
uint
2419
2271
parse_comma(const char *string, uint **range)
2420
2272
{
2421
 
  unsigned int count= 1,x; /* We know that there is always one */
 
2273
  uint count= 1,x; /* We know that there is always one */
2422
2274
  char *retstr;
2423
2275
  char *ptr= (char *)string;
2424
 
  unsigned int *nptr;
 
2276
  uint *nptr;
2425
2277
 
2426
2278
  for (;*ptr; ptr++)
2427
2279
    if (*ptr == ',') count++;
2428
 
 
 
2280
 
2429
2281
  /* One extra spot for the NULL */
2430
 
  nptr= *range= (uint *)malloc(sizeof(unsigned int) * (count + 1));
2431
 
  memset(nptr, 0, sizeof(unsigned int) * (count + 1));
 
2282
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
 
2283
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2432
2284
 
2433
2285
  ptr= (char *)string;
2434
2286
  x= 0;
2447
2299
{
2448
2300
  printf("Benchmark\n");
2449
2301
  if (con->engine)
2450
 
    printf("\tRunning for engine %s\n", con->engine);
 
2302
      printf("\tRunning for engine %s\n", con->engine);
2451
2303
  if (opt_label || opt_auto_generate_sql_type)
2452
2304
  {
2453
2305
    const char *ptr= opt_auto_generate_sql_type ? opt_auto_generate_sql_type : "query";
2464
2316
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2465
2317
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2466
2318
  printf("\tStandard Deviation: %ld.%03ld\n", con->std_dev / 1000, con->std_dev % 1000);
2467
 
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->create_count);
 
2319
  printf("\tNumber of queries in create queries: %llu\n", con->create_count);
2468
2320
  printf("\tNumber of clients running queries: %u/%u\n",
2469
2321
         con->users, con->real_users);
2470
2322
  printf("\tNumber of times test was run: %u\n", iterations);
2471
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->avg_rows);
 
2323
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows);
2472
2324
  printf("\n");
2473
2325
}
2474
2326
 
2510
2362
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
2511
2363
 
2512
2364
  snprintf(buffer, HUGE_STRING_LENGTH,
2513
 
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2514
 
           "%u,%u,%u,%"PRIu64"\n",
 
2365
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%u,%u,%u,%llu\n",
2515
2366
           con->engine ? con->engine : "", /* Storage engine we ran against */
2516
2367
           label_buffer, /* Load type */
2517
2368
           con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
2523
2374
           con->users, /* Children used max_timing */
2524
2375
           con->real_users, /* Children used max_timing */
2525
2376
           con->avg_rows  /* Queries run */
2526
 
           );
2527
 
  my_write(csv_file, (unsigned char*) buffer, (uint)strlen(buffer), MYF(0));
 
2377
          );
 
2378
  my_write(csv_file, (uchar*) buffer, (uint)strlen(buffer), MYF(0));
2528
2379
}
2529
2380
 
2530
2381
void
2537
2388
  con->max_timing= sptr->timing;
2538
2389
  con->min_rows= sptr->rows;
2539
2390
  con->max_rows= sptr->rows;
2540
 
 
 
2391
 
2541
2392
  /* At the moment we assume uniform */
2542
2393
  con->users= sptr->users;
2543
2394
  con->real_users= sptr->real_users;
2544
2395
  con->avg_rows= sptr->rows;
2545
 
 
 
2396
 
2546
2397
  /* With no next, we know it is the last element that was malloced */
2547
2398
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2548
2399
  {
2566
2417
  /* Now we do the create time operations */
2567
2418
  con->create_min_timing= sptr->create_timing;
2568
2419
  con->create_max_timing= sptr->create_timing;
2569
 
 
 
2420
 
2570
2421
  /* At the moment we assume uniform */
2571
2422
  con->create_count= sptr->create_count;
2572
 
 
 
2423
 
2573
2424
  /* With no next, we know it is the last element that was malloced */
2574
2425
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2575
2426
  {
2594
2445
  {
2595
2446
    nptr= ptr->next;
2596
2447
    if (ptr->string)
2597
 
      free(ptr->string);
 
2448
      my_free(ptr->string, MYF(0));
2598
2449
    if (ptr->option)
2599
 
      free(ptr->option);
2600
 
    free(ptr);
 
2450
      my_free(ptr->option, MYF(0));
 
2451
    my_free(ptr, MYF(0));
2601
2452
  }
2602
2453
}
2603
2454
 
2612
2463
  {
2613
2464
    nptr= ptr->next;
2614
2465
    if (ptr->string)
2615
 
      free(ptr->string);
2616
 
    free(ptr);
 
2466
      my_free(ptr->string, MYF(0));
 
2467
    my_free(ptr, MYF(0));
2617
2468
  }
2618
2469
}
2619
2470
 
2637
2488
    return;
2638
2489
 
2639
2490
  if (opt_delayed_start)
2640
 
    usleep(random()%opt_delayed_start);
 
2491
    my_sleep(random()%opt_delayed_start);
2641
2492
 
2642
2493
  drizzle_create(drizzle);
2643
2494
 
2644
2495
  if (opt_compress)
2645
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
2496
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
 
2497
  /* We always do opt_protocol to TCP/IP */
 
2498
  drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
2499
  drizzle_options(drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
2646
2500
 
2647
2501
  for (x= 0; x < 10; x++)
2648
2502
  {
2649
2503
 
2650
2504
 
2651
2505
    if (drizzle_connect(drizzle, host, user, opt_password,
2652
 
                        connect_to_schema ? create_schema_string : NULL,
2653
 
                        opt_drizzle_port,
2654
 
                        opt_drizzle_unix_port,
2655
 
                        connect_flags))
 
2506
                           connect_to_schema ? create_schema_string : NULL,
 
2507
                           opt_drizzle_port,
 
2508
                           opt_drizzle_unix_port,
 
2509
                           connect_flags))
2656
2510
    {
2657
2511
      /* Connect suceeded */
2658
2512
      connect_error= 0;
2659
2513
      break;
2660
2514
    }
2661
 
    usleep(connection_retry_sleep);
 
2515
    my_sleep(connection_retry_sleep);
2662
2516
  }
2663
2517
  if (connect_error)
2664
2518
  {
2675
2529
{
2676
2530
  unsigned int x;
2677
2531
  long int sum_of_squares;
2678
 
  double the_catch;
 
2532
  double catch;
2679
2533
  stats *ptr;
2680
2534
 
2681
2535
  if (iterations == 1 || iterations == 0)
2692
2546
    sum_of_squares+= deviation*deviation;
2693
2547
  }
2694
2548
 
2695
 
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2696
 
  con->std_dev= (long int)the_catch;
 
2549
  catch= sqrt((double)(sum_of_squares/(iterations -1)));
 
2550
  con->std_dev= (long int)catch;
2697
2551
}