116
117
const char *delimiter= "\n";
118
const char *create_schema_string= "mysqlslap";
119
const char *create_schema_string= "drizzleslap";
120
121
static bool opt_preserve= true;
121
122
static bool debug_info_flag= 0, debug_check_flag= 0;
176
177
static int get_options(int *argc,char ***argv);
177
178
static uint opt_drizzle_port= 0;
179
static const char *load_default_groups[]= { "mysqlslap","client",0 };
180
static const char *load_default_groups[]= { "drizzleslap","client",0 };
779
780
char buf[HUGE_STRING_LENGTH];
780
781
unsigned int col_count;
782
DYNAMIC_STRING table_string;
784
init_dynamic_string(&table_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
786
dynstr_append(&table_string, "CREATE TABLE `t1` (");
785
table_string.reserve(HUGE_STRING_LENGTH);
787
table_string= "CREATE TABLE `t1` (";
788
789
if (auto_generate_sql_autoincrement)
790
dynstr_append(&table_string, "id serial");
791
table_string.append("id serial");
792
793
if (num_int_cols || num_char_cols)
793
dynstr_append(&table_string, ",");
794
table_string.append(",");
796
797
if (auto_generate_sql_guid_primary)
798
dynstr_append(&table_string, "id varchar(128) primary key");
799
table_string.append("id varchar(128) primary key");
800
801
if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
801
dynstr_append(&table_string, ",");
802
table_string.append(",");
804
805
if (auto_generate_sql_secondary_indexes)
808
809
for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
810
811
if (count) /* Except for the first pass we add a comma */
811
dynstr_append(&table_string, ",");
812
table_string.append(",");
813
814
if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
814
815
> HUGE_STRING_LENGTH)
816
817
fprintf(stderr, "Memory Allocation error in create table\n");
819
dynstr_append(&table_string, buf);
820
table_string.append(buf);
822
823
if (num_int_cols || num_char_cols)
823
dynstr_append(&table_string, ",");
824
table_string.append(",");
826
827
if (num_int_cols)
847
dynstr_append(&table_string, buf);
848
table_string.append(buf);
849
850
if (col_count < num_int_cols || num_char_cols > 0)
850
dynstr_append(&table_string, ",");
851
table_string.append(",");
853
854
if (num_char_cols)
875
dynstr_append(&table_string, buf);
876
table_string.append(buf);
877
878
if (col_count < num_char_cols || num_blob_cols > 0)
878
dynstr_append(&table_string, ",");
879
table_string.append(",");
881
882
if (num_blob_cols)
887
888
fprintf(stderr, "Memory Allocation error in creating table\n");
890
dynstr_append(&table_string, buf);
891
table_string.append(buf);
892
893
if (col_count < num_blob_cols)
893
dynstr_append(&table_string, ",");
894
table_string.append(",");
896
dynstr_append(&table_string, ")");
897
table_string.append(")");
897
898
ptr= (statement *)my_malloc(sizeof(statement),
898
899
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
899
ptr->string = (char *)my_malloc(table_string.length+1,
900
ptr->string = (char *)my_malloc(table_string.length()+1,
900
901
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
901
ptr->length= table_string.length+1;
902
ptr->length= table_string.length()+1;
902
903
ptr->type= CREATE_TABLE_TYPE;
903
stpcpy(ptr->string, table_string.str);
904
dynstr_free(&table_string);
904
stpcpy(ptr->string, table_string.c_str());
917
917
char buf[HUGE_STRING_LENGTH];
918
918
unsigned int col_count;
920
DYNAMIC_STRING update_string;
923
init_dynamic_string(&update_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
925
dynstr_append(&update_string, "UPDATE t1 SET ");
920
string update_string;
922
update_string.reserve(HUGE_STRING_LENGTH);
924
update_string= "UPDATE t1 SET ";
927
926
if (num_int_cols)
928
927
for (col_count= 1; col_count <= num_int_cols; col_count++)
933
932
fprintf(stderr, "Memory Allocation error in creating update\n");
936
dynstr_append(&update_string, buf);
935
update_string.append(buf);
938
937
if (col_count < num_int_cols || num_char_cols > 0)
939
dynstr_append_mem(&update_string, ",", 1);
938
update_string.append(",", 1);
942
941
if (num_char_cols)
952
951
fprintf(stderr, "Memory Allocation error in creating update\n");
955
dynstr_append(&update_string, buf);
954
update_string.append(buf);
957
956
if (col_count < num_char_cols)
958
dynstr_append_mem(&update_string, ",", 1);
957
update_string.append(",", 1);
961
960
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
962
dynstr_append(&update_string, " WHERE id = ");
961
update_string.append(" WHERE id = ");
965
964
ptr= (statement *)my_malloc(sizeof(statement),
966
965
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
968
ptr->string= (char *)my_malloc(update_string.length + 1,
967
ptr->string= (char *)my_malloc(update_string.length() + 1,
969
968
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
970
ptr->length= update_string.length+1;
969
ptr->length= update_string.length()+1;
971
970
if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
972
971
ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
974
973
ptr->type= UPDATE_TYPE;
975
stpcpy(ptr->string, update_string.str);
976
dynstr_free(&update_string);
974
stpcpy(ptr->string, update_string.c_str());
990
988
char buf[HUGE_STRING_LENGTH];
991
989
unsigned int col_count;
993
DYNAMIC_STRING insert_string;
996
init_dynamic_string(&insert_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
998
dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
991
string insert_string;
993
insert_string.reserve(HUGE_STRING_LENGTH);
995
insert_string= "INSERT INTO t1 VALUES (";
1000
997
if (auto_generate_sql_autoincrement)
1002
dynstr_append(&insert_string, "NULL");
999
insert_string.append("NULL");
1004
1001
if (num_int_cols || num_char_cols)
1005
dynstr_append(&insert_string, ",");
1002
insert_string.append(",");
1008
1005
if (auto_generate_sql_guid_primary)
1010
dynstr_append(&insert_string, "uuid()");
1007
insert_string.append("uuid()");
1012
1009
if (num_int_cols || num_char_cols)
1013
dynstr_append(&insert_string, ",");
1010
insert_string.append(",");
1016
1013
if (auto_generate_sql_secondary_indexes)
1020
1017
for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1022
1019
if (count) /* Except for the first pass we add a comma */
1023
dynstr_append(&insert_string, ",");
1020
insert_string.append(",");
1025
dynstr_append(&insert_string, "uuid()");
1022
insert_string.append("uuid()");
1028
1025
if (num_int_cols || num_char_cols)
1029
dynstr_append(&insert_string, ",");
1026
insert_string.append(",");
1032
1029
if (num_int_cols)
1037
1034
fprintf(stderr, "Memory Allocation error in creating insert\n");
1040
dynstr_append(&insert_string, buf);
1037
insert_string.append(buf);
1042
1039
if (col_count < num_int_cols || num_char_cols > 0)
1043
dynstr_append_mem(&insert_string, ",", 1);
1040
insert_string.append(",");
1046
1043
if (num_char_cols)
1047
1044
for (col_count= 1; col_count <= num_char_cols; col_count++)
1049
1046
int buf_len= get_random_string(buf, RAND_STRING_SIZE);
1050
dynstr_append_mem(&insert_string, "'", 1);
1051
dynstr_append_mem(&insert_string, buf, buf_len);
1052
dynstr_append_mem(&insert_string, "'", 1);
1047
insert_string.append("'", 1);
1048
insert_string.append(buf, buf_len);
1049
insert_string.append("'", 1);
1054
1051
if (col_count < num_char_cols || num_blob_cols > 0)
1055
dynstr_append_mem(&insert_string, ",", 1);
1052
insert_string.append(",", 1);
1058
1055
if (num_blob_cols)
1086
1083
buf_len= get_random_string(blob_ptr, size);
1088
dynstr_append_mem(&insert_string, "'", 1);
1089
dynstr_append_mem(&insert_string, blob_ptr, buf_len);
1090
dynstr_append_mem(&insert_string, "'", 1);
1085
insert_string.append("'", 1);
1086
insert_string.append(blob_ptr, buf_len);
1087
insert_string.append("'", 1);
1092
1089
if (col_count < num_blob_cols)
1093
dynstr_append_mem(&insert_string, ",", 1);
1090
insert_string.append(",", 1);
1096
1093
if (num_blob_cols_size > HUGE_STRING_LENGTH)
1097
1094
my_free(blob_ptr, MYF(0));
1100
dynstr_append_mem(&insert_string, ")", 1);
1097
insert_string.append(")", 1);
1102
1099
if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1104
1101
fprintf(stderr, "Memory Allocation error in creating select\n");
1107
if (!(ptr->string= (char *)my_malloc(insert_string.length + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1104
if (!(ptr->string= (char *)my_malloc(insert_string.length() + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1109
1106
fprintf(stderr, "Memory Allocation error in creating select\n");
1112
ptr->length= insert_string.length+1;
1109
ptr->length= insert_string.length()+1;
1113
1110
ptr->type= INSERT_TYPE;
1114
stpcpy(ptr->string, insert_string.str);
1115
dynstr_free(&insert_string);
1111
stpcpy(ptr->string, insert_string.c_str());
1130
1125
char buf[HUGE_STRING_LENGTH];
1131
1126
unsigned int col_count;
1132
1127
statement *ptr;
1133
static DYNAMIC_STRING query_string;
1136
init_dynamic_string(&query_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
1138
dynstr_append_mem(&query_string, "SELECT ", 7);
1128
string query_string;
1130
query_string.reserve(HUGE_STRING_LENGTH);
1132
query_string.append("SELECT ", 7);
1139
1133
if (auto_generate_selected_columns_opt)
1141
dynstr_append(&query_string, auto_generate_selected_columns_opt);
1135
query_string.append(auto_generate_selected_columns_opt);
1150
1144
fprintf(stderr, "Memory Allocation error in creating select\n");
1153
dynstr_append(&query_string, buf);
1147
query_string.append(buf);
1155
1149
if (col_count < num_int_cols || num_char_cols > 0)
1156
dynstr_append_mem(&query_string, ",", 1);
1150
query_string.append(",", 1);
1159
1153
for (col_count= 1; col_count <= num_char_cols; col_count++)
1164
1158
fprintf(stderr, "Memory Allocation error in creating select\n");
1167
dynstr_append(&query_string, buf);
1161
query_string.append(buf);
1169
1163
if (col_count < num_char_cols || num_blob_cols > 0)
1170
dynstr_append_mem(&query_string, ",", 1);
1164
query_string.append(",", 1);
1173
1167
for (col_count= 1; col_count <= num_blob_cols; col_count++)
1178
1172
fprintf(stderr, "Memory Allocation error in creating select\n");
1181
dynstr_append(&query_string, buf);
1175
query_string.append(buf);
1183
1177
if (col_count < num_blob_cols)
1184
dynstr_append_mem(&query_string, ",", 1);
1178
query_string.append(",", 1);
1187
dynstr_append(&query_string, " FROM t1");
1181
query_string.append(" FROM t1");
1190
1184
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1191
dynstr_append(&query_string, " WHERE id = ");
1185
query_string.append(" WHERE id = ");
1193
1187
ptr= (statement *)my_malloc(sizeof(statement),
1194
1188
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1195
ptr->string= (char *)my_malloc(query_string.length + 1,
1189
ptr->string= (char *)my_malloc(query_string.length() + 1,
1196
1190
MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1197
ptr->length= query_string.length+1;
1191
ptr->length= query_string.length()+1;
1199
1193
(auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1200
1194
ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1202
1196
ptr->type= SELECT_TYPE;
1203
stpcpy(ptr->string, query_string.str);
1204
dynstr_free(&query_string);
1197
stpcpy(ptr->string, query_string.c_str());
2546
2539
sum_of_squares+= deviation*deviation;
2549
catch= sqrt((double)(sum_of_squares/(iterations -1)));
2550
con->std_dev= (long int)catch;
2542
the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2543
con->std_dev= (long int)the_catch;