Commit 2fe875af authored by unknown's avatar unknown

Simple changes during review of code

Added back flag that I accidently removed in last patch


sql/ha_federated.cc:
  Indentation cleanups
  Simple optimization using min() and strmake()
  Much simpler create()
sql/sql_prepare.cc:
  Added back flag that I accidently removed in last patch
sql/sql_table.cc:
  Simplify code by having error block last
parent 872a537c
...@@ -441,6 +441,7 @@ static int check_foreign_data_source( ...@@ -441,6 +441,7 @@ static int check_foreign_data_source(
String query(query_buffer, sizeof(query_buffer), &my_charset_bin); String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
MYSQL *mysql; MYSQL *mysql;
DBUG_ENTER("ha_federated::check_foreign_data_source"); DBUG_ENTER("ha_federated::check_foreign_data_source");
/* Zero the length, otherwise the string will have misc chars */ /* Zero the length, otherwise the string will have misc chars */
query.length(0); query.length(0);
...@@ -525,6 +526,7 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num) ...@@ -525,6 +526,7 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num)
char buf[FEDERATED_QUERY_BUFFER_SIZE]; char buf[FEDERATED_QUERY_BUFFER_SIZE];
int buf_len; int buf_len;
DBUG_ENTER("ha_federated parse_url_error"); DBUG_ENTER("ha_federated parse_url_error");
if (share->scheme) if (share->scheme)
{ {
DBUG_PRINT("info", DBUG_PRINT("info",
...@@ -533,11 +535,9 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num) ...@@ -533,11 +535,9 @@ static int parse_url_error(FEDERATED_SHARE *share, TABLE *table, int error_num)
my_free((gptr) share->scheme, MYF(0)); my_free((gptr) share->scheme, MYF(0));
share->scheme= 0; share->scheme= 0;
} }
buf_len= (table->s->connect_string.length > (FEDERATED_QUERY_BUFFER_SIZE - 1)) buf_len= min(table->s->connect_string.length,
? FEDERATED_QUERY_BUFFER_SIZE - 1 : table->s->connect_string.length; FEDERATED_QUERY_BUFFER_SIZE-1);
strmake(buf, table->s->connect_string.str, buf_len);
strnmov(buf, table->s->connect_string.str, buf_len);
buf[buf_len]= '\0';
my_error(error_num, MYF(0), buf); my_error(error_num, MYF(0), buf);
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
...@@ -748,12 +748,9 @@ uint ha_federated::convert_row_to_internal_format(byte *record, MYSQL_ROW row) ...@@ -748,12 +748,9 @@ uint ha_federated::convert_row_to_internal_format(byte *record, MYSQL_ROW row)
{ {
ulong *lengths; ulong *lengths;
Field **field; Field **field;
DBUG_ENTER("ha_federated::convert_row_to_internal_format"); DBUG_ENTER("ha_federated::convert_row_to_internal_format");
// num_fields= mysql_num_fields(stored_result);
lengths= mysql_fetch_lengths(stored_result); lengths= mysql_fetch_lengths(stored_result);
memset(record, 0, table->s->null_bytes); memset(record, 0, table->s->null_bytes);
for (field= table->field; *field; field++) for (field= table->field; *field; field++)
...@@ -1108,8 +1105,8 @@ bool ha_federated::create_where_from_key(String *to, ...@@ -1108,8 +1105,8 @@ bool ha_federated::create_where_from_key(String *to,
char tmpbuff[FEDERATED_QUERY_BUFFER_SIZE]; char tmpbuff[FEDERATED_QUERY_BUFFER_SIZE];
String tmp(tmpbuff, sizeof(tmpbuff), system_charset_info); String tmp(tmpbuff, sizeof(tmpbuff), system_charset_info);
const key_range *ranges[2]= { start_key, end_key }; const key_range *ranges[2]= { start_key, end_key };
DBUG_ENTER("ha_federated::create_where_from_key"); DBUG_ENTER("ha_federated::create_where_from_key");
tmp.length(0); tmp.length(0);
if (start_key == NULL && end_key == NULL) if (start_key == NULL && end_key == NULL)
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -1369,8 +1366,8 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table) ...@@ -1369,8 +1366,8 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
static int free_share(FEDERATED_SHARE *share) static int free_share(FEDERATED_SHARE *share)
{ {
DBUG_ENTER("free_share"); DBUG_ENTER("free_share");
pthread_mutex_lock(&federated_mutex);
pthread_mutex_lock(&federated_mutex);
if (!--share->use_count) if (!--share->use_count)
{ {
if (share->scheme) if (share->scheme)
...@@ -1565,7 +1562,6 @@ int ha_federated::write_row(byte *buf) ...@@ -1565,7 +1562,6 @@ int ha_federated::write_row(byte *buf)
values_string.length(0); values_string.length(0);
insert_string.length(0); insert_string.length(0);
insert_field_value_string.length(0); insert_field_value_string.length(0);
DBUG_ENTER("ha_federated::write_row"); DBUG_ENTER("ha_federated::write_row");
DBUG_PRINT("info", DBUG_PRINT("info",
("table charset name %s csname %s", ("table charset name %s csname %s",
...@@ -1692,7 +1688,6 @@ int ha_federated::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1692,7 +1688,6 @@ int ha_federated::optimize(THD* thd, HA_CHECK_OPT* check_opt)
{ {
char query_buffer[STRING_BUFFER_USUAL_SIZE]; char query_buffer[STRING_BUFFER_USUAL_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin); String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
DBUG_ENTER("ha_federated::optimize"); DBUG_ENTER("ha_federated::optimize");
query.length(0); query.length(0);
...@@ -1716,7 +1711,6 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1716,7 +1711,6 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt)
{ {
char query_buffer[STRING_BUFFER_USUAL_SIZE]; char query_buffer[STRING_BUFFER_USUAL_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin); String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
DBUG_ENTER("ha_federated::repair"); DBUG_ENTER("ha_federated::repair");
query.length(0); query.length(0);
...@@ -1762,14 +1756,16 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1762,14 +1756,16 @@ int ha_federated::repair(THD* thd, HA_CHECK_OPT* check_opt)
int ha_federated::update_row(const byte *old_data, byte *new_data) int ha_federated::update_row(const byte *old_data, byte *new_data)
{ {
/* /*
This used to control how the query was built. If there was a primary key, This used to control how the query was built. If there was a
the query would be built such that there was a where clause with only primary key, the query would be built such that there was a where
that column as the condition. This is flawed, because if we have a multi-part clause with only that column as the condition. This is flawed,
primary key, it would only use the first part! We don't need to do this anyway, because if we have a multi-part primary key, it would only use the
because read_range_first will retrieve the correct record, which is what is used first part! We don't need to do this anyway, because
to build the WHERE clause. We can however use this to append a LIMIT to the end read_range_first will retrieve the correct record, which is what
if there is NOT a primary key. Why do this? Because we only are updating one is used to build the WHERE clause. We can however use this to
record, and LIMIT enforces this. append a LIMIT to the end if there is NOT a primary key. Why do
this? Because we only are updating one record, and LIMIT enforces
this.
*/ */
bool has_a_primary_key= (table->s->primary_key == 0 ? TRUE : FALSE); bool has_a_primary_key= (table->s->primary_key == 0 ? TRUE : FALSE);
/* /*
...@@ -1796,7 +1792,6 @@ int ha_federated::update_row(const byte *old_data, byte *new_data) ...@@ -1796,7 +1792,6 @@ int ha_federated::update_row(const byte *old_data, byte *new_data)
String where_string(where_buffer, String where_string(where_buffer,
sizeof(where_buffer), sizeof(where_buffer),
&my_charset_bin); &my_charset_bin);
DBUG_ENTER("ha_federated::update_row"); DBUG_ENTER("ha_federated::update_row");
/* /*
set string lengths to 0 to avoid misc chars in string set string lengths to 0 to avoid misc chars in string
...@@ -1991,12 +1986,10 @@ int ha_federated::index_read_idx(byte *buf, uint index, const byte *key, ...@@ -1991,12 +1986,10 @@ int ha_federated::index_read_idx(byte *buf, uint index, const byte *key,
sizeof(sql_query_buffer), sizeof(sql_query_buffer),
&my_charset_bin); &my_charset_bin);
key_range range; key_range range;
DBUG_ENTER("ha_federated::index_read_idx");
index_string.length(0); index_string.length(0);
sql_query.length(0); sql_query.length(0);
DBUG_ENTER("ha_federated::index_read_idx");
statistic_increment(table->in_use->status_var.ha_read_key_count, statistic_increment(table->in_use->status_var.ha_read_key_count,
&LOCK_status); &LOCK_status);
...@@ -2085,8 +2078,8 @@ int ha_federated::read_range_first(const key_range *start_key, ...@@ -2085,8 +2078,8 @@ int ha_federated::read_range_first(const key_range *start_key,
String sql_query(sql_query_buffer, String sql_query(sql_query_buffer,
sizeof(sql_query_buffer), sizeof(sql_query_buffer),
&my_charset_bin); &my_charset_bin);
DBUG_ENTER("ha_federated::read_range_first"); DBUG_ENTER("ha_federated::read_range_first");
if (start_key == NULL && end_key == NULL) if (start_key == NULL && end_key == NULL)
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -2401,7 +2394,6 @@ void ha_federated::info(uint flag) ...@@ -2401,7 +2394,6 @@ void ha_federated::info(uint flag)
MYSQL_RES *result= 0; MYSQL_RES *result= 0;
MYSQL_ROW row; MYSQL_ROW row;
String status_query_string(status_buf, sizeof(status_buf), &my_charset_bin); String status_query_string(status_buf, sizeof(status_buf), &my_charset_bin);
DBUG_ENTER("ha_federated::info"); DBUG_ENTER("ha_federated::info");
error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE; error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
...@@ -2492,10 +2484,10 @@ void ha_federated::info(uint flag) ...@@ -2492,10 +2484,10 @@ void ha_federated::info(uint flag)
int ha_federated::delete_all_rows() int ha_federated::delete_all_rows()
{ {
DBUG_ENTER("ha_federated::delete_all_rows");
char query_buffer[FEDERATED_QUERY_BUFFER_SIZE]; char query_buffer[FEDERATED_QUERY_BUFFER_SIZE];
String query(query_buffer, sizeof(query_buffer), &my_charset_bin); String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
DBUG_ENTER("ha_federated::delete_all_rows");
query.length(0); query.length(0);
query.set_charset(system_charset_info); query.set_charset(system_charset_info);
...@@ -2590,32 +2582,14 @@ THR_LOCK_DATA **ha_federated::store_lock(THD *thd, ...@@ -2590,32 +2582,14 @@ THR_LOCK_DATA **ha_federated::store_lock(THD *thd,
int ha_federated::create(const char *name, TABLE *table_arg, int ha_federated::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info) HA_CREATE_INFO *create_info)
{ {
int retval= 0; int retval;
/* FEDERATED_SHARE tmp_share; // Only a temporary share, to test the url
only a temporary share, to test the url
*/
FEDERATED_SHARE tmp_share;
DBUG_ENTER("ha_federated::create"); DBUG_ENTER("ha_federated::create");
if ((retval= parse_url(&tmp_share, table_arg, 1))) if (!(retval= parse_url(&tmp_share, table_arg, 1)))
goto error; retval= check_foreign_data_source(&tmp_share, 1);
if ((retval= check_foreign_data_source(&tmp_share, 1)))
goto error;
if (tmp_share.scheme) my_free((gptr) tmp_share.scheme, MYF(MY_ALLOW_ZERO_PTR));
{
my_free((gptr) tmp_share.scheme, MYF(0));
tmp_share.scheme= 0;
}
DBUG_RETURN(retval);
error:
if (tmp_share.scheme)
{
my_free((gptr) tmp_share.scheme, MYF(0));
tmp_share.scheme= 0;
}
DBUG_RETURN(retval); DBUG_RETURN(retval);
} }
......
...@@ -2792,6 +2792,8 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) ...@@ -2792,6 +2792,8 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
my_error(ER_PS_NO_RECURSION, MYF(0)); my_error(ER_PS_NO_RECURSION, MYF(0));
return 1; return 1;
} }
/* In case the command has a call to SP which re-uses this statement name */
flags|= (uint) IS_IN_USE;
if (cursor && cursor->is_open()) if (cursor && cursor->is_open())
close_cursor(); close_cursor();
......
...@@ -1571,7 +1571,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -1571,7 +1571,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (wait_if_global_read_lock(thd, 0, 1)) if (wait_if_global_read_lock(thd, 0, 1))
DBUG_RETURN(error); DBUG_RETURN(TRUE);
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE)) if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{ {
...@@ -1636,20 +1636,20 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, ...@@ -1636,20 +1636,20 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
error= FALSE; error= FALSE;
goto end;
warn:
error= 0;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
alias);
create_info->table_existed= 1; // Mark that table existed
end: end:
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
start_waiting_global_read_lock(thd); start_waiting_global_read_lock(thd);
thd->proc_info="After create"; thd->proc_info="After create";
DBUG_RETURN(error); DBUG_RETURN(error);
warn:
error= FALSE;
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
alias);
create_info->table_existed= 1; // Mark that table existed
goto end;
} }
/* /*
......
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