From: Sergey Glukhov Date: August 2 2011 8:16am Subject: bzr push into mysql-trunk branch (sergey.glukhov:3332 to 3333) List-Archive: http://lists.mysql.com/commits/140505 Message-Id: <201108020827.p728R5oQ008210@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3333 Sergey Glukhov 2011-08-02 [merge] 5.5 -> trunk merge @ mysql-test/r/sp.result 5.5 -> trunk merge @ mysql-test/t/sp.test 5.5 -> trunk merge @ sql/opt_explain.cc 5.5 -> trunk merge @ sql/sql_base.cc 5.5 -> trunk merge @ sql/sql_class.cc 5.5 -> trunk merge @ sql/sql_class.h 5.5 -> trunk merge @ sql/sql_insert.cc 5.5 -> trunk merge @ sql/sql_lex.cc 5.5 -> trunk merge @ sql/sql_lex.h 5.5 -> trunk merge @ sql/sql_prepare.cc 5.5 -> trunk merge @ sql/sql_select.cc 5.5 -> trunk merge modified: mysql-test/r/sp.result mysql-test/t/sp.test sql/opt_explain.cc sql/sql_base.cc sql/sql_class.cc sql/sql_class.h sql/sql_insert.cc sql/sql_lex.cc sql/sql_lex.h sql/sql_prepare.cc sql/sql_select.cc 3332 Alexander Nozdrin 2011-08-01 A follow-up patch for Bug#11763162 (55843: HANDLED CONDITION APPEARS AS NOT HANDLED). Update results for the 'engines' test suite. modified: mysql-test/suite/engines/funcs/r/sf_alter.result mysql-test/suite/engines/funcs/r/sf_cursor.result mysql-test/suite/engines/funcs/r/sp_alter.result mysql-test/suite/engines/funcs/r/sp_cursor.result === modified file 'mysql-test/r/sp.result' --- a/mysql-test/r/sp.result 2011-07-28 08:31:36 +0000 +++ b/mysql-test/r/sp.result 2011-08-02 08:14:26 +0000 @@ -7025,6 +7025,25 @@ init_connect SET @@GLOBAL.init_connect= @old_init_connect; DROP PROCEDURE p2; DROP PROCEDURE p5; +# +# Bug#11766594 59736: SELECT DISTINCT.. INCORRECT RESULT WITH DETERMINISTIC FUNCTION IN WHERE C +# +CREATE TABLE t1 (a INT, b INT, KEY(b)); +CREATE TABLE t2 (c INT, d INT, KEY(c)); +INSERT INTO t1 VALUES (1,1),(1,1),(1,2); +INSERT INTO t2 VALUES (1,1),(1,2); +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC +BEGIN +DECLARE a int; +-- SQL statement inside +SELECT 1 INTO a; +RETURN a; +END $ +SELECT COUNT(DISTINCT d) FROM t1, t2 WHERE a = c AND b = f1(); +COUNT(DISTINCT d) +2 +DROP FUNCTION f1; +DROP TABLE t1, t2; # ------------------------------------------------------------------ # -- End of 5.1 tests # ------------------------------------------------------------------ === modified file 'mysql-test/t/sp.test' --- a/mysql-test/t/sp.test 2011-07-14 08:05:12 +0000 +++ b/mysql-test/t/sp.test 2011-08-02 08:14:26 +0000 @@ -8376,6 +8376,33 @@ SET @@GLOBAL.init_connect= @old_init_con DROP PROCEDURE p2; DROP PROCEDURE p5; +--echo # +--echo # Bug#11766594 59736: SELECT DISTINCT.. INCORRECT RESULT WITH DETERMINISTIC FUNCTION IN WHERE C +--echo # + +CREATE TABLE t1 (a INT, b INT, KEY(b)); +CREATE TABLE t2 (c INT, d INT, KEY(c)); +INSERT INTO t1 VALUES (1,1),(1,1),(1,2); +INSERT INTO t2 VALUES (1,1),(1,2); + +DELIMITER $; + +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC +BEGIN + DECLARE a int; + -- SQL statement inside + SELECT 1 INTO a; + RETURN a; +END $ + +DELIMITER ;$ + +SELECT COUNT(DISTINCT d) FROM t1, t2 WHERE a = c AND b = f1(); + +DROP FUNCTION f1; +DROP TABLE t1, t2; + + --echo # ------------------------------------------------------------------ --echo # -- End of 5.1 tests --echo # ------------------------------------------------------------------ === modified file 'sql/opt_explain.cc' --- a/sql/opt_explain.cc 2011-07-28 10:54:44 +0000 +++ b/sql/opt_explain.cc 2011-08-02 08:14:26 +0000 @@ -1013,7 +1013,7 @@ bool Explain_join::explain_extra() explain_tmptable_and_filesort(need_tmp_table, need_order, &str_extra); need_tmp_table= need_order= false; - if (distinct && test_all_bits(used_tables,thd->used_tables)) + if (distinct && test_all_bits(used_tables, thd->lex->used_tables)) str_extra.append(STRING_WITH_LEN("; Distinct")); if (tab->loosescan_match_tab) === modified file 'sql/sql_base.cc' --- a/sql/sql_base.cc 2011-07-28 10:54:44 +0000 +++ b/sql/sql_base.cc 2011-08-02 08:14:26 +0000 @@ -8166,7 +8166,7 @@ bool setup_fields(THD *thd, Ref_ptr_arra if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM && sum_func_list) item->split_sum_func(thd, ref_pointer_array, *sum_func_list); - thd->used_tables|= item->used_tables(); + thd->lex->used_tables|= item->used_tables(); thd->lex->current_select->cur_pos_in_select_list++; } thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup; @@ -8473,7 +8473,7 @@ insert_fields(THD *thd, Name_resolution_ views and natural joins this update is performed inside the loop below. */ if (table) - thd->used_tables|= table->map; + thd->lex->used_tables|= table->map; /* Initialize a generic field iterator for the current table reference. @@ -8558,7 +8558,7 @@ insert_fields(THD *thd, Name_resolution_ field_table= nj_col->table_ref->table; if (field_table) { - thd->used_tables|= field_table->map; + thd->lex->used_tables|= field_table->map; field_table->covering_keys.intersect(field->part_of_key); field_table->merge_keys.merge(field->part_of_key); field_table->used_fields++; @@ -8566,7 +8566,7 @@ insert_fields(THD *thd, Name_resolution_ } } else - thd->used_tables|= item->used_tables(); + thd->lex->used_tables|= item->used_tables(); thd->lex->current_select->cur_pos_in_select_list++; } /* === modified file 'sql/sql_class.cc' --- a/sql/sql_class.cc 2011-07-28 10:54:44 +0000 +++ b/sql/sql_class.cc 2011-08-02 08:14:26 +0000 @@ -821,7 +821,6 @@ THD::THD(bool enable_plugins) is_slave_error= thread_specific_used= FALSE; my_hash_clear(&handler_tables_hash); tmp_table=0; - used_tables=0; cuted_fields= 0L; m_sent_row_count= 0L; limit_found_rows= 0; === modified file 'sql/sql_class.h' --- a/sql/sql_class.h 2011-07-28 10:54:44 +0000 +++ b/sql/sql_class.h 2011-08-02 08:14:26 +0000 @@ -2315,13 +2315,6 @@ public: void set_status_no_index_used(); void set_status_no_good_index_used(); - /* - The set of those tables whose fields are referenced in all subqueries - of the query. - TODO: possibly this it is incorrect to have used tables in THD because - with more than one subquery, it is not clear what does the field mean. - */ - table_map used_tables; USER_CONN *user_connect; const CHARSET_INFO *db_charset; #if defined(ENABLED_PROFILING) === modified file 'sql/sql_insert.cc' --- a/sql/sql_insert.cc 2011-07-28 10:54:44 +0000 +++ b/sql/sql_insert.cc 2011-08-02 08:14:26 +0000 @@ -723,7 +723,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t lock_type= table_list->lock_type; THD_STAGE_INFO(thd, stage_init); - thd->used_tables=0; + thd->lex->used_tables=0; values= its++; value_count= values->elements; @@ -889,7 +889,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t } else { - if (thd->used_tables) // Column used in values() + if (thd->lex->used_tables) // Column used in values() restore_record(table,s->default_values); // Get empty record else { === modified file 'sql/sql_lex.cc' --- a/sql/sql_lex.cc 2011-07-25 10:54:06 +0000 +++ b/sql/sql_lex.cc 2011-08-02 08:14:26 +0000 @@ -435,6 +435,7 @@ void lex_start(THD *thd) lex->server_options.port= -1; lex->is_lex_started= TRUE; + lex->used_tables= 0; DBUG_VOID_RETURN; } === modified file 'sql/sql_lex.h' --- a/sql/sql_lex.h 2011-07-20 10:24:14 +0000 +++ b/sql/sql_lex.h 2011-08-02 08:14:26 +0000 @@ -2287,6 +2287,16 @@ struct LEX: public Query_tables_list bool escape_used; bool is_lex_started; /* If lex_start() did run. For debugging. */ + /* + The set of those tables whose fields are referenced in all subqueries + of the query. + TODO: possibly this it is incorrect to have used tables in LEX because + with subquery, it is not clear what does the field mean. To fix this + we should aggregate used tables information for selected expressions + into the select_lex. + */ + table_map used_tables; + LEX(); virtual ~LEX() === modified file 'sql/sql_prepare.cc' --- a/sql/sql_prepare.cc 2011-07-28 09:00:43 +0000 +++ b/sql/sql_prepare.cc 2011-08-02 08:14:26 +0000 @@ -1472,7 +1472,7 @@ static int mysql_test_select(Prepared_st if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL)) goto error; - thd->used_tables= 0; // Updated by setup_fields + thd->lex->used_tables= 0; // Updated by setup_fields thd->thd_marker.emb_on_expr_nest= 0; /* @@ -1646,7 +1646,7 @@ static bool select_like_stmt_test(Prepar if (specific_prepare && (*specific_prepare)(thd)) DBUG_RETURN(TRUE); - thd->used_tables= 0; // Updated by setup_fields + thd->lex->used_tables= 0; // Updated by setup_fields /* Calls JOIN::prepare */ DBUG_RETURN(lex->unit.prepare(thd, 0, setup_tables_done_option)); === modified file 'sql/sql_select.cc' --- a/sql/sql_select.cc 2011-07-28 10:54:44 +0000 +++ b/sql/sql_select.cc 2011-08-02 08:14:26 +0000 @@ -550,7 +550,7 @@ fix_inner_refs(THD *thd, List &all if (!ref->fixed && ref->fix_fields(thd, 0)) return TRUE; - thd->used_tables|= item->used_tables(); + thd->lex->used_tables|= item->used_tables(); } return false; } @@ -2742,7 +2742,7 @@ JOIN::optimize() if (exec_tmp_table1->distinct) { - table_map used_tables= thd->used_tables; + table_map used_tables= thd->lex->used_tables; JOIN_TAB *last_join_tab= join_tab+tables-1; do { @@ -3763,7 +3763,7 @@ mysql_select(THD *thd, if (!(join= new JOIN(thd, fields, select_options, result))) DBUG_RETURN(TRUE); /* purecov: inspected */ THD_STAGE_INFO(thd, stage_init); - thd->used_tables=0; // Updated by setup_fields + thd->lex->used_tables=0; // Updated by setup_fields err= join->prepare(tables, wild_num, conds, og_num, order, group, having, proc_param, select_lex, unit); No bundle (reason: useless for push emails).