Commit 28eac83e authored by unknown's avatar unknown

Add query_len variable to st_query, avoids a lot of strlen and allows better...

Add query_len variable to st_query, avoids a lot of strlen and allows better allocation of dynamic strings
Tune some inital allocations of dynamic strings


parent f2eabb87
...@@ -362,7 +362,7 @@ Q_COMMENT_WITH_COMMAND ...@@ -362,7 +362,7 @@ Q_COMMENT_WITH_COMMAND
struct st_query struct st_query
{ {
char *query, *query_buf,*first_argument,*last_argument,*end; char *query, *query_buf,*first_argument,*last_argument,*end;
int first_word_len; int first_word_len, query_len;
my_bool abort_on_error, require_file; my_bool abort_on_error, require_file;
match_err expected_errno[MAX_EXPECTED_ERRORS]; match_err expected_errno[MAX_EXPECTED_ERRORS];
uint expected_errors; uint expected_errors;
...@@ -758,12 +758,13 @@ static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) ...@@ -758,12 +758,13 @@ static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname)
if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP))) if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP)))
die(NullS); die(NullS);
tmp[stat_info.st_size] = 0; tmp[stat_info.st_size] = 0;
init_dynamic_string(&res_ds, "", 0, 65536); init_dynamic_string(&res_ds, "", stat_info.st_size+256, 256);
if (eval_result) if (eval_result)
{ {
do_eval(&res_ds, tmp, FALSE); do_eval(&res_ds, tmp, FALSE);
res_ptr = res_ds.str; res_ptr= res_ds.str;
if ((res_len = res_ds.length) != ds->length) res_len= res_ds.length;
if (res_len != ds->length)
{ {
res= RESULT_LENGTH_MISMATCH; res= RESULT_LENGTH_MISMATCH;
goto err; goto err;
...@@ -783,9 +784,9 @@ err: ...@@ -783,9 +784,9 @@ err:
str_to_file(fn_format(eval_file, fname, "", ".eval",2), res_ptr, str_to_file(fn_format(eval_file, fname, "", ".eval",2), res_ptr,
res_len); res_len);
dynstr_free(&res_ds);
my_free((gptr) tmp, MYF(0)); my_free((gptr) tmp, MYF(0));
my_close(fd, MYF(MY_WME)); my_close(fd, MYF(MY_WME));
dynstr_free(&res_ds);
DBUG_RETURN(res); DBUG_RETURN(res);
} }
...@@ -1183,7 +1184,7 @@ static void do_exec(struct st_query *query) ...@@ -1183,7 +1184,7 @@ static void do_exec(struct st_query *query)
die("Missing argument in exec"); die("Missing argument in exec");
query->last_argument= query->end; query->last_argument= query->end;
init_dynamic_string(&ds_cmd, 0, strlen(cmd)+256, 256); init_dynamic_string(&ds_cmd, 0, query->query_len+256, 256);
/* Eval the command, thus replacing all environment variables */ /* Eval the command, thus replacing all environment variables */
do_eval(&ds_cmd, cmd, TRUE); do_eval(&ds_cmd, cmd, TRUE);
cmd= ds_cmd.str; cmd= ds_cmd.str;
...@@ -1306,7 +1307,7 @@ int var_query_set(VAR* var, const char *query, const char** query_end) ...@@ -1306,7 +1307,7 @@ int var_query_set(VAR* var, const char *query, const char** query_end)
MYSQL_FIELD *fields= mysql_fetch_fields(res); MYSQL_FIELD *fields= mysql_fetch_fields(res);
#endif #endif
init_dynamic_string(&result, "", 16384, 65536); init_dynamic_string(&result, "", 2048, 2048);
lengths= mysql_fetch_lengths(res); lengths= mysql_fetch_lengths(res);
for (i=0; i < mysql_num_fields(res); i++) for (i=0; i < mysql_num_fields(res); i++)
{ {
...@@ -1498,7 +1499,7 @@ void do_system(struct st_query *command) ...@@ -1498,7 +1499,7 @@ void do_system(struct st_query *command)
if (strlen(command->first_argument) == 0) if (strlen(command->first_argument) == 0)
die("Missing arguments to system, nothing to do!"); die("Missing arguments to system, nothing to do!");
init_dynamic_string(&ds_cmd, 0, strlen(command->first_argument) + 64, 256); init_dynamic_string(&ds_cmd, 0, command->query_len + 64, 256);
/* Eval the system command, thus replacing all environment variables */ /* Eval the system command, thus replacing all environment variables */
do_eval(&ds_cmd, command->first_argument, TRUE); do_eval(&ds_cmd, command->first_argument, TRUE);
...@@ -1552,7 +1553,7 @@ int do_echo(struct st_query *command) ...@@ -1552,7 +1553,7 @@ int do_echo(struct st_query *command)
ds= &ds_res; ds= &ds_res;
init_dynamic_string(&ds_echo, "", 256, 256); init_dynamic_string(&ds_echo, "", command->query_len, 256);
do_eval(&ds_echo, command->first_argument, FALSE); do_eval(&ds_echo, command->first_argument, FALSE);
dynstr_append_mem(ds, ds_echo.str, ds_echo.length); dynstr_append_mem(ds, ds_echo.str, ds_echo.length);
dynstr_append_mem(ds, "\n", 1); dynstr_append_mem(ds, "\n", 1);
...@@ -3205,6 +3206,7 @@ int read_query(struct st_query** q_ptr) ...@@ -3205,6 +3206,7 @@ int read_query(struct st_query** q_ptr)
q->record_file[0]= 0; q->record_file[0]= 0;
q->require_file= 0; q->require_file= 0;
q->first_word_len= 0; q->first_word_len= 0;
q->query_len= 0;
q->type= Q_UNKNOWN; q->type= Q_UNKNOWN;
q->query_buf= q->query= 0; q->query_buf= q->query= 0;
...@@ -3255,6 +3257,7 @@ end: ...@@ -3255,6 +3257,7 @@ end:
p++; p++;
q->first_argument= p; q->first_argument= p;
q->end= strend(q->query); q->end= strend(q->query);
q->query_len= (q->end - q->query);
parser.read_lines++; parser.read_lines++;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -4723,7 +4726,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) ...@@ -4723,7 +4726,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags)
*/ */
if (command->type == Q_EVAL) if (command->type == Q_EVAL)
{ {
init_dynamic_string(&eval_query, "", 16384, 65536); init_dynamic_string(&eval_query, "", command->query_len+256, 1024);
do_eval(&eval_query, command->query, FALSE); do_eval(&eval_query, command->query, FALSE);
query = eval_query.str; query = eval_query.str;
query_len = eval_query.length; query_len = eval_query.length;
...@@ -4742,7 +4745,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) ...@@ -4742,7 +4745,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags)
*/ */
if (command->record_file[0]) if (command->record_file[0])
{ {
init_dynamic_string(&ds_result, "", 16384, 65536); init_dynamic_string(&ds_result, "", 1024, 1024);
ds= &ds_result; ds= &ds_result;
} }
else else
...@@ -5209,7 +5212,7 @@ int main(int argc, char **argv) ...@@ -5209,7 +5212,7 @@ int main(int argc, char **argv)
memset(&master_pos, 0, sizeof(master_pos)); memset(&master_pos, 0, sizeof(master_pos));
init_dynamic_string(&ds_res, "", 0, 65536); init_dynamic_string(&ds_res, "", 65536, 65536);
init_dynamic_string(&ds_progress, "", 0, 2048); init_dynamic_string(&ds_progress, "", 0, 2048);
parse_args(argc, argv); parse_args(argc, argv);
...@@ -5404,7 +5407,8 @@ int main(int argc, char **argv) ...@@ -5404,7 +5407,8 @@ int main(int argc, char **argv)
} }
/* fix up query pointer if this is first iteration for this line */ /* fix up query pointer if this is first iteration for this line */
if (q->query == q->query_buf) if (q->query == q->query_buf)
q->query += q->first_word_len; q->query+= q->first_word_len;
/* /*
run_query() can execute a query partially, depending on the flags. run_query() can execute a query partially, depending on the flags.
QUERY_SEND flag without QUERY_REAP tells it to just send the QUERY_SEND flag without QUERY_REAP tells it to just send the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment