From 2dcedd9cbc4effee5a1c7e4c8045f2e8adced065 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 21:42:17 +0200 Subject: Fixes during review of new pushed code: Remove wrong fix for Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash Safety fix for bug #13855 "select distinct with group by caused server crash" client/mysqlimport.c: Remove not used variable myisam/myisam_ftdump.c: Fixed compiler warning sql/item_cmpfunc.cc: Removed compiler warning sql/sql_handler.cc: Remove wrong fix for Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash. It's better to let mysql_lock_tables reopen the TABLE object in case of OPTIMIZE TABLE and fix items AFTER mysql_lock_table() instead of before sql/sql_select.cc: Safety fix for bug #13855 "select distinct with group by caused server crash" The previous patch only removed the symptomps, this fix removed the cause of the problem (Which was that not all hidden_fields was stored in the temporary table) --- client/mysqlimport.c | 1 - myisam/myisam_ftdump.c | 2 +- sql/item_cmpfunc.cc | 2 +- sql/sql_handler.cc | 46 ++++++++++++---------------------------------- sql/sql_select.cc | 9 ++++++++- 5 files changed, 22 insertions(+), 38 deletions(-) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 0932cf7432a..2dcb1d4eb6d 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -252,7 +252,6 @@ static int write_to_table(char *filename, MYSQL *sock) { char tablename[FN_REFLEN], hard_path[FN_REFLEN], sql_statement[FN_REFLEN*16+256], *end; - my_bool local_file; DBUG_ENTER("write_to_table"); DBUG_PRINT("enter",("filename: %s",filename)); diff --git a/myisam/myisam_ftdump.c b/myisam/myisam_ftdump.c index 838f90feae5..005d15376fb 100644 --- a/myisam/myisam_ftdump.c +++ b/myisam/myisam_ftdump.c @@ -66,7 +66,7 @@ int main(int argc,char *argv[]) struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */ MY_INIT(argv[0]); - if (error=handle_options(&argc, &argv, my_long_options, get_one_option)) + if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) exit(error); if (count || dump) verbose=0; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 107a17815ae..db6c4d9789b 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -659,7 +659,7 @@ bool Item_func_nullif::is_null() { if (!(this->*cmp_func)()) - return null_value=1; + return (null_value= 1); return 0; } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 28e94d1a477..58b75e667b5 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -380,27 +380,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' tab %p", hash_tables->db, hash_tables->real_name, hash_tables->alias, table)); - /* Table might have been flushed. */ - if (table && (table->version != refresh_version)) - { - /* - We must follow the thd->handler_tables chain, as we need the - address of the 'next' pointer referencing this table - for close_thread_table(). - */ - for (table_ptr= &(thd->handler_tables); - *table_ptr && (*table_ptr != table); - table_ptr= &(*table_ptr)->next) - {} - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, table_ptr)) - { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); - } - VOID(pthread_mutex_unlock(&LOCK_open)); - table= hash_tables->table= NULL; - } if (!table) { /* @@ -447,11 +426,16 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, } tables->table=table; + HANDLER_TABLES_HACK(thd); + lock= mysql_lock_tables(thd, &tables->table, 1, 0); + HANDLER_TABLES_HACK(thd); + + if (!lock) + goto err0; // mysql_lock_tables() printed error message already + if (cond && cond->fix_fields(thd,tables)) goto err0; - table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it - if (keyname) { if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0) @@ -462,6 +446,11 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, } table->file->index_init(keyno); } + + byte *key; + uint key_len; + LINT_INIT(key); + LINT_INIT(key_len); if (insert_fields(thd,tables,tables->db,tables->alias,&it)) goto err0; @@ -469,17 +458,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, select_limit+=offset_limit; send_fields(thd,list,1); - HANDLER_TABLES_HACK(thd); - lock= mysql_lock_tables(thd, &tables->table, 1, 0); - HANDLER_TABLES_HACK(thd); - - byte *key; - uint key_len; - LINT_INIT(key); - LINT_INIT(key_len); - if (!lock) - goto err0; // mysql_lock_tables() printed error message already - table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it for (num_rows=0; num_rows < select_limit; ) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6dd68a60f88..32658f92416 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4082,7 +4082,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, *(reg_field++) =new_field; } if (!--hidden_field_count) + { hidden_null_count=null_count; + /* + We need to update hidden_field_count as we may have stored group + functions with constant arguments + */ + param->hidden_field_count= (uint) (reg_field - table->field); + } } DBUG_ASSERT(field_count >= (uint) (reg_field - table->field)); field_count= (uint) (reg_field - table->field); @@ -4270,7 +4277,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, } } - if (distinct) + if (distinct && field_count != param->hidden_field_count) { /* Create an unique key or an unique constraint over all columns -- cgit v1.2.1 From e12bc697db8509602cd7c765fbd95d8543ad6308 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 11:10:49 +0200 Subject: After merge fix (Lines lost in manual merge) --- sql/sql_handler.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index a69bf04cc48..765a057f740 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -454,6 +454,9 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, if (insert_fields(thd,tables,tables->db,tables->alias,&it)) goto err0; + select_limit+=offset_limit; + protocol->send_fields(&list,1); + /* In ::external_lock InnoDB resets the fields which tell it that the handle is used in the HANDLER interface. Tell it again that -- cgit v1.2.1 From af024409afac7b9ded1f5c431e08f3b26699bcf6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 19:13:12 +0200 Subject: Re-run fix-fields on condition if table was reopened in HANDLERREAD sql/sql_base.cc: Added more comments sql/sql_handler.cc: Re-run fix-fields on condition if table was reopened --- sql/sql_base.cc | 20 ++++++++++++++++---- sql/sql_handler.cc | 11 ++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c8443948a4a..ea013bb4e1e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1012,10 +1012,20 @@ TABLE *find_locked_table(THD *thd, const char *db,const char *table_name) /**************************************************************************** -** Reopen an table because the definition has changed. The date file for the -** table is already closed. -** Returns 0 if ok. -** If table can't be reopened, the entry is unchanged. + Reopen an table because the definition has changed. The date file for the + table is already closed. + + SYNOPSIS + reopen_table() + table Table to be opened + locked 1 if we have already a lock on LOCK_open + + NOTES + table->query_id will be 0 if table was reopened + + RETURN + 0 ok + 1 error ('table' is unchanged if table couldn't be reopened) ****************************************************************************/ bool reopen_table(TABLE *table,bool locked) @@ -1085,8 +1095,10 @@ bool reopen_table(TABLE *table,bool locked) (*field)->table_name=table->table_name; } for (key=0 ; key < table->keys ; key++) + { for (part=0 ; part < table->key_info[key].usable_key_parts ; part++) table->key_info[key].key_part[part].field->table= table; + } VOID(pthread_cond_broadcast(&COND_refresh)); error=0; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 765a057f740..1c5381a9fa0 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -437,9 +437,14 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, if (!lock) goto err0; // mysql_lock_tables() printed error message already - if (cond && ((!cond->fixed && - cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1))) - goto err0; + if (cond) + { + if (table->query_id != thd->query_id) + cond->cleanup(); // File was reopened + if ((!cond->fixed && + cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1)) + goto err0; + } if (keyname) { -- cgit v1.2.1 From 2946f9a64f664293010777e422e7b66058ce323a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 15:10:12 +0200 Subject: NetWare specific change to increase thread stack size. Changes to Netware specific mysqld_safe.c include/config-netware.h: NetWare specific change to increase thread stack size. innobase/os/os0thread.c: NetWare specific change to increase thread stack size. netware/mysqld_safe.c: NetWare specific change to make multiple mysqld_safe instances work when called through a NCF file. sql/mysqld.cc: NetWare specific change to increase thread stack size. --- include/config-netware.h | 3 +++ innobase/os/os0thread.c | 9 +++++++++ netware/mysqld_safe.c | 42 +++++++++++++++--------------------------- sql/mysqld.cc | 5 +++++ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/include/config-netware.h b/include/config-netware.h index e07e972ba4b..43ee05e39ee 100644 --- a/include/config-netware.h +++ b/include/config-netware.h @@ -92,6 +92,9 @@ extern "C" { /* On NetWare, stack grows towards lower address*/ #define STACK_DIRECTION -1 +/* On NetWare, we need to set stack size for threads, otherwise default 16K is used */ +#define NW_THD_STACKSIZE 65536 + /* On NetWare, to fix the problem with the deletion of open files */ #define CANT_DELETE_OPEN_FILES 1 diff --git a/innobase/os/os0thread.c b/innobase/os/os0thread.c index 59d0fdbd8c9..cb72310f23d 100644 --- a/innobase/os/os0thread.c +++ b/innobase/os/os0thread.c @@ -147,6 +147,15 @@ os_thread_create( "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); exit(1); } +#endif +#ifdef __NETWARE__ + ret = pthread_attr_setstacksize(&attr, + (size_t) NW_THD_STACKSIZE); + if (ret) { + fprintf(stderr, + "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); + exit(1); + } #endif os_mutex_enter(os_sync_mutex); os_thread_count++; diff --git a/netware/mysqld_safe.c b/netware/mysqld_safe.c index dbb49882140..5f65e2f45b7 100644 --- a/netware/mysqld_safe.c +++ b/netware/mysqld_safe.c @@ -252,51 +252,39 @@ void finish_defaults() ******************************************************************************/ void read_defaults(arg_list_t *pal) { - arg_list_t al; - char defaults_file[PATH_MAX]; char mydefaults[PATH_MAX]; + char mydefaults_command[3*PATH_MAX]; char line[PATH_MAX]; FILE *fp; - // defaults output file - snprintf(defaults_file, PATH_MAX, "%s/bin/defaults.out", basedir); - remove(defaults_file); - - // mysqladmin file + // my_print_defaults file snprintf(mydefaults, PATH_MAX, "%s/bin/my_print_defaults", basedir); - // args - init_args(&al); - add_arg(&al, mydefaults); - if (default_option[0]) add_arg(&al, default_option); - add_arg(&al, "mysqld"); - add_arg(&al, "server"); - add_arg(&al, "mysqld_safe"); - add_arg(&al, "safe_mysqld"); - - spawn(mydefaults, &al, TRUE, NULL, defaults_file, NULL); - - free_args(&al); - + // args to my_print_defaults + if (default_option[0]) + { + snprintf(mydefaults_command, 3*PATH_MAX, "%s %s mysqld server mysqld_safe safe_mysqld", mydefaults, default_option); + } + else + { + snprintf(mydefaults_command, 3*PATH_MAX, "%s mysqld server mysqld_safe safe_mysqld", mydefaults); + } // gather defaults - if((fp = fopen(defaults_file, "r")) != NULL) + if((fp = popen(mydefaults_command, "r")) != NULL) { while(fgets(line, PATH_MAX, fp)) { char *p; // remove end-of-line character - if ((p = strrchr(line, '\n')) != NULL) *p = '\0'; + if ((p = strrchr(line, '\n')) != NULL) + *p = '\0'; // add the option as an argument add_arg(pal, line); } - - fclose(fp); + pclose(fp); } - - // remove file - remove(defaults_file); } /****************************************************************************** diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f7df7233795..00bcdbf7132 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2401,6 +2401,11 @@ You should consider changing lower_case_table_names to 1 or 2", thread_stack= stack_size; } } +#endif +#ifdef __NETWARE__ + /* Increasing stacksize of threads on NetWare */ + + pthread_attr_setstacksize(&connection_attrib, NW_THD_STACKSIZE); #endif if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); -- cgit v1.2.1