diff options
author | hf@deer.mysql.r18.ru <> | 2003-01-28 12:59:07 +0400 |
---|---|---|
committer | hf@deer.mysql.r18.ru <> | 2003-01-28 12:59:07 +0400 |
commit | 6bca9b7034d736e1aa78ed4b3204d26b712d1623 (patch) | |
tree | 91ecc381255a1f6b27acaad85c16ac20d6be0d0f /sql | |
parent | 524e33eb5916a10ff363959f589fdd388ee7a5a7 (diff) | |
parent | 6fea54dd8ddb6ee0cd74a30ca6a503ec3919d073 (diff) | |
download | mariadb-git-6bca9b7034d736e1aa78ed4b3204d26b712d1623.tar.gz |
Merge abotchkov@work.mysql.com:/home/bk/mysql-4.1
into deer.mysql.r18.ru:/home/hf/work/mysql-default
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 51 | ||||
-rw-r--r-- | sql/ha_innodb.cc | 21 | ||||
-rw-r--r-- | sql/item.cc | 29 | ||||
-rw-r--r-- | sql/item.h | 7 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 68 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 19 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 7 | ||||
-rw-r--r-- | sql/mysqld.cc | 274 | ||||
-rw-r--r-- | sql/protocol.cc | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 11 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 93 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 | ||||
-rw-r--r-- | sql/sql_string.cc | 2 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 72 |
14 files changed, 374 insertions, 286 deletions
diff --git a/sql/field.cc b/sql/field.cc index 00bb409e82e..0fa306fe718 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1652,11 +1652,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) long tmp; int error= 0; char *end; - /* TODO: Make multi-byte-character safe */ - while (len && my_isspace(cs,*from)) - { - len--; from++; - } + + tmp= cs->scan(cs, from, from+len, MY_SEQ_SPACES); + len-= tmp; + from+= tmp; my_errno=0; if (unsigned_flag) { @@ -1910,11 +1909,10 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) longlong tmp; int error= 0; char *end; - /* TODO: Make multi byte safe */ - while (len && my_isspace(cs,*from)) - { // For easy error check - len--; from++; - } + + tmp= cs->scan(cs, from, from+len, MY_SEQ_SPACES); + len-= tmp; + from+= tmp; my_errno=0; if (unsigned_flag) { @@ -3878,14 +3876,6 @@ void Field_datetime::sql_type(String &res) const int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) { int error= 0; -#ifdef USE_TIS620 - if (!binary()) { - ThNormalize((uchar *)ptr, field_length, (uchar *)from, length); - if (length < field_length) { - bfill(ptr + length, field_length - length, ' '); - } - } -#else if (length <= field_length) { memcpy(ptr,from,length); @@ -3909,7 +3899,6 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) } } } -#endif /* USE_TIS620 */ return error; } @@ -4062,12 +4051,6 @@ uint Field_string::max_packed_col_length(uint max_length) int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) { int error= 0; -#ifdef USE_TIS620 - if (!binary()) - { - ThNormalize((uchar *) ptr+2, field_length, (uchar *) from, length); - } -#else if (length > field_length) { length=field_length; @@ -4075,7 +4058,6 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs) error= 1; } memcpy(ptr+2,from,length); -#endif /* USE_TIS620 */ int2store(ptr, length); return error; } @@ -4376,28 +4358,11 @@ int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs) } else { -#ifdef USE_TIS620 - char *th_ptr=0; -#endif Field_blob::store_length(len); if (table->copy_blobs || len <= MAX_FIELD_WIDTH) { // Must make a copy -#ifdef USE_TIS620 - if (!binary()) - { - /* If there isn't enough memory, use original string */ - if ((th_ptr=(char * ) my_malloc(sizeof(char) * len,MYF(0)))) - { - ThNormalize((uchar *) th_ptr, len, (uchar *) from, len); - from= (const char*) th_ptr; - } - } -#endif /* USE_TIS620 */ value.copy(from,len,charset()); from=value.ptr(); -#ifdef USE_TIS620 - my_free(th_ptr,MYF(MY_ALLOW_ZERO_PTR)); -#endif } bmove(ptr+packlength,(char*) &from,sizeof(char*)); } diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index c639431c0fa..e4ffeef85c3 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -1672,18 +1672,31 @@ build_template( field = table->field[i]; if (templ_type == ROW_MYSQL_REC_FIELDS + && prebuilt->read_just_key + && dict_index_get_nth_col_pos(index, i) + == ULINT_UNDEFINED) { + /* Skip a column which is not in the index */ + + goto skip_field; + } + + + /* TODO: we have removed temporarily the test of which columns + to fetch, until the new client/server protocol of 4.1 + is fixed!!!!!!!!!!!!!!!!! + + if (templ_type == ROW_MYSQL_REC_FIELDS && !(fetch_all_in_key && - ULINT_UNDEFINED != dict_index_get_nth_col_pos( - index, i)) + ULINT_UNDEFINED != dict_index_get_nth_col_pos( + index, i)) && thd->query_id != field->query_id && thd->query_id != (field->query_id ^ MAX_ULONG_BIT) && thd->query_id != (field->query_id ^ (MAX_ULONG_BIT >> 1))) { - /* This field is not needed in the query, skip it */ - goto skip_field; } + */ n_requested_fields++; diff --git a/sql/item.cc b/sql/item.cc index f1fee7e8ef1..575c5b4d89c 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -347,6 +347,25 @@ void Item_param::set_value(const char *str, uint length) } +void Item_param::set_time(TIME *tm, timestamp_type type) +{ + ltime.year= tm->year; + ltime.month= tm->month; + ltime.day= tm->day; + + ltime.hour= tm->hour; + ltime.minute= tm->minute; + ltime.second= tm->second; + + ltime.second_part= tm->second_part; + + ltime.time_type= type; + + item_is_time= true; + item_type= STRING_ITEM; +} + + void Item_param::set_longdata(const char *str, ulong length) { str_value.append(str,length); @@ -369,11 +388,21 @@ int Item_param::save_in_field(Field *field, bool no_conversions) { double nr=val(); return (field->store(nr)) ? -1 : 0; + } + if (item_is_time) + { + field->store_time(<ime, ltime.time_type); + return 0; } String *result=val_str(&str_value); return (field->store(result->ptr(),result->length(),field->charset())) ? -1 : 0; } +bool Item_param::get_time(TIME *res) +{ + *res=ltime; + return 0; +} double Item_param::val() { diff --git a/sql/item.h b/sql/item.h index ee68563d5cf..7aa33b25db8 100644 --- a/sql/item.h +++ b/sql/item.h @@ -202,9 +202,11 @@ class Item_param :public Item public: longlong int_value; double real_value; + TIME ltime; enum Item_result item_result_type; enum Type item_type; enum enum_field_types buffer_type; + bool item_is_time; my_bool long_data_supplied; Item_param(char *name_par=0) @@ -213,6 +215,7 @@ public: long_data_supplied= false; item_type= STRING_ITEM; item_result_type = STRING_RESULT; + item_is_time= false; } enum Type type() const { return item_type; } double val(); @@ -227,6 +230,8 @@ public: void set_long_binary(const char *str, ulong length); void set_longdata(const char *str, ulong length); void set_long_end(); + void set_time(TIME *tm, timestamp_type type); + bool get_time(TIME *tm); void reset() {} void (*setup_param_func)(Item_param *param, uchar **pos); enum Item_result result_type () const @@ -556,12 +561,12 @@ public: #include "spatial.h" #include "item_sum.h" #include "item_func.h" +#include "item_row.h" #include "item_cmpfunc.h" #include "item_strfunc.h" #include "item_timefunc.h" #include "item_uniq.h" #include "item_subselect.h" -#include "item_row.h" class Item_copy_string :public Item { diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 1c579708503..06b7dc451dc 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -392,51 +392,44 @@ longlong Item_func_strcmp::val_int() return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1); } - void Item_func_interval::fix_length_and_dec() { - bool nums=1; - uint i; - for (i=0 ; i < arg_count ; i++) + if (row->cols() > 8) { - if (!args[i]) - return; // End of memory - if (args[i]->type() != Item::INT_ITEM && - args[i]->type() != Item::REAL_ITEM) + bool consts=1; + + for (uint i=1 ; consts && i < row->cols() ; i++) { - nums=0; - break; + consts&= row->el(i)->const_item(); } - } - if (nums && arg_count >= 8) - { - if ((intervals=(double*) sql_alloc(sizeof(double)*arg_count))) + + if (consts && + (intervals=(double*) sql_alloc(sizeof(double)*(row->cols()-1)))) { - for (i=0 ; i < arg_count ; i++) - intervals[i]=args[i]->val(); + for (uint i=1 ; i < row->cols(); i++) + intervals[i-1]=row->el(i)->val(); } } maybe_null= 0; max_length= 2; - used_tables_cache|=item->used_tables(); } /* return -1 if null value, 0 if lower than lowest - 1 - arg_count if between args[n] and args[n+1] - arg_count+1 if higher than biggest argument + 1 - arg_count-1 if between args[n] and args[n+1] + arg_count if higher than biggest argument */ longlong Item_func_interval::val_int() { - double value=item->val(); - if (item->null_value) - return -1; // -1 if null /* purecov: inspected */ + double value=row->el(0)->val(); + if (row->el(0)->null_value) + return -1; // -1 if null if (intervals) { // Use binary search to find interval uint start,end; - start=0; end=arg_count-1; + start=1; end=row->cols()-2; while (start != end) { uint mid=(start+end+1)/2; @@ -447,31 +440,14 @@ longlong Item_func_interval::val_int() } return (value < intervals[start]) ? 0 : start+1; } - if (args[0]->val() > value) - return 0; - for (uint i=1 ; i < arg_count ; i++) + + uint i; + for (i=1 ; i < row->cols() ; i++) { - if (args[i]->val() > value) - return i; + if (row->el(i)->val() > value) + return i-1; } - return (longlong) arg_count; -} - - -void Item_func_interval::update_used_tables() -{ - Item_func::update_used_tables(); - item->update_used_tables(); - used_tables_cache|=item->used_tables(); - const_item_cache&=item->const_item(); -} - -bool Item_func_interval::check_loop(uint id) -{ - DBUG_ENTER("Item_func_interval::check_loop"); - if (Item_func::check_loop(id)) - DBUG_RETURN(1); - DBUG_RETURN(item->check_loop(id)); + return i-1; } void Item_func_between::fix_length_and_dec() diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 8641ab410b3..1bb85a9e233 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -267,27 +267,14 @@ public: class Item_func_interval :public Item_int_func { - Item *item; + Item_row *row; double *intervals; public: - Item_func_interval(Item *a,List<Item> &list) - :Item_int_func(list),item(a),intervals(0) {} + Item_func_interval(Item_row *a) + :Item_int_func(a),row(a),intervals(0) { allowed_arg_cols= a->cols(); } longlong val_int(); - bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref) - { - return (item->fix_fields(thd, tlist, &item) || item->check_cols(1) || - Item_func::fix_fields(thd, tlist, ref)); - } void fix_length_and_dec(); - ~Item_func_interval() { delete item; } const char *func_name() const { return "interval"; } - void update_used_tables(); - bool check_loop(uint id); - void set_outer_resolving() - { - item->set_outer_resolving(); - Item_func::set_outer_resolving(); - } }; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 66f0510cc3d..03dd940db51 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2014,9 +2014,8 @@ String *Item_func_conv_charset::val_str(String *str) d0=d=(unsigned char*)str->ptr(); de=d+dmaxlen; - while (s < se && d < de) + while (1) { - cnvres=from->mb_wc(from,&wc,s,se); if (cnvres>0) { @@ -2089,8 +2088,8 @@ String *Item_func_conv_charset3::val_str(String *str) d0=d=(unsigned char*)str->ptr(); de=d+dmaxlen; - while (s < se && d < de){ - + while (1) + { cnvres=from_charset->mb_wc(from_charset,&wc,s,se); if (cnvres>0) { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 3b34f111e8d..1bbd5914d36 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -670,6 +670,7 @@ static void close_connections(void) } #endif /*EMBEDDED_LIBRARY*/ + static void close_server_sock() { #ifdef HAVE_CLOSE_SERVER_SOCK @@ -760,8 +761,6 @@ void kill_mysql(void) DBUG_VOID_RETURN; } -#ifndef EMBEDDED_LIBRARY - /* Force server down. kill all connections and threads and exit */ #if defined(OS2) @@ -777,7 +776,7 @@ static void __cdecl kill_server(int sig_ptr) { int sig=(int) (long) sig_ptr; // This is passed a int DBUG_ENTER("kill_server"); - +#ifndef EMBEDDED_LIBRARY // if there is a signal during the kill in progress, ignore the other if (kill_in_progress) // Safety RETURN_FROM_KILL_SERVER; @@ -798,19 +797,17 @@ static void __cdecl kill_server(int sig_ptr) else unireg_end(); pthread_exit(0); /* purecov: deadcode */ +#endif /* EMBEDDED_LIBRARY */ RETURN_FROM_KILL_SERVER; } -#endif /* EMBEDDED_LIBRARY */ #ifdef USE_ONE_SIGNAL_HAND extern "C" pthread_handler_decl(kill_server_thread,arg __attribute__((unused))) { SHUTDOWN_THD; my_thread_init(); // Initialize new thread -#ifndef EMBEDDED_LIBRARY kill_server(0); -#endif /* EMBEDDED_LIBRARY */ my_thread_end(); // Normally never reached return 0; } @@ -1047,6 +1044,7 @@ static void set_root(const char *path) #endif } + static void server_init(void) { struct sockaddr_in IPaddr; @@ -1158,7 +1156,7 @@ static void server_init(void) { DBUG_PRINT("general",("UNIX Socket is %s",mysql_unix_port)); - if ((unix_sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { sql_perror("Can't start server : UNIX Socket "); /* purecov: inspected */ unireg_abort(1); /* purecov: inspected */ @@ -1201,6 +1199,7 @@ void yyerror(const char *s) thd->lex.yylineno); } + #ifndef EMBEDDED_LIBRARY void close_connection(NET *net,uint errcode,bool lock) { @@ -1221,7 +1220,8 @@ void close_connection(NET *net,uint errcode,bool lock) (void) pthread_mutex_unlock(&LOCK_thread_count); DBUG_VOID_RETURN; } -#endif +#endif /* EMBEDDED_LIBRARY */ + /* Called when a thread is aborted */ /* ARGSUSED */ @@ -1772,7 +1772,7 @@ extern "C" pthread_handler_decl(handle_shutdown,arg) PeekMessage(&msg, NULL, 1, 65534,PM_NOREMOVE); #if !defined(EMBEDDED_LIBRARY) if (WaitForSingleObject(hEventShutdown,INFINITE)==WAIT_OBJECT_0) -#endif +#endif /* EMBEDDED_LIBRARY */ kill_server(MYSQL_KILL_SIGNAL); return 0; } @@ -1789,6 +1789,7 @@ int __stdcall handle_kill(ulong ctrl_type) } #endif + #ifdef OS2 extern "C" pthread_handler_decl(handle_shutdown,arg) { @@ -1856,8 +1857,8 @@ bool open_log(MYSQL_LOG *log, const char *hostname, } -static int init_common_variables(const char *conf_file_name, int argc, char **argv, - const char **groups) +static int init_common_variables(const char *conf_file_name, int argc, + char **argv, const char **groups) { my_umask=0660; // Default umask for new files my_umask_dir=0700; // Default umask for new directories @@ -1943,12 +1944,12 @@ static int init_common_variables(const char *conf_file_name, int argc, char **ar charsets_list= list_charsets(MYF(MY_CS_COMPILED | MY_CS_CONFIG)); if (use_temp_pool && bitmap_init(&temp_pool,1024,1)) - return 2; - + return 1; return 0; } -static int init_thread_environement() + +static int init_thread_environment() { (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_Acl,MY_MUTEX_INIT_SLOW); @@ -1966,9 +1967,6 @@ static int init_thread_environement() (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_timezone,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST); -#ifdef HAVE_REPLICATION - (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST); -#endif (void) pthread_mutex_init(&LOCK_active_mi, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_global_system_variables, MY_MUTEX_INIT_FAST); (void) my_rwlock_init(&LOCK_grant, NULL); @@ -1978,14 +1976,16 @@ static int init_thread_environement() (void) pthread_cond_init(&COND_flush_thread_cache,NULL); (void) pthread_cond_init(&COND_manager,NULL); #ifdef HAVE_REPLICATION + (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST); (void) pthread_cond_init(&COND_rpl_status, NULL); #endif /* Parameter for threads created for connections */ (void) pthread_attr_init(&connection_attrib); (void) pthread_attr_setdetachstate(&connection_attrib, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&connection_attrib,thread_stack); pthread_attr_setscope(&connection_attrib, PTHREAD_SCOPE_SYSTEM); + if (!(opt_specialflag & SPECIAL_NO_PRIOR)) + my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); if (pthread_key_create(&THR_THD,NULL) || pthread_key_create(&THR_MALLOC,NULL)) @@ -1993,12 +1993,10 @@ static int init_thread_environement() sql_print_error("Can't create thread-keys"); return 1; } - - (void) thr_setconcurrency(concurrency); // 10 by default - return 0; } + static void init_ssl() { #ifdef HAVE_OPENSSL @@ -2017,6 +2015,7 @@ static void init_ssl() #endif /* HAVE_OPENSSL */ } + static int init_server_components() { table_cache_init(); @@ -2039,15 +2038,24 @@ static int init_server_components() NullS, LOG_NEW); using_update_log=1; } - if (opt_slow_log) open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log", NullS, LOG_NORMAL); + + if (opt_bin_log) + { + open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin", + opt_binlog_index_name,LOG_BIN); + using_update_log=1; + } + if (ha_init()) { sql_print_error("Can't init databases"); return 1; } + if (opt_myisam_log) + (void) mi_log(1); ha_key_cache(); #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) @@ -2064,23 +2072,14 @@ static int init_server_components() locked_in_memory=0; #endif - if (opt_myisam_log) - (void) mi_log( 1 ); ft_init_stopwords(ft_precompiled_stopwords); init_max_user_conn(); init_update_queries(); - - if (opt_bin_log) - { - open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin", - opt_binlog_index_name,LOG_BIN); - using_update_log=1; - } - return 0; } + static void create_maintenance_thread() { if ( @@ -2095,74 +2094,88 @@ static void create_maintenance_thread() } } + static void create_shutdown_thread() { - #ifdef __WIN__ - { - hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name); - pthread_t hThread; - if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0)) - sql_print_error("Warning: Can't create thread to handle shutdown requests"); + hEventShutdown=CreateEvent(0, FALSE, FALSE, shutdown_event_name); + pthread_t hThread; + if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0)) + sql_print_error("Warning: Can't create thread to handle shutdown requests"); - // On "Stop Service" we have to do regular shutdown - Service.SetShutdownEvent(hEventShutdown); - } + // On "Stop Service" we have to do regular shutdown + Service.SetShutdownEvent(hEventShutdown); #endif #ifdef OS2 - { - pthread_cond_init( &eventShutdown, NULL); - pthread_t hThread; - if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0)) - sql_print_error("Warning: Can't create thread to handle shutdown requests"); - } + pthread_cond_init(&eventShutdown, NULL); + pthread_t hThread; + if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0)) + sql_print_error("Warning: Can't create thread to handle shutdown requests"); #endif } -#ifdef __NT__ -void create_named_pipe_thread() + +#if defined(__NT__) || defined(HAVE_SMEM) +static void handle_connections_methods() { + pthread_t hThread; + DBUG_ENTER("handle_connections_methods"); +#ifdef __NT__ if (hPipe == INVALID_HANDLE_VALUE && - (!have_tcpip || opt_disable_networking)) + (!have_tcpip || opt_disable_networking) && + !opt_enable_shared_memory) { - sql_print_error("TCP/IP or --enable-named-pipe should be configured on NT OS"); - unireg_abort(1); + sql_print_error("TCP/IP,--shared-memory or --named-pipe should be configured on NT OS"); + unireg_abort(1); // Will not return } - else +#endif + + pthread_mutex_lock(&LOCK_thread_count); + (void) pthread_cond_init(&COND_handler_count,NULL); + handler_count=0; +#ifdef __NT__ + if (hPipe != INVALID_HANDLE_VALUE) { - pthread_mutex_lock(&LOCK_thread_count); - (void) pthread_cond_init(&COND_handler_count,NULL); + handler_count++; + if (pthread_create(&hThread,&connection_attrib, + handle_connections_namedpipes, 0)) { - pthread_t hThread; - handler_count=0; - if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe) - { - handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_namedpipes, 0)) - { - sql_print_error("Warning: Can't create thread to handle named pipes"); - handler_count--; - } - } - if (have_tcpip && !opt_disable_networking) - { - handler_count++; - if (pthread_create(&hThread,&connection_attrib, - handle_connections_sockets, 0)) - { - sql_print_error("Warning: Can't create thread to handle named pipes"); - handler_count--; - } - } - while (handler_count > 0) - pthread_cond_wait(&COND_handler_count,&LOCK_thread_count); + sql_print_error("Warning: Can't create thread to handle named pipes"); + handler_count--; + } + } +#endif /* __NT__ */ + if (have_tcpip && !opt_disable_networking) + { + handler_count++; + if (pthread_create(&hThread,&connection_attrib, + handle_connections_sockets, 0)) + { + sql_print_error("Warning: Can't create thread to handle TCP/IP"); + handler_count--; + } + } +#ifdef HAVE_SMEM + if (opt_enable_shared_memory) + { + handler_count++; + if (pthread_create(&hThread,&connection_attrib, + handle_connections_shared_memory, 0)) + { + sql_print_error("Warning: Can't create thread to handle shared memory"); + handler_count--; } - pthread_mutex_unlock(&LOCK_thread_count); } -} #endif + while (handler_count > 0) + pthread_cond_wait(&COND_handler_count,&LOCK_thread_count); + pthread_mutex_unlock(&LOCK_thread_count); + DBUG_VOID_RETURN; +} +#endif /* defined(__NT__) || defined(HAVE_SMEM) */ + + #ifndef EMBEDDED_LIBRARY #ifdef __WIN__ int win_main(int argc, char **argv) @@ -2170,10 +2183,10 @@ int win_main(int argc, char **argv) int main(int argc, char **argv) #endif { - int init_error; - DEBUGGER_OFF; + MY_INIT(argv[0]); // init my_sys library & pthreads + #ifdef _CUSTOMSTARTUPCONFIG_ if (_cust_check_startup()) { @@ -2182,26 +2195,20 @@ int main(int argc, char **argv) } #endif - MY_INIT(argv[0]); // init my_sys library & pthreads - - if ((init_error=init_common_variables(MYSQL_CONFIG_NAME, - argc, argv, load_default_groups))) - if (init_error == 2) - unireg_abort(1); - else - exit(1); + if (init_common_variables(MYSQL_CONFIG_NAME, + argc, argv, load_default_groups)) + unireg_abort(1); // Will do exit init_signals(); - if (init_thread_environement()) - exit(1); - select_thread=pthread_self(); - select_thread_in_use=1; if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),CONNECT_PRIOR); + if (init_thread_environment()) + unireg_abort(1); + pthread_attr_setstacksize(&connection_attrib,thread_stack); + (void) thr_setconcurrency(concurrency); // 10 by default - if (!(opt_specialflag & SPECIAL_NO_PRIOR)) - my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); - + select_thread=pthread_self(); + select_thread_in_use=1; init_ssl(); #ifdef HAVE_LIBWRAP @@ -2224,21 +2231,21 @@ int main(int argc, char **argv) if (opt_bin_log && !server_id) { server_id= !master_host ? 1 : 2; - switch (server_id) { #ifdef EXTRA_DEBUG + switch (server_id) { case 1: sql_print_error("\ Warning: You have enabled the binary log, but you haven't set server-id:\n\ Updates will be logged to the binary log, but connections to slaves will\n\ not be accepted."); break; -#endif case 2: sql_print_error("\ Warning: You should set server-id to a non-0 value if master_host is set.\n\ The server will not act as a slave."); break; } +#endif } if (init_server_components()) @@ -2250,12 +2257,8 @@ The server will not act as a slave."); { freopen(MYSQL_ERR_FILE,"a+",stdout); freopen(MYSQL_ERR_FILE,"a+",stderr); - } -#endif - -#ifdef __WIN__ - if (!opt_console) FreeConsole(); // Remove window + } #endif /* @@ -2273,6 +2276,8 @@ The server will not act as a slave."); if (!opt_bootstrap) (void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore #endif + if (unix_sock != INVALID_SOCKET) + unlink(mysql_unix_port); exit(1); } if (!opt_noacl) @@ -2306,13 +2311,10 @@ The server will not act as a slave."); printf(ER(ER_READY),my_progname,server_version,""); fflush(stdout); -#ifdef __NT__ - create_named_pipe_thread(); +#if defined(__NT__) || defined(HAVE_SMEM) + handle_connections_methods(); #else handle_connections_sockets(0); -#ifdef EXTRA_DEBUG2 - sql_print_error("Exiting main thread"); -#endif #endif /* __NT__ */ /* (void) pthread_attr_destroy(&connection_attrib); */ @@ -2494,13 +2496,14 @@ int main(int argc, char **argv) Execute all commands from a file. Used by the mysql_install_db script to create MySQL privilege tables without having to start a full MySQL server. */ -#ifndef EMBEDDED_LIBRARY + static int bootstrap(FILE *file) { - THD *thd= new THD; - int error; + THD *thd; + int error= 0; DBUG_ENTER("bootstrap"); - +#ifndef EMBEDDED_LIBRARY // TODO: Enable this + thd= new THD; thd->bootstrap=1; thd->client_capabilities=0; my_net_init(&thd->net,(st_vio*) 0); @@ -2528,10 +2531,10 @@ static int bootstrap(FILE *file) net_end(&thd->net); thd->cleanup(); delete thd; +#endif /* EMBEDDED_LIBRARY */ DBUG_RETURN(error); } -#endif static bool read_init_file(char *file_name) { @@ -2540,15 +2543,13 @@ static bool read_init_file(char *file_name) DBUG_PRINT("enter",("name: %s",file_name)); if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME)))) return(1); -#ifndef EMBEDDED_LIBRARY bootstrap(file); /* Ignore errors from this */ -#endif (void) my_fclose(file,MYF(MY_WME)); return 0; } -#ifndef EMBEDDED_LIBRARY +#ifndef EMBEDDED_LIBRARY static void create_new_thread(THD *thd) { DBUG_ENTER("create_new_thread"); @@ -2629,7 +2630,8 @@ static void create_new_thread(THD *thd) DBUG_PRINT("info",("Thread created")); DBUG_VOID_RETURN; } -#endif +#endif /* EMBEDDED_LIBRARY */ + #ifdef SIGNALS_DONT_BREAK_READ inline void kill_broken_server() @@ -2647,10 +2649,11 @@ inline void kill_broken_server() #define MAYBE_BROKEN_SYSCALL #endif -#ifndef EMBEDDED_LIBRARY /* Handle new connections and spawn new process to handle them */ -extern "C" pthread_handler_decl(handle_connections_sockets,arg __attribute__((unused))) +#ifndef EMBEDDED_LIBRARY +extern "C" pthread_handler_decl(handle_connections_sockets, + arg __attribute__((unused))) { my_socket sock,new_sock; uint error_count=0; @@ -2939,6 +2942,7 @@ extern "C" pthread_handler_decl(handle_connections_namedpipes,arg) } #endif /* __NT__ */ + /* Thread of shared memory's service @@ -2947,6 +2951,7 @@ extern "C" pthread_handler_decl(handle_connections_namedpipes,arg) handle_connections_shared_memory Thread handle arg Arguments of thread */ + #ifdef HAVE_SMEM pthread_handler_decl(handle_connections_shared_memory,arg) { @@ -2979,13 +2984,13 @@ pthread_handler_decl(handle_connections_shared_memory,arg) DBUG_PRINT("general",("Waiting for allocated shared memory.")); -/* - The name of event and file-mapping events create agree next rule: - shared_memory_base_name+unique_part - Where: - shared_memory_base_name is unique value for each server - unique_part is unique value for each object (events and file-mapping) -*/ + /* + The name of event and file-mapping events create agree next rule: + shared_memory_base_name+unique_part + Where: + shared_memory_base_name is unique value for each server + unique_part is unique value for each object (events and file-mapping) + */ suffix_pos = strxmov(tmp,shared_memory_base_name,"_",NullS); strmov(suffix_pos, "CONNECT_REQUEST"); if ((event_connect_request = CreateEvent(NULL,FALSE,FALSE,tmp)) == 0) @@ -3151,14 +3156,15 @@ error: DBUG_RETURN(0); } #endif /* HAVE_SMEM */ - #endif /* EMBEDDED_LIBRARY */ -/****************************************************************************** -** handle start options + +/**************************************************************************** + Handle start options ******************************************************************************/ -enum options { +enum options +{ OPT_ISAM_LOG=256, OPT_SKIP_NEW, OPT_SKIP_GRANT, OPT_SKIP_LOCK, OPT_ENABLE_LOCK, OPT_USE_LOCKING, @@ -4039,7 +4045,7 @@ struct my_option my_long_options[] = "Number of seconds to wait for more data from a master/slave connection before aborting the read.", (gptr*) &slave_net_timeout, (gptr*) &slave_net_timeout, 0, GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0}, -#endif +#endif /* HAVE_REPLICATION */ {"slow_launch_time", OPT_SLOW_LAUNCH_TIME, "If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.", (gptr*) &slow_launch_time, (gptr*) &slow_launch_time, 0, GET_ULONG, @@ -4941,7 +4947,7 @@ static void fix_paths(void) if (!(slave_load_tmpdir = (char*) my_strdup(mysql_tmpdir, MYF(MY_FAE)))) exit(1); } -#endif +#endif /* HAVE_REPLICATION */ } diff --git a/sql/protocol.cc b/sql/protocol.cc index da9f5712e3a..b81aa54af99 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -923,6 +923,7 @@ bool Protocol_prep::store_long(longlong from) { #ifndef DEBUG_OFF DBUG_ASSERT(field_types == 0 || + field_types[field_pos] == MYSQL_TYPE_INT24 || field_types[field_pos] == MYSQL_TYPE_LONG); #endif field_pos++; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d5deabf606b..ac79f4ebcf6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1208,23 +1208,26 @@ bool dispatch_command(enum enum_server_command command, THD *thd, while (!thd->fatal_error && thd->lex.found_colon) { + char *packet= thd->lex.found_colon; /* Multiple queries exits, execute them individually */ if (thd->lock || thd->open_tables || thd->derived_tables) close_thread_tables(thd); - uint length= thd->query_length-(uint)(thd->lex.found_colon-thd->query); + ulong length= thd->query_length-(ulong)(thd->lex.found_colon-thd->query); /* Remove garbage at start of query */ - char *packet= thd->lex.found_colon; - while (my_isspace(system_charset_info,packet[0]) && length > 0) + while (my_isspace(system_charset_info, *packet) && length > 0) { packet++; length--; } - thd->query= packet; thd->query_length= length; + thd->query= packet; + VOID(pthread_mutex_lock(&LOCK_thread_count)); + thd->query_id= query_id++; + VOID(pthread_mutex_unlock(&LOCK_thread_count)); mysql_parse(thd, packet, length); } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index e8ba7e91c7b..758054a6e48 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -256,11 +256,87 @@ static void setup_param_double(Item_param *param, uchar **pos) *pos+= 8; } +static void setup_param_time(Item_param *param, uchar **pos) +{ + ulong length; + + if ((length= get_param_length(pos))) + { + uchar *to= *pos; + TIME tm; + + tm.second_part= (length > 8 ) ? (ulong) sint4korr(to+7): 0; + + tm.day= (ulong) sint4korr(to+1); + tm.hour= (uint) to[5]; + tm.minute= (uint) to[6]; + tm.second= (uint) to[7]; + + tm.year= tm.month= 0; + tm.neg= (bool)to[0]; + + param->set_time(&tm, TIMESTAMP_TIME); + } + *pos+= length; +} + +static void setup_param_datetime(Item_param *param, uchar **pos) +{ + uint length= get_param_length(pos); + + if (length) + { + uchar *to= *pos; + TIME tm; + + tm.second_part= (length > 7 ) ? (ulong) sint4korr(to+7): 0; + + if (length > 4) + { + tm.hour= (uint) to[4]; + tm.minute= (uint) to[5]; + tm.second= (uint) to[6]; + } + else + tm.hour= tm.minute= tm.second= 0; + + tm.year= (uint) sint2korr(to); + tm.month= (uint) to[2]; + tm.day= (uint) to[3]; + tm.neg= 0; + + param->set_time(&tm, TIMESTAMP_FULL); + } + *pos+= length; +} + +static void setup_param_date(Item_param *param, uchar **pos) +{ + ulong length; + + if ((length= get_param_length(pos))) + { + uchar *to= *pos; + TIME tm; + + tm.year = (uint) sint2korr(to); + tm.month= (uint) to[2]; + tm.day= (uint) to[3]; + + tm.hour= tm.minute= tm.second= 0; + tm.second_part= 0; + tm.neg= 0; + + param->set_time(&tm, TIMESTAMP_DATE); + } + *pos+= length; +} + static void setup_param_str(Item_param *param, uchar **pos) { - ulong len=get_param_length(pos); + ulong len= get_param_length(pos); param->set_value((const char *)*pos, len); - *pos+=len; + *pos+= len; } static void setup_param_functions(Item_param *param, uchar param_type) @@ -290,6 +366,19 @@ static void setup_param_functions(Item_param *param, uchar param_type) param->setup_param_func= setup_param_double; param->item_result_type = REAL_RESULT; break; + case FIELD_TYPE_TIME: + param->setup_param_func= setup_param_time; + param->item_result_type = STRING_RESULT; + break; + case FIELD_TYPE_DATE: + param->setup_param_func= setup_param_date; + param->item_result_type = STRING_RESULT; + break; + case FIELD_TYPE_DATETIME: + case FIELD_TYPE_TIMESTAMP: + param->setup_param_func= setup_param_datetime; + param->item_result_type = STRING_RESULT; + break; default: param->setup_param_func= setup_param_str; param->item_result_type = STRING_RESULT; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f758fef4fc9..e554ac1d560 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -732,7 +732,9 @@ JOIN::exec() result->send_fields(fields_list,1); if (!having || having->val_int()) { - if (do_send_rows && result->send_data(fields_list)) + if (do_send_rows && (procedure ? (procedure->send_row(fields_list) || + procedure->end_of_records()) + : result->send_data(fields_list))) error= 1; else { @@ -743,7 +745,6 @@ JOIN::exec() else error=(int) result->send_eof(); } - delete procedure; DBUG_VOID_RETURN; } diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 0d604d043cc..654076c3f41 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -706,7 +706,7 @@ copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, char *to_start= to; uchar *to_end= (uchar*) to+to_length; - while ((uchar*) from < from_end) + while (1) { if ((cnvres=from_cs->mb_wc(from_cs, &wc, (uchar*) from, from_end)) > 0) from+= cnvres; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f6834f71bd9..239e8728d48 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -587,7 +587,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); literal text_literal insert_ident order_ident simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr table_wild opt_pad no_in_expr expr_expr simple_expr no_and_expr - using_list expr_or_default set_expr_or_default + using_list expr_or_default set_expr_or_default interval_expr param_marker singlerow_subselect singlerow_subselect_init exists_subselect exists_subselect_init @@ -1930,10 +1930,10 @@ expr_expr: | expr '^' expr { $$= new Item_func_bit_xor($1,$3); } | expr '&' expr { $$= new Item_func_bit_and($1,$3); } | expr '%' expr { $$= new Item_func_mod($1,$3); } - | expr '+' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,0); } - | expr '-' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,1); } + | expr '+' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,0); } + | expr '-' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,1); } | expr COLLATE_SYM collation_name { $$= new Item_func_set_collation($1,$3); }; @@ -1977,10 +1977,10 @@ no_in_expr: | no_in_expr '&' expr { $$= new Item_func_bit_and($1,$3); } | no_in_expr '%' expr { $$= new Item_func_mod($1,$3); } | no_in_expr MOD_SYM expr { $$= new Item_func_mod($1,$3); } - | no_in_expr '+' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,0); } - | no_in_expr '-' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,1); } + | no_in_expr '+' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,0); } + | no_in_expr '-' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,1); } | simple_expr; /* expressions that begin with 'expr' that does NOT follow AND */ @@ -2032,12 +2032,16 @@ no_and_expr: | no_and_expr '&' expr { $$= new Item_func_bit_and($1,$3); } | no_and_expr '%' expr { $$= new Item_func_mod($1,$3); } | no_and_expr MOD_SYM expr { $$= new Item_func_mod($1,$3); } - | no_and_expr '+' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,0); } - | no_and_expr '-' INTERVAL_SYM expr interval - { $$= new Item_date_add_interval($1,$4,$5,1); } + | no_and_expr '+' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,0); } + | no_and_expr '-' interval_expr interval + { $$= new Item_date_add_interval($1,$3,$4,1); } | simple_expr; +interval_expr: + INTERVAL_SYM expr { $$=$2; } + ; + simple_expr: simple_ident | literal @@ -2063,8 +2067,11 @@ simple_expr: | NOT expr %prec NEG { $$= new Item_func_not($2); } | '!' expr %prec NEG { $$= new Item_func_not($2); } | '(' expr ')' { $$= $2; } - /* Note: In SQL-99 "ROW" is optional, but not having it mandatory - causes conflicts with the INTERVAL syntax. */ + | '(' expr ',' expr_list ')' + { + $4->push_front($2); + $$= new Item_row(*$4); + } | ROW_SYM '(' expr ',' expr_list ')' { $5->push_front($3); @@ -2122,10 +2129,10 @@ simple_expr: $$= new Item_func_curtime($3); Lex->safe_to_cache_query=0; } - | DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' - { $$= new Item_date_add_interval($3,$6,$7,0); } - | DATE_SUB_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')' - { $$= new Item_date_add_interval($3,$6,$7,1); } + | DATE_ADD_INTERVAL '(' expr ',' interval_expr interval ')' + { $$= new Item_date_add_interval($3,$5,$6,0); } + | DATE_SUB_INTERVAL '(' expr ',' interval_expr interval ')' + { $$= new Item_date_add_interval($3,$5,$6,1); } | DATABASE '(' ')' { $$= new Item_func_database(); @@ -2185,14 +2192,21 @@ simple_expr: { $$= new Item_func_if($3,$5,$7); } | INSERT '(' expr ',' expr ',' expr ',' expr ')' { $$= new Item_func_insert($3,$5,$7,$9); } - | INTERVAL_SYM expr interval '+' expr + | interval_expr interval '+' expr /* we cannot put interval before - */ - { $$= new Item_date_add_interval($5,$2,$3,0); } - | INTERVAL_SYM '(' expr ',' expr_list ')' - { $$= new Item_func_interval($3,* $5); } + { $$= new Item_date_add_interval($4,$1,$2,0); } + | interval_expr + { + if ($1->type() != Item::ROW_ITEM) + { + send_error(Lex->thd, ER_SYNTAX_ERROR); + YYABORT; + } + $$= new Item_func_interval((Item_row *)$1); + } | LAST_INSERT_ID '(' ')' { - $$= get_system_var(OPT_SESSION, "last_insert_id", 14, + $$= get_system_var(OPT_SESSION, "last_insert_id", 14, "last_insert_id()"); } | LAST_INSERT_ID '(' expr ')' @@ -2247,10 +2261,10 @@ simple_expr: | MPOLYFROMTEXT '(' expr ',' expr ')' { $$= new Item_func_geometry_from_text($3); } | MULTIPOINT '(' expr_list ')' - { $$= new Item_func_spatial_collection(* $3, + { $$= new Item_func_spatial_collection(* $3, Geometry::wkbMultiPoint, Geometry::wkbPoint); } | MULTIPOLYGON '(' expr_list ')' - { $$= new Item_func_spatial_collection(* $3, + { $$= new Item_func_spatial_collection(* $3, Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); } | NOW_SYM optional_braces { $$= new Item_func_now(); Lex->safe_to_cache_query=0;} @@ -2269,7 +2283,7 @@ simple_expr: | POLYFROMTEXT '(' expr ',' expr ')' { $$= new Item_func_geometry_from_text($3); } | POLYGON '(' expr_list ')' - { $$= new Item_func_spatial_collection(* $3, + { $$= new Item_func_spatial_collection(* $3, Geometry::wkbPolygon, Geometry::wkbLineString); } | POSITION_SYM '(' no_in_expr IN_SYM expr ')' { $$ = new Item_func_locate($5,$3); } @@ -2429,7 +2443,7 @@ in_sum_expr: }; cast_type: - BINARY { $$=ITEM_CAST_BINARY; } + BINARY { $$=ITEM_CAST_BINARY; } | CHAR_SYM { $$=ITEM_CAST_CHAR; } | SIGNED_SYM { $$=ITEM_CAST_SIGNED_INT; } | SIGNED_SYM INT_SYM { $$=ITEM_CAST_SIGNED_INT; } @@ -4651,7 +4665,7 @@ subselect_start: '(' SELECT_SYM { LEX *lex=Lex; - if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && + if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL) { send_error(lex->thd, ER_SYNTAX_ERROR); YYABORT; |