Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
18d5a748
Commit
18d5a748
authored
Jun 26, 2014
by
Sergei Petrunia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-406: ANALYZE $stmt: Make multi-table UPDATE/DELETE work, code cleanup.
parent
4a7cacda
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
14 deletions
+61
-14
mysql-test/r/analyze_stmt.result
mysql-test/r/analyze_stmt.result
+28
-0
mysql-test/t/analyze_stmt.test
mysql-test/t/analyze_stmt.test
+19
-0
sql/sql_delete.cc
sql/sql_delete.cc
+1
-1
sql/sql_parse.cc
sql/sql_parse.cc
+4
-7
sql/sql_update.cc
sql/sql_update.cc
+9
-6
No files found.
mysql-test/r/analyze_stmt.result
View file @
18d5a748
...
...
@@ -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;
mysql-test/t/analyze_stmt.test
View file @
18d5a748
...
...
@@ -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
;
sql/sql_delete.cc
View file @
18d5a748
...
...
@@ -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
);
}
...
...
sql/sql_parse.cc
View file @
18d5a748
...
...
@@ -3581,7 +3581,6 @@ case SQLCOM_PREPARE:
{
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 @@ case SQLCOM_PREPARE:
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
)
...
...
sql/sql_update.cc
View file @
18d5a748
...
...
@@ -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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment