mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-406: ANALYZE $stmt: Make multi-table UPDATE/DELETE work, code cleanup.
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user