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
|
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
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 70.00 Using where; Using temporary; Using filesort
|
||||||
drop table t0;
|
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;
|
analyze select count(*),max(a),b from t0 where a<7 group by b;
|
||||||
drop table t0;
|
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)
|
if (local_error != 0)
|
||||||
error_handled= TRUE; // to force early leave from ::abort_result_set()
|
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);
|
::my_ok(thd, deleted);
|
||||||
}
|
}
|
||||||
|
@ -3581,7 +3581,6 @@ end_with_restore_list:
|
|||||||
{
|
{
|
||||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||||
TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
|
TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
|
||||||
bool explain= MY_TEST(lex->describe);
|
|
||||||
multi_delete *result;
|
multi_delete *result;
|
||||||
|
|
||||||
if ((res= multi_delete_precheck(thd, all_tables)))
|
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 */
|
result->abort_result_set(); /* for both DELETE and EXPLAIN DELETE */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (explain)
|
if (lex->describe || lex->analyze_stmt)
|
||||||
res= thd->lex->explain->send_explain(thd);
|
res= thd->lex->explain->send_explain(thd);
|
||||||
}
|
}
|
||||||
delete result;
|
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
|
This will call optimize() for all parts of query. The query plan is
|
||||||
printed out below.
|
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 */
|
/* Print EXPLAIN only if we don't have an error */
|
||||||
if (!res)
|
if (!res)
|
||||||
@ -5233,8 +5232,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
|
|||||||
top-level LIMIT
|
top-level LIMIT
|
||||||
*/
|
*/
|
||||||
result->reset_offset_limit();
|
result->reset_offset_limit();
|
||||||
thd->lex->explain->print_explain(result, thd->lex->describe,
|
lex->explain->print_explain(result, lex->describe, lex->analyze_stmt);
|
||||||
thd->lex->analyze_stmt);
|
|
||||||
if (lex->describe & DESCRIBE_EXTENDED)
|
if (lex->describe & DESCRIBE_EXTENDED)
|
||||||
{
|
{
|
||||||
char buff[1024];
|
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
|
The warnings system requires input in utf8, @see
|
||||||
mysqld_show_warnings().
|
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,
|
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
|
||||||
ER_YES, str.c_ptr_safe());
|
ER_YES, str.c_ptr_safe());
|
||||||
}
|
}
|
||||||
@ -5258,7 +5256,6 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//psergey-todo: ANALYZE should hook in here...
|
|
||||||
select_result *save_result;
|
select_result *save_result;
|
||||||
Protocol *save_protocol;
|
Protocol *save_protocol;
|
||||||
if (lex->analyze_stmt)
|
if (lex->analyze_stmt)
|
||||||
|
@ -1570,7 +1570,7 @@ bool mysql_multi_update(THD *thd,
|
|||||||
(*result)->abort_result_set();
|
(*result)->abort_result_set();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (thd->lex->describe)
|
if (thd->lex->describe || thd->lex->analyze_stmt)
|
||||||
res= thd->lex->explain->send_explain(thd);
|
res= thd->lex->explain->send_explain(thd);
|
||||||
}
|
}
|
||||||
thd->abort_on_warning= 0;
|
thd->abort_on_warning= 0;
|
||||||
@ -2509,11 +2509,14 @@ bool multi_update::send_eof()
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!thd->lex->analyze_stmt)
|
||||||
|
{
|
||||||
id= thd->arg_of_last_insert_id_function ?
|
id= thd->arg_of_last_insert_id_function ?
|
||||||
thd->first_successful_insert_id_in_prev_stmt : 0;
|
thd->first_successful_insert_id_in_prev_stmt : 0;
|
||||||
my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO),
|
my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO),
|
||||||
(ulong) found, (ulong) updated, (ulong) thd->cuted_fields);
|
(ulong) found, (ulong) updated, (ulong) thd->cuted_fields);
|
||||||
::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated,
|
::my_ok(thd, (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated,
|
||||||
id, buff);
|
id, buff);
|
||||||
|
}
|
||||||
DBUG_RETURN(FALSE);
|
DBUG_RETURN(FALSE);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user