diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2014-06-26 01:22:50 +0400 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2014-06-26 01:22:50 +0400 |
commit | 18d5a748f17f39ee585c137e41389b460d5df9d5 (patch) | |
tree | 202340f90c9dad37c4104d9ef6c5f224c8e0e685 | |
parent | 4a7cacda58a33da48da30e255a12194ee8fa6243 (diff) | |
download | mariadb-git-18d5a748f17f39ee585c137e41389b460d5df9d5.tar.gz |
MDEV-406: ANALYZE $stmt: Make multi-table UPDATE/DELETE work, code cleanup.
-rw-r--r-- | mysql-test/r/analyze_stmt.result | 28 | ||||
-rw-r--r-- | mysql-test/t/analyze_stmt.test | 19 | ||||
-rw-r--r-- | sql/sql_delete.cc | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 11 | ||||
-rw-r--r-- | sql/sql_update.cc | 15 |
5 files changed, 61 insertions, 14 deletions
diff --git a/mysql-test/r/analyze_stmt.result b/mysql-test/r/analyze_stmt.result index d5a9875f9fe..41fdce43807 100644 --- a/mysql-test/r/analyze_stmt.result +++ b/mysql-test/r/analyze_stmt.result @@ -169,3 +169,31 @@ analyze select count(*),max(a),b from t0 where a<7 group by b; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 70.00 Using where; Using temporary; Using filesort drop table t0; +# +# Check multi-table UPDATE/DELETE. +# +create table t0 (a int, b int); +create table t1 (a int, b int); +insert into t0 values (0,0),(2,2),(4,4), (8,8); +insert into t1 values (0,0),(2,2), (6,6); +analyze select * from t0,t1 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where; Using join buffer (flat, BNL join) +analyze update t0,t1 set t1.b=5555 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where +select * from t1; +a b +0 5555 +2 5555 +6 6 +analyze delete t1 from t1, t0 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where +select * from t1; +a b +6 6 +drop table t0, t1; diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test index de1a3a812f5..2f9de4a3763 100644 --- a/mysql-test/t/analyze_stmt.test +++ b/mysql-test/t/analyze_stmt.test @@ -127,3 +127,22 @@ insert into t0 values analyze select count(*),max(a),b from t0 where a<7 group by b; drop table t0; + +--echo # +--echo # Check multi-table UPDATE/DELETE. +--echo # +create table t0 (a int, b int); +create table t1 (a int, b int); +insert into t0 values (0,0),(2,2),(4,4), (8,8); +insert into t1 values (0,0),(2,2), (6,6); + +analyze select * from t0,t1 where t0.a=t1.a; + +analyze update t0,t1 set t1.b=5555 where t0.a=t1.a; +select * from t1; + +analyze delete t1 from t1, t0 where t0.a=t1.a; +select * from t1; + +drop table t0, t1; + diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 9b811c8cea8..8e776d7281c 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1292,7 +1292,7 @@ bool multi_delete::send_eof() if (local_error != 0) error_handled= TRUE; // to force early leave from ::abort_result_set() - if (!local_error) + if (!local_error && !thd->lex->analyze_stmt) { ::my_ok(thd, deleted); } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 007f1c2b69b..5e305bd4541 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3581,7 +3581,6 @@ end_with_restore_list: { DBUG_ASSERT(first_table == all_tables && first_table != 0); TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first; - bool explain= MY_TEST(lex->describe); multi_delete *result; if ((res= multi_delete_precheck(thd, all_tables))) @@ -3627,7 +3626,7 @@ end_with_restore_list: result->abort_result_set(); /* for both DELETE and EXPLAIN DELETE */ else { - if (explain) + if (lex->describe || lex->analyze_stmt) res= thd->lex->explain->send_explain(thd); } delete result; @@ -5223,7 +5222,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) This will call optimize() for all parts of query. The query plan is printed out below. */ - res= mysql_explain_union(thd, &thd->lex->unit, result); + res= mysql_explain_union(thd, &lex->unit, result); /* Print EXPLAIN only if we don't have an error */ if (!res) @@ -5233,8 +5232,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) top-level LIMIT */ result->reset_offset_limit(); - thd->lex->explain->print_explain(result, thd->lex->describe, - thd->lex->analyze_stmt); + lex->explain->print_explain(result, lex->describe, lex->analyze_stmt); if (lex->describe & DESCRIBE_EXTENDED) { char buff[1024]; @@ -5244,7 +5242,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) The warnings system requires input in utf8, @see mysqld_show_warnings(). */ - thd->lex->unit.print(&str, QT_TO_SYSTEM_CHARSET); + lex->unit.print(&str, QT_TO_SYSTEM_CHARSET); push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_YES, str.c_ptr_safe()); } @@ -5258,7 +5256,6 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) } else { - //psergey-todo: ANALYZE should hook in here... select_result *save_result; Protocol *save_protocol; if (lex->analyze_stmt) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index cb56e231c06..b9277adb15a 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1570,7 +1570,7 @@ bool mysql_multi_update(THD *thd, (*result)->abort_result_set(); else { - if (thd->lex->describe) + if (thd->lex->describe || thd->lex->analyze_stmt) res= thd->lex->explain->send_explain(thd); } thd->abort_on_warning= 0; @@ -2509,11 +2509,14 @@ bool multi_update::send_eof() DBUG_RETURN(TRUE); } - id= thd->arg_of_last_insert_id_function ? + if (!thd->lex->analyze_stmt) + { + id= thd->arg_of_last_insert_id_function ? thd->first_successful_insert_id_in_prev_stmt : 0; - my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), - (ulong) found, (ulong) updated, (ulong) thd->cuted_fields); - ::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, - id, buff); + my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), + (ulong) found, (ulong) updated, (ulong) thd->cuted_fields); + ::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated, + id, buff); + } DBUG_RETURN(FALSE); } |