~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mto: (1.2.1) (37.1.1 lucid-security)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: package-import@ubuntu.com-20120222223355-ku1tb4r70osci6v2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 MySQL AB, 2009 Sun Microsystems, Inc.
 
1
/*
 
2
   Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   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
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
15
16
 
16
17
   original idea: Brian Aker via playing with ab for too many years
17
18
   coded by: Patrick Galbraith
131
132
 
132
133
const char *create_schema_string= "mysqlslap";
133
134
 
134
 
static my_bool opt_preserve= TRUE;
 
135
static my_bool opt_preserve= TRUE, opt_no_drop= FALSE;
135
136
static my_bool debug_info_flag= 0, debug_check_flag= 0;
136
137
static my_bool opt_only_print= FALSE;
137
138
static my_bool opt_compress= FALSE, tty_password= FALSE,
511
512
    0, 0, 0, 0, 0, 0},
512
513
  {"auto-generate-sql", 'a',
513
514
    "Generate SQL where not supplied by file or command line.",
514
 
    (uchar**) &auto_generate_sql, (uchar**) &auto_generate_sql,
 
515
    &auto_generate_sql, &auto_generate_sql,
515
516
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
516
517
  {"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
517
518
    "Add an AUTO_INCREMENT column to auto-generated tables.",
518
 
    (uchar**) &auto_generate_sql_autoincrement, 
519
 
    (uchar**) &auto_generate_sql_autoincrement,
 
519
    &auto_generate_sql_autoincrement,
 
520
    &auto_generate_sql_autoincrement,
520
521
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
521
522
  {"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
522
523
    "Set this number to generate a set number of queries to run.",
523
 
    (uchar**) &auto_actual_queries, (uchar**) &auto_actual_queries,
 
524
    &auto_actual_queries, &auto_actual_queries,
524
525
    0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
525
526
  {"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
526
527
    "Add GUID based primary keys to auto-generated tables.",
527
 
    (uchar**) &auto_generate_sql_guid_primary, 
528
 
    (uchar**) &auto_generate_sql_guid_primary,
 
528
    &auto_generate_sql_guid_primary,
 
529
    &auto_generate_sql_guid_primary,
529
530
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
530
531
  {"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
531
532
    "Specify test load type: mixed, update, write, key, or read; default is mixed.",
532
 
    (uchar**) &auto_generate_sql_type, (uchar**) &auto_generate_sql_type,
 
533
    &auto_generate_sql_type, &auto_generate_sql_type,
533
534
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
534
535
  {"auto-generate-sql-secondary-indexes", 
535
536
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES, 
536
537
    "Number of secondary indexes to add to auto-generated tables.",
537
 
    (uchar**) &auto_generate_sql_secondary_indexes, 
538
 
    (uchar**) &auto_generate_sql_secondary_indexes, 0,
 
538
    &auto_generate_sql_secondary_indexes,
 
539
    &auto_generate_sql_secondary_indexes, 0,
539
540
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
540
541
  {"auto-generate-sql-unique-query-number", 
541
542
    OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
542
543
    "Number of unique queries to generate for automatic tests.",
543
 
    (uchar**) &auto_generate_sql_unique_query_number, 
544
 
    (uchar**) &auto_generate_sql_unique_query_number,
 
544
    &auto_generate_sql_unique_query_number,
 
545
    &auto_generate_sql_unique_query_number,
545
546
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
546
547
  {"auto-generate-sql-unique-write-number", 
547
548
    OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
548
549
    "Number of unique queries to generate for auto-generate-sql-write-number.",
549
 
    (uchar**) &auto_generate_sql_unique_write_number, 
550
 
    (uchar**) &auto_generate_sql_unique_write_number,
 
550
    &auto_generate_sql_unique_write_number,
 
551
    &auto_generate_sql_unique_write_number,
551
552
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
552
553
  {"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
553
554
    "Number of row inserts to perform for each thread (default is 100).",
554
 
    (uchar**) &auto_generate_sql_number, (uchar**) &auto_generate_sql_number,
 
555
    &auto_generate_sql_number, &auto_generate_sql_number,
555
556
    0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
556
557
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
557
 
    (uchar**) &commit_rate, (uchar**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
 
558
    &commit_rate, &commit_rate, 0, GET_UINT, REQUIRED_ARG,
558
559
    0, 0, 0, 0, 0, 0},
559
560
  {"compress", 'C', "Use compression in server/client protocol.",
560
 
    (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
561
    &opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
561
562
    0, 0, 0},
562
563
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
563
 
    (uchar**) &concurrency_str, (uchar**) &concurrency_str, 0, GET_STR,
 
564
    &concurrency_str, &concurrency_str, 0, GET_STR,
564
565
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
565
566
  {"create", OPT_SLAP_CREATE_STRING, "File or string to use create tables.",
566
 
    (uchar**) &create_string, (uchar**) &create_string, 0, GET_STR, REQUIRED_ARG,
 
567
    &create_string, &create_string, 0, GET_STR, REQUIRED_ARG,
567
568
    0, 0, 0, 0, 0, 0},
568
569
  {"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
569
 
    (uchar**) &create_schema_string, (uchar**) &create_schema_string, 0, GET_STR, 
 
570
    &create_schema_string, &create_schema_string, 0, GET_STR, 
570
571
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
571
572
  {"csv", OPT_SLAP_CSV,
572
573
        "Generate CSV output to named file or to stdout if no file is named.",
576
577
   0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
577
578
#else
578
579
  {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
579
 
    (uchar**) &default_dbug_option, (uchar**) &default_dbug_option, 0, GET_STR,
 
580
    &default_dbug_option, &default_dbug_option, 0, GET_STR,
580
581
    OPT_ARG, 0, 0, 0, 0, 0, 0},
581
582
#endif
582
583
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
583
 
   (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
 
584
   &debug_check_flag, &debug_check_flag, 0,
584
585
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
585
 
  {"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
586
 
   (uchar**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
586
  {"debug-info", 'T', "Print some debug info at exit.", &debug_info_flag,
 
587
   &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
587
588
  {"delimiter", 'F',
588
589
    "Delimiter to use in SQL statements supplied in file or command line.",
589
 
    (uchar**) &delimiter, (uchar**) &delimiter, 0, GET_STR, REQUIRED_ARG,
 
590
    &delimiter, &delimiter, 0, GET_STR, REQUIRED_ARG,
590
591
    0, 0, 0, 0, 0, 0},
591
592
  {"detach", OPT_SLAP_DETACH,
592
593
    "Detach (close and reopen) connections after X number of requests.",
593
 
    (uchar**) &detach_rate, (uchar**) &detach_rate, 0, GET_UINT, REQUIRED_ARG, 
 
594
    &detach_rate, &detach_rate, 0, GET_UINT, REQUIRED_ARG, 
594
595
    0, 0, 0, 0, 0, 0},
595
596
  {"engine", 'e', "Storage engine to use for creating the table.",
596
 
    (uchar**) &default_engine, (uchar**) &default_engine, 0,
 
597
    &default_engine, &default_engine, 0,
597
598
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
598
 
  {"host", 'h', "Connect to host.", (uchar**) &host, (uchar**) &host, 0, GET_STR,
 
599
  {"host", 'h', "Connect to host.", &host, &host, 0, GET_STR,
599
600
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
600
 
  {"iterations", 'i', "Number of times to run the tests.", (uchar**) &iterations,
601
 
    (uchar**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
 
601
  {"iterations", 'i', "Number of times to run the tests.", &iterations,
 
602
    &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
 
603
  {"no-drop", OPT_SLAP_NO_DROP, "Do not drop the schema after the test.",
 
604
   &opt_no_drop, &opt_no_drop, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
602
605
  {"number-char-cols", 'x', 
603
606
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
604
 
    (uchar**) &num_char_cols_opt, (uchar**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
607
    &num_char_cols_opt, &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
605
608
    0, 0, 0, 0, 0, 0},
606
609
  {"number-int-cols", 'y', 
607
610
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
608
 
    (uchar**) &num_int_cols_opt, (uchar**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG, 
 
611
    &num_int_cols_opt, &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG, 
609
612
    0, 0, 0, 0, 0, 0},
610
613
  {"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY, 
611
614
    "Limit each client to this number of queries (this is not exact).",
612
 
    (uchar**) &num_of_query, (uchar**) &num_of_query, 0,
 
615
    &num_of_query, &num_of_query, 0,
613
616
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
614
617
  {"only-print", OPT_MYSQL_ONLY_PRINT,
615
 
    "This causes mysqlslap to not connect to the databases, but instead print "
616
 
      "out what it would have done instead.",
617
 
    (uchar**) &opt_only_print, (uchar**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
 
618
    "Do not connect to the databases, but instead print out what would have "
 
619
     "been done.",
 
620
    &opt_only_print, &opt_only_print, 0, GET_BOOL,  NO_ARG,
618
621
    0, 0, 0, 0, 0, 0},
619
622
  {"password", 'p',
620
623
    "Password to use when connecting to server. If password is not given it's "
623
626
  {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
624
627
    NO_ARG, 0, 0, 0, 0, 0, 0},
625
628
#endif
626
 
  {"port", 'P', "Port number to use for connection.", (uchar**) &opt_mysql_port,
627
 
    (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
 
629
  {"port", 'P', "Port number to use for connection.", &opt_mysql_port,
 
630
    &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
628
631
    0},
629
632
  {"post-query", OPT_SLAP_POST_QUERY,
630
633
    "Query to run or file containing query to execute after tests have completed.",
631
 
    (uchar**) &user_supplied_post_statements, 
632
 
    (uchar**) &user_supplied_post_statements,
 
634
    &user_supplied_post_statements, &user_supplied_post_statements,
633
635
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
634
636
  {"post-system", OPT_SLAP_POST_SYSTEM,
635
637
    "system() string to execute after tests have completed.",
636
 
    (uchar**) &post_system, 
637
 
    (uchar**) &post_system,
 
638
    &post_system, &post_system,
638
639
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
639
640
  {"pre-query", OPT_SLAP_PRE_QUERY, 
640
641
    "Query to run or file containing query to execute before running tests.",
641
 
    (uchar**) &user_supplied_pre_statements, 
642
 
    (uchar**) &user_supplied_pre_statements,
 
642
    &user_supplied_pre_statements, &user_supplied_pre_statements,
643
643
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
644
644
  {"pre-system", OPT_SLAP_PRE_SYSTEM, 
645
645
    "system() string to execute before running tests.",
646
 
    (uchar**) &pre_system, 
647
 
    (uchar**) &pre_system,
 
646
    &pre_system, &pre_system,
648
647
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
649
648
  {"protocol", OPT_MYSQL_PROTOCOL,
650
 
    "The protocol of connection (tcp,socket,pipe,memory).",
 
649
    "The protocol to use for connection (tcp, socket, pipe, memory).",
651
650
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
652
651
  {"query", 'q', "Query to run or file containing query to run.",
653
 
    (uchar**) &user_supplied_query, (uchar**) &user_supplied_query,
 
652
    &user_supplied_query, &user_supplied_query,
654
653
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
655
654
#ifdef HAVE_SMEM
656
655
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
657
 
    "Base name of shared memory.", (uchar**) &shared_memory_base_name,
658
 
    (uchar**) &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG,
 
656
    "Base name of shared memory.", &shared_memory_base_name,
 
657
    &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG,
659
658
    0, 0, 0, 0, 0, 0},
660
659
#endif
661
660
  {"silent", 's', "Run program in silent mode - no output.",
662
 
    (uchar**) &opt_silent, (uchar**) &opt_silent, 0, GET_BOOL,  NO_ARG,
 
661
    &opt_silent, &opt_silent, 0, GET_BOOL,  NO_ARG,
663
662
    0, 0, 0, 0, 0, 0},
664
 
  {"socket", 'S', "Socket file to use for connection.",
665
 
    (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
 
663
  {"socket", 'S', "The socket file to use for connection.",
 
664
    &opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR,
666
665
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
667
666
#include <sslopt-longopts.h>
668
667
#ifndef DONT_ALLOW_USER_CHANGE
669
 
  {"user", 'u', "User for login if not current user.", (uchar**) &user,
670
 
    (uchar**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
668
  {"user", 'u', "User for login if not current user.", &user,
 
669
    &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
671
670
#endif
672
671
  {"verbose", 'v',
673
 
    "More verbose output; you can use this multiple times to get even more "
674
 
      "verbose output.", (uchar**) &verbose, (uchar**) &verbose, 0, 
675
 
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
676
 
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
677
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
672
   "More verbose output; you can use this multiple times to get even more "
 
673
   "verbose output.", &verbose, &verbose, 0, GET_NO_ARG, NO_ARG,
 
674
   0, 0, 0, 0, 0, 0},
 
675
  {"version", 'V', "Output version information and exit.", 0, 0, 0,
 
676
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
678
677
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
679
678
};
680
679
 
692
691
{
693
692
  print_version();
694
693
  puts("Copyright (C) 2005 MySQL AB");
695
 
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
696
 
  puts("Run a query multiple times against the server\n");
 
694
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n");
 
695
  puts("Run a query multiple times against the server.\n");
697
696
  printf("Usage: %s [OPTIONS]\n",my_progname);
698
697
  print_defaults("my",load_default_groups);
699
698
  my_print_help(my_long_options);
1151
1150
  if (!user)
1152
1151
    user= (char *)"root";
1153
1152
 
1154
 
  /* If something is created we clean it up, otherwise we leave schemas alone */
