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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
680107f1
Commit
680107f1
authored
Jun 03, 2009
by
Sergey Petrunia
Browse files
Options
Browse Files
Download
Plain Diff
Merge MWL#17 with maria/5.1
parents
52fb7f12
275a4b35
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
434 additions
and
8 deletions
+434
-8
mysql-test/r/table_elim.result
mysql-test/r/table_elim.result
+56
-0
mysql-test/t/table_elim.test
mysql-test/t/table_elim.test
+52
-0
sql/sql_select.cc
sql/sql_select.cc
+321
-8
sql/sql_select.h
sql/sql_select.h
+3
-0
sql/table.h
sql/table.h
+2
-0
No files found.
mysql-test/r/table_elim.result
0 → 100644
View file @
680107f1
drop table if exists t0, t1, t2, t3;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3);
create table t0 as select * from t1;
create table t2 (a int primary key, b int)
as select a, a as b from t1 where a in (1,2);
create table t3 (a int primary key, b int)
as select a, a as b from t1 where a in (1,3);
# This will be eliminated:
explain select t1.a from t1 left join t2 on t2.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
select t1.a from t1 left join t2 on t2.a=t1.a;
a
0
1
2
3
# This will not be eliminated as t2.b is in in select list:
explain select * from t1 left join t2 on t2.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
# This will not be eliminated as t2.b is in in order list:
explain select t1.a from t1 left join t2 on t2.a=t1.a order by t2.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
# This will not be eliminated as t2.b is in group list:
explain select t1.a from t1 left join t2 on t2.a=t1.a group by t2.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
# This will not be eliminated as t2.b is in the WHERE
explain select t1.a from t1 left join t2 on t2.a=t1.a where t2.b < 3 or t2.b is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
# Elimination of multiple tables:
explain select t1.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
# Elimination of multiple tables (2):
explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and t3.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
# Elimination when done within an outer join nest:
explain
select t0.*
from
t0 left join (t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
t3.a=t1.a) on t0.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 4
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
drop table t0, t1, t2, t3;
mysql-test/t/table_elim.test
0 → 100644
View file @
680107f1
#
# Table elimination (MWL#17) tests
#
--
disable_warnings
drop
table
if
exists
t0
,
t1
,
t2
,
t3
;
--
enable_warnings
create
table
t1
(
a
int
);
insert
into
t1
values
(
0
),(
1
),(
2
),(
3
);
create
table
t0
as
select
*
from
t1
;
create
table
t2
(
a
int
primary
key
,
b
int
)
as
select
a
,
a
as
b
from
t1
where
a
in
(
1
,
2
);
create
table
t3
(
a
int
primary
key
,
b
int
)
as
select
a
,
a
as
b
from
t1
where
a
in
(
1
,
3
);
--
echo
# This will be eliminated:
explain
select
t1
.
a
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
;
select
t1
.
a
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
;
--
echo
# This will not be eliminated as t2.b is in in select list:
explain
select
*
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
;
--
echo
# This will not be eliminated as t2.b is in in order list:
explain
select
t1
.
a
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
order
by
t2
.
b
;
--
echo
# This will not be eliminated as t2.b is in group list:
explain
select
t1
.
a
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
group
by
t2
.
b
;
## TODO: Aggregate functions prevent table elimination ATM.
--
echo
# This will not be eliminated as t2.b is in the WHERE
explain
select
t1
.
a
from
t1
left
join
t2
on
t2
.
a
=
t1
.
a
where
t2
.
b
<
3
or
t2
.
b
is
null
;
--
echo
# Elimination of multiple tables:
explain
select
t1
.
a
from
t1
left
join
(
t2
join
t3
)
on
t2
.
a
=
t1
.
a
and
t3
.
a
=
t1
.
a
;
--
echo
# Elimination of multiple tables (2):
explain
select
t1
.
a
from
t1
left
join
(
t2
join
t3
on
t2
.
b
=
t3
.
b
)
on
t2
.
a
=
t1
.
a
and
t3
.
a
=
t1
.
a
;
--
echo
# Elimination when done within an outer join nest:
explain
select
t0
.*
from
t0
left
join
(
t1
left
join
(
t2
join
t3
on
t2
.
b
=
t3
.
b
)
on
t2
.
a
=
t1
.
a
and
t3
.
a
=
t1
.
a
)
on
t0
.
a
=
t1
.
a
;
drop
table
t0
,
t1
,
t2
,
t3
;
sql/sql_select.cc
View file @
680107f1
This diff is collapsed.
Click to expand it.
sql/sql_select.h
View file @
680107f1
...
...
@@ -210,6 +210,9 @@ typedef struct st_join_table {
JOIN
*
join
;
/** Bitmap of nested joins this table is part of */
nested_join_map
embedding_map
;
//psergey-todo: more justified place
bool
eliminated
;
void
cleanup
();
inline
bool
is_using_loose_index_scan
()
...
...
sql/table.h
View file @
680107f1
...
...
@@ -1626,6 +1626,8 @@ typedef struct st_nested_join
Before each use the counters are zeroed by reset_nj_counters.
*/
uint
counter
;
/* Tables left after elimination */
uint
n_tables
;
nested_join_map
nj_map
;
/* Bit used to identify this nested join*/
}
NESTED_JOIN
;
...
...
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