diff options
author | Joerg Bruehe <joerg.bruehe@oracle.com> | 2012-05-07 22:20:42 +0200 |
---|---|---|
committer | Joerg Bruehe <joerg.bruehe@oracle.com> | 2012-05-07 22:20:42 +0200 |
commit | 5be07ceaddcae282a1c41b62fb3222715c773577 (patch) | |
tree | fd4bc4e87a0385cd676cd34fe9ba93dd57358f2e /sql | |
parent | 1d47bbe3bf80f5fbd2770d56c97f788f8401ffa0 (diff) | |
parent | 83d455be90a06e8fc1293a611061bd9529ed8536 (diff) | |
download | mariadb-git-5be07ceaddcae282a1c41b62fb3222715c773577.tar.gz |
Merge 5.5.24 back into main 5.5.
This is a weave merge, but without any conflicts.
In 14 source files, the copyright year needed to be updated to 2012.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 16 | ||||
-rw-r--r-- | sql/field.h | 10 | ||||
-rw-r--r-- | sql/field_conv.cc | 13 | ||||
-rw-r--r-- | sql/handler.cc | 10 | ||||
-rw-r--r-- | sql/item.cc | 43 | ||||
-rw-r--r-- | sql/item_subselect.cc | 3 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 2 | ||||
-rw-r--r-- | sql/log_event.cc | 31 | ||||
-rw-r--r-- | sql/log_event_old.cc | 14 | ||||
-rw-r--r-- | sql/mysqld.cc | 16 | ||||
-rw-r--r-- | sql/password.c | 4 | ||||
-rw-r--r-- | sql/rpl_rli.cc | 20 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 3 | ||||
-rw-r--r-- | sql/spatial.cc | 5 | ||||
-rw-r--r-- | sql/sql_class.cc | 45 | ||||
-rw-r--r-- | sql/sql_class.h | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 9 |
17 files changed, 183 insertions, 64 deletions
diff --git a/sql/field.cc b/sql/field.cc index 59eb83da5fa..4fcf5b33dc1 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -8257,7 +8257,19 @@ String *Field_set::val_str(String *val_buffer, ulonglong tmp=(ulonglong) Field_enum::val_int(); uint bitnr=0; - val_buffer->set("", 0, field_charset); + if (tmp == 0) + { + /* + Some callers expect *val_buffer to contain the result, + so we assign to it, rather than doing 'return &empty_set_string. + */ + *val_buffer= empty_set_string; + return val_buffer; + } + + val_buffer->set_charset(field_charset); + val_buffer->length(0); + while (tmp && bitnr < (uint) typelib->count) { if (tmp & 1) diff --git a/sql/field.h b/sql/field.h index b4adb764b22..d9f0b892adb 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1,7 +1,7 @@ #ifndef FIELD_INCLUDED #define FIELD_INCLUDED -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1985,7 +1985,8 @@ public: :Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, packlength_arg, - typelib_arg,charset_arg) + typelib_arg,charset_arg), + empty_set_string("", 0, charset_arg) { flags=(flags & ~ENUM_FLAG) | SET_FLAG; } @@ -1996,8 +1997,11 @@ public: virtual bool zero_pack() const { return 1; } String *val_str(String*,String *); void sql_type(String &str) const; + uint size_of() const { return sizeof(*this); } enum_field_types real_type() const { return MYSQL_TYPE_SET; } bool has_charset(void) const { return TRUE; } +private: + const String empty_set_string; }; @@ -2192,6 +2196,8 @@ public: { return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0; } +private: + const String empty_set_string; }; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 594449174bc..17b0d34557a 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -317,10 +317,11 @@ static void do_save_blob(Copy_field *copy) static void do_field_string(Copy_field *copy) { char buff[MAX_FIELD_WIDTH]; - copy->tmp.set_quick(buff,sizeof(buff),copy->tmp.charset()); - copy->from_field->val_str(©->tmp); - copy->to_field->store(copy->tmp.c_ptr_quick(),copy->tmp.length(), - copy->tmp.charset()); + String res(buff, sizeof(buff), copy->from_field->charset()); + res.length(0U); + + copy->from_field->val_str(&res); + copy->to_field->store(res.c_ptr_quick(), res.length(), res.charset()); } @@ -563,7 +564,7 @@ void Copy_field::set(uchar *to,Field *from) /* To do: - If 'save\ is set to true and the 'from' is a blob field, do_copy is set to + If 'save' is set to true and the 'from' is a blob field, do_copy is set to do_save_blob rather than do_conv_blob. The only differences between them appears to be: diff --git a/sql/handler.cc b/sql/handler.cc index c3c70109daa..b2cb7f1cf9a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -10,8 +10,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ /** @file handler.cc @@ -437,6 +437,7 @@ int ha_init_errors(void) SETMSG(HA_ERR_TOO_MANY_CONCURRENT_TRXS, ER_DEFAULT(ER_TOO_MANY_CONCURRENT_TRXS)); SETMSG(HA_ERR_INDEX_COL_TOO_LONG, ER_DEFAULT(ER_INDEX_COLUMN_TOO_LONG)); SETMSG(HA_ERR_INDEX_CORRUPT, ER_DEFAULT(ER_INDEX_CORRUPT)); + SETMSG(HA_ERR_TABLE_IN_FK_CHECK, ER_DEFAULT(ER_TABLE_IN_FK_CHECK)); /* Register the error messages for use with my_error(). */ return my_error_register(get_handler_errmsgs, HA_ERR_FIRST, HA_ERR_LAST); @@ -2964,6 +2965,9 @@ void handler::print_error(int error, myf errflag) case HA_ERR_UNDO_REC_TOO_BIG: textno= ER_UNDO_RECORD_TOO_BIG; break; + case HA_ERR_TABLE_IN_FK_CHECK: + textno= ER_TABLE_IN_FK_CHECK; + break; default: { /* The error was "unknown" to this function. diff --git a/sql/item.cc b/sql/item.cc index 69821df986a..22b5adc4597 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7078,20 +7078,12 @@ bool Item_insert_value::fix_fields(THD *thd, Item **items) } if (arg->type() == REF_ITEM) + arg= static_cast<Item_ref *>(arg)->ref[0]; + if (arg->type() != FIELD_ITEM) { - Item_ref *ref= (Item_ref *)arg; - if (ref->ref[0]->type() != FIELD_ITEM) - { - my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function"); - return TRUE; - } - arg= ref->ref[0]; + my_error(ER_BAD_FIELD_ERROR, MYF(0), "", "VALUES() function"); + return TRUE; } - /* - According to our SQL grammar, VALUES() function can reference - only to a column. - */ - DBUG_ASSERT(arg->type() == FIELD_ITEM); Item_field *field_arg= (Item_field *)arg; @@ -7655,6 +7647,33 @@ bool Item_cache_datetime::cache_value() str_value.copy(*res); null_value= example->null_value; unsigned_flag= example->unsigned_flag; + + if (!null_value) + { + switch(field_type()) + { + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + { + MYSQL_TIME ltime; + int was_cut; + const timestamp_type tt= + str_to_datetime(str_value.charset(), + str_value.ptr(), + str_value.length(), + <ime, + TIME_DATETIME_ONLY, + &was_cut); + if (tt != MYSQL_TIMESTAMP_DATETIME || was_cut) + null_value= true; + else + my_datetime_to_str(<ime, const_cast<char*>(str_value.ptr())); + } + default: + {} + } + } + return TRUE; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a6bcdbd8645..97b8dbbe113 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -182,6 +182,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref) (*ref)= substitution; substitution->name= name; + substitution->name_length= name_length; if (have_to_be_excluded) engine->exclude(); substitution= 0; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index ddb00874b62..6fc85a01668 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2694,7 +2694,7 @@ longlong Item_datetime_typecast::val_int() { DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - if (get_arg0_date(<ime,1)) + if (get_arg0_date(<ime, TIME_FUZZY_DATE)) { null_value= 1; return 0; diff --git a/sql/log_event.cc b/sql/log_event.cc index 1f49155bf7f..76ff852107b 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -7697,9 +7697,24 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) { DBUG_PRINT("debug", ("Checking compability of tables to lock - tables_to_lock: %p", rli->tables_to_lock)); + + /** + When using RBR and MyISAM MERGE tables the base tables that make + up the MERGE table can be appended to the list of tables to lock. + + Thus, we just check compatibility for those that tables that have + a correspondent table map event (ie, those that are actually going + to be accessed while applying the event). That's why the loop stops + at rli->tables_to_lock_count . + + NOTE: The base tables are added here are removed when + close_thread_tables is called. + */ RPL_TABLE_LIST *ptr= rli->tables_to_lock; - for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global)) + for (uint i= 0 ; ptr && (i < rli->tables_to_lock_count); + ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++) { + DBUG_ASSERT(ptr->m_tabledef_valid); TABLE *conv_table; if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli), ptr->table, &conv_table)) @@ -7737,10 +7752,10 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) Rows_log_event, we can invalidate the query cache for the associated table. */ - for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global) - { + TABLE_LIST *ptr= rli->tables_to_lock; + for (uint i=0 ; ptr && (i < rli->tables_to_lock_count); ptr= ptr->next_global, i++) const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table); - } + #ifdef HAVE_QUERY_CACHE query_cache.invalidate_locked_for_write(rli->tables_to_lock); #endif @@ -8522,9 +8537,9 @@ check_table_map(Relay_log_info const *rli, RPL_TABLE_LIST *table_list) res= FILTERED_OUT; else { - for(RPL_TABLE_LIST *ptr= static_cast<RPL_TABLE_LIST*>(rli->tables_to_lock); - ptr; - ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_local)) + RPL_TABLE_LIST *ptr= static_cast<RPL_TABLE_LIST*>(rli->tables_to_lock); + for(uint i=0 ; ptr && (i< rli->tables_to_lock_count); + ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_local), i++) { if (ptr->table_id == table_list->table_id) { diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc index 4aa8c0959b1..d68c474d00a 100644 --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -126,8 +126,10 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info { RPL_TABLE_LIST *ptr= rli->tables_to_lock; - for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global)) + for (uint i= 0 ; ptr&& (i< rli->tables_to_lock_count); + ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++) { + DBUG_ASSERT(ptr->m_tabledef_valid); TABLE *conv_table; if (!ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli), ptr->table, &conv_table)) @@ -158,10 +160,9 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info Old_rows_log_event, we can invalidate the query cache for the associated table. */ - for (TABLE_LIST *ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global) - { + TABLE_LIST *ptr= rli->tables_to_lock; + for (uint i=0; ptr && (i < rli->tables_to_lock_count); ptr= ptr->next_global, i++) const_cast<Relay_log_info*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table); - } #ifdef HAVE_QUERY_CACHE query_cache.invalidate_locked_for_write(rli->tables_to_lock); #endif @@ -1539,7 +1540,8 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli) { RPL_TABLE_LIST *ptr= rli->tables_to_lock; - for ( ; ptr ; ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global)) + for (uint i= 0 ; ptr&& (i< rli->tables_to_lock_count); + ptr= static_cast<RPL_TABLE_LIST*>(ptr->next_global), i++) { TABLE *conv_table; if (ptr->m_tabledef.compatible_with(thd, const_cast<Relay_log_info*>(rli), diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 63656460f42..a37a9701fe7 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1045,7 +1045,7 @@ static void close_connections(void) { if (ip_sock != INVALID_SOCKET) { - (void) shutdown(ip_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(ip_sock, SHUT_RDWR); (void) closesocket(ip_sock); ip_sock= INVALID_SOCKET; } @@ -1077,7 +1077,7 @@ static void close_connections(void) #ifdef HAVE_SYS_UN_H if (unix_sock != INVALID_SOCKET) { - (void) shutdown(unix_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(unix_sock, SHUT_RDWR); (void) closesocket(unix_sock); (void) unlink(mysqld_unix_port); unix_sock= INVALID_SOCKET; @@ -1184,14 +1184,14 @@ static void close_server_sock() { ip_sock=INVALID_SOCKET; DBUG_PRINT("info",("calling shutdown on TCP/IP socket")); - (void) shutdown(tmp_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR); } tmp_sock=unix_sock; if (tmp_sock != INVALID_SOCKET) { unix_sock=INVALID_SOCKET; DBUG_PRINT("info",("calling shutdown on unix socket")); - (void) shutdown(tmp_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR); (void) unlink(mysqld_unix_port); } DBUG_VOID_RETURN; @@ -5266,7 +5266,7 @@ void handle_connections_sockets() if (req.sink) ((void (*)(int))req.sink)(req.fd); - (void) shutdown(new_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(new_sock, SHUT_RDWR); (void) closesocket(new_sock); continue; } @@ -5282,7 +5282,7 @@ void handle_connections_sockets() (SOCKET_SIZE_TYPE *)&dummyLen) < 0 ) { sql_perror("Error on new connection socket"); - (void) shutdown(new_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(new_sock, SHUT_RDWR); (void) closesocket(new_sock); continue; } @@ -5294,7 +5294,7 @@ void handle_connections_sockets() if (!(thd= new THD)) { - (void) shutdown(new_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(new_sock, SHUT_RDWR); (void) closesocket(new_sock); continue; } @@ -5313,7 +5313,7 @@ void handle_connections_sockets() vio_delete(vio_tmp); else { - (void) shutdown(new_sock, SHUT_RDWR); + (void) mysql_socket_shutdown(new_sock, SHUT_RDWR); (void) closesocket(new_sock); } delete thd; diff --git a/sql/password.c b/sql/password.c index ca194204360..afa514a6c53 100644 --- a/sql/password.c +++ b/sql/password.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -531,7 +531,7 @@ check_scramble(const uchar *scramble_arg, const char *message, mysql_sha1_reset(&sha1_context); mysql_sha1_input(&sha1_context, buf, SHA1_HASH_SIZE); mysql_sha1_result(&sha1_context, hash_stage2_reassured); - return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE); + return test(memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE)); } diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 607bd092b73..2d302011b44 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1264,6 +1264,23 @@ void Relay_log_info::cleanup_context(THD *thd, bool error) void Relay_log_info::clear_tables_to_lock() { + DBUG_ENTER("Relay_log_info::clear_tables_to_lock()"); +#ifndef DBUG_OFF + /** + When replicating in RBR and MyISAM Merge tables are involved + open_and_lock_tables (called in do_apply_event) appends the + base tables to the list of tables_to_lock. Then these are + removed from the list in close_thread_tables (which is called + before we reach this point). + + This assertion just confirms that we get no surprises at this + point. + */ + uint i=0; + for (TABLE_LIST *ptr= tables_to_lock ; ptr ; ptr= ptr->next_global, i++) ; + DBUG_ASSERT(i == tables_to_lock_count); +#endif + while (tables_to_lock) { uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock); @@ -1288,10 +1305,12 @@ void Relay_log_info::clear_tables_to_lock() my_free(to_free); } DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0); + DBUG_VOID_RETURN; } void Relay_log_info::slave_close_thread_tables(THD *thd) { + DBUG_ENTER("Relay_log_info::slave_close_thread_tables(THD *thd)"); thd->stmt_da->can_overwrite_status= TRUE; thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd); thd->stmt_da->can_overwrite_status= FALSE; @@ -1313,5 +1332,6 @@ void Relay_log_info::slave_close_thread_tables(THD *thd) thd->mdl_context.release_statement_locks(); clear_tables_to_lock(); + DBUG_VOID_RETURN; } #endif diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index c8cacd22303..263dd0ffeb7 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6497,6 +6497,9 @@ ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC ER_BINLOG_UNSAFE_INSERT_TWO_KEYS eng "INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEY is unsafe" +ER_TABLE_IN_FK_CHECK + eng "Table is being used in foreign key check." + ER_UNSUPPORTED_ENGINE eng "Storage engine '%s' does not support system tables. [%s.%s]" diff --git a/sql/spatial.cc b/sql/spatial.cc index ee701d82657..894f2a1dae5 100644 --- a/sql/spatial.cc +++ b/sql/spatial.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -609,7 +609,8 @@ int Gis_line_string::is_closed(int *closed) const return 0; } data+= 4; - if (no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) + if (n_points == 0 || + no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) return 1; /* Get first point */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6660f848653..bdcb85218c3 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -2861,13 +2861,42 @@ bool select_exists_subselect::send_data(List<Item> &items) int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u) { unit= u; + List_iterator_fast<my_var> var_li(var_list); + List_iterator_fast<Item> it(list); + Item *item; + my_var *mv; + Item_func_set_user_var **suv; if (var_list.elements != list.elements) { my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0)); return 1; - } + } + + /* + Iterate over the destination variables and mark them as being + updated in this query. + We need to do this at JOIN::prepare time to ensure proper + const detection of Item_func_get_user_var that is determined + by the presence of Item_func_set_user_vars + */ + + suv= set_var_items= (Item_func_set_user_var **) + sql_alloc(sizeof(Item_func_set_user_var *) * list.elements); + + while ((mv= var_li++) && (item= it++)) + { + if (!mv->local) + { + *suv= new Item_func_set_user_var(mv->s, item); + (*suv)->fix_fields(thd, 0); + } + else + *suv= NULL; + suv++; + } + return 0; } @@ -3184,6 +3213,7 @@ bool select_dumpvar::send_data(List<Item> &items) List_iterator<Item> it(items); Item *item; my_var *mv; + Item_func_set_user_var **suv; DBUG_ENTER("select_dumpvar::send_data"); if (unit->offset_limit_cnt) @@ -3196,20 +3226,19 @@ bool select_dumpvar::send_data(List<Item> &items) my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); DBUG_RETURN(1); } - while ((mv= var_li++) && (item= it++)) + for (suv= set_var_items; ((mv= var_li++) && (item= it++)); suv++) { if (mv->local) { + DBUG_ASSERT(!*suv); if (thd->spcont->set_variable(thd, mv->offset, &item)) DBUG_RETURN(1); } else { - Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item); - if (suv->fix_fields(thd, 0)) - DBUG_RETURN (1); - suv->save_item_result(item); - if (suv->update()) + DBUG_ASSERT(*suv); + (*suv)->save_item_result(item); + if ((*suv)->update()) DBUG_RETURN (1); } } diff --git a/sql/sql_class.h b/sql/sql_class.h index f107bfe4a69..bffa490ebe3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -3533,6 +3533,7 @@ public: class select_dumpvar :public select_result_interceptor { ha_rows row_count; + Item_func_set_user_var **set_var_items; public: List<my_var> var_list; select_dumpvar() { var_list.empty(); row_count= 0;} diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 423c59d34cc..3c709e3c0ea 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -5890,6 +5890,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse, } keyuse++; } while (keyuse->table == table && keyuse->key == key); + DBUG_ASSERT(length > 0 && keyparts != 0); } /* not ftkey */ /* set up fieldref */ @@ -13698,6 +13699,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, DBUG_ENTER("test_if_skip_sort_order"); LINT_INIT(ref_key_parts); + /* Check that we are always called with first non-const table */ + DBUG_ASSERT(tab == tab->join->join_tab + tab->join->const_tables); + /* Keys disabled by ALTER TABLE ... DISABLE KEYS should have already been taken into account. @@ -13779,7 +13783,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, while (keyuse->key != new_ref_key && keyuse->table == tab->table) keyuse++; if (create_ref_for_key(tab->join, tab, keyuse, - tab->join->const_table_map)) + (tab->join->const_table_map | + OUTER_REF_TABLE_BIT))) DBUG_RETURN(0); pick_table_access_method(tab); |