~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

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