1155
 
  if (create_string || auto_generate_sql)
 
1153
  /*
 
1154
    If something is created and --no-drop is not specified, we drop the
 
1155
    schema.
 
1156
  */
 
1157
  if (!opt_no_drop && (create_string || auto_generate_sql))
1156
1158
    opt_preserve= FALSE;
1157
1159
 
1158
1160
  if (auto_generate_sql && (create_string || user_supplied_query))
1523
1525
      exit(1);
1524
1526
    }
1525
1527
 
1526
 
    result= mysql_store_result(mysql);
 
1528
    if (!(result= mysql_store_result(mysql)))
 
1529
    {
 
1530
      fprintf(stderr, "%s: Error when storing result: %d %s\n",
 
1531
              my_progname, mysql_errno(mysql), mysql_error(mysql));
 
1532
      exit(1);
 
1533
    }
1527
1534
    primary_keys_number_of= mysql_num_rows(result);
1528
1535
 
1529
1536
    /* So why check this? Blackhole :) */
1895
1902
      {
1896
1903
        if (mysql_field_count(mysql))
1897
1904
        {
1898
 
          result= mysql_store_result(mysql);
1899
 
          while ((row = mysql_fetch_row(result)))
1900
 
            counter++;
1901
 
          mysql_free_result(result);
 
1905
          if (!(result= mysql_store_result(mysql)))
 
1906
            fprintf(stderr, "%s: Error when storing result: %d %s\n",
 
1907
                    my_progname, mysql_errno(mysql), mysql_error(mysql));
 
1908
          else
 
1909
          {
 
1910
            while ((row= mysql_fetch_row(result)))
 
1911
              counter++;
 
1912
            mysql_free_result(result);
 
1913
          }
1902
1914
        }
1903
1915
      } while(mysql_next_result(mysql) == 0);
1904
1916
      queries++;