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
307a6ba5
Commit
307a6ba5
authored
Aug 18, 2009
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MWL#17: Table elimination
- Code cleanup
parent
c1b69e72
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
237 deletions
+128
-237
sql/opt_table_elimination.cc
sql/opt_table_elimination.cc
+128
-237
No files found.
sql/opt_table_elimination.cc
View file @
307a6ba5
...
@@ -275,7 +275,7 @@ class Outer_join_module: public Module_dep
...
@@ -275,7 +275,7 @@ class Outer_join_module: public Module_dep
public:
public:
Outer_join_module
(
//TABLE_LIST *table_list_arg,
Outer_join_module
(
//TABLE_LIST *table_list_arg,
uint
n_children
)
uint
n_children
)
// table_list(table_list_arg)
, parent(NULL)
// table_list(table_list_arg)
{
{
type
=
Module_dep
::
MODULE_OUTER_JOIN
;
type
=
Module_dep
::
MODULE_OUTER_JOIN
;
unknown_args
=
n_children
;
unknown_args
=
n_children
;
...
@@ -285,9 +285,6 @@ public:
...
@@ -285,9 +285,6 @@ public:
is outer join'ed.
is outer join'ed.
*/
*/
// TABLE_LIST *table_list;
// TABLE_LIST *table_list;
/* Parent eliminable outer join, if any */
// Outer_join_module *parent;
};
};
...
@@ -297,7 +294,7 @@ public:
...
@@ -297,7 +294,7 @@ public:
class
Table_elimination
class
Table_elimination
{
{
public:
public:
Table_elimination
(
JOIN
*
join_arg
)
:
join
(
join_arg
)
,
n_outer_joins
(
0
)
Table_elimination
(
JOIN
*
join_arg
)
:
join
(
join_arg
)
{
{
bzero
(
table_deps
,
sizeof
(
table_deps
));
bzero
(
table_deps
,
sizeof
(
table_deps
));
}
}
...
@@ -310,14 +307,20 @@ public:
...
@@ -310,14 +307,20 @@ public:
/* tablenr -> Table_value* mapping. */
/* tablenr -> Table_value* mapping. */
Table_value
*
table_deps
[
MAX_KEY
];
Table_value
*
table_deps
[
MAX_KEY
];
/* Outer joins that are candidates for elimination */
List
<
Outer_join_module
>
oj_deps
;
uint
n_outer_joins
;
/* Bitmap of how expressions depend on bits */
/* Bitmap of how expressions depend on bits */
MY_BITMAP
expr_deps
;
MY_BITMAP
expr_deps
;
};
};
void
eliminate_tables
(
JOIN
*
join
);
static
bool
eliminate_tables_for_list
(
Table_elimination
*
te
,
List
<
TABLE_LIST
>
*
join_list
,
table_map
tables_in_list
,
Item
*
on_expr
,
table_map
tables_used_elsewhere
);
static
bool
check_func_dependency
(
Table_elimination
*
te
,
table_map
tables
,
Item
*
cond
);
static
static
bool
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
bool
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
...
@@ -339,9 +342,10 @@ static Outer_join_module *get_outer_join_dep(Table_elimination *te,
...
@@ -339,9 +342,10 @@ static Outer_join_module *get_outer_join_dep(Table_elimination *te,
table_map
deps_map
);
table_map
deps_map
);
static
static
bool
run_elimination_wave
(
Table_elimination
*
te
,
Module_dep
*
bound_modules
);
bool
run_elimination_wave
(
Table_elimination
*
te
,
Module_dep
*
bound_modules
);
void
eliminate_tables
(
JOIN
*
join
);
static
void
mark_as_eliminated
(
JOIN
*
join
,
TABLE_LIST
*
tbl
);
static
void
mark_as_eliminated
(
JOIN
*
join
,
TABLE_LIST
*
tbl
);
#ifndef DBUG_OFF
#ifndef DBUG_OFF
static
void
dbug_print_deps
(
Table_elimination
*
te
);
static
void
dbug_print_deps
(
Table_elimination
*
te
);
#endif
#endif
...
@@ -383,10 +387,6 @@ bool build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -383,10 +387,6 @@ bool build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
if
(
build_eq_deps_for_cond
(
te
,
fdeps
,
and_level
,
item
,
usable_tables
))
if
(
build_eq_deps_for_cond
(
te
,
fdeps
,
and_level
,
item
,
usable_tables
))
return
TRUE
;
return
TRUE
;
}
}
/*
TODO: inject here a "if we have {t.col=const AND t.col=smth_else}, then
remove the second part" logic.
*/
for
(;
org_key_fields
!=
*
fdeps
;
org_key_fields
++
)
for
(;
org_key_fields
!=
*
fdeps
;
org_key_fields
++
)
org_key_fields
->
level
=
*
and_level
;
org_key_fields
->
level
=
*
and_level
;
}
}
...
@@ -614,7 +614,7 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
...
@@ -614,7 +614,7 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
/*
/*
Ok, the results are within the [start, first_free) range, and the useful
Ok, the results are within the [start, first_free) range, and the useful
elements have level==and_level. Now,
lets
remove all unusable elements:
elements have level==and_level. Now, remove all unusable elements:
*/
*/
for
(
Equality_module
*
old
=
start
;
old
!=
first_free
;)
for
(
Equality_module
*
old
=
start
;
old
!=
first_free
;)
{
{
...
@@ -632,14 +632,31 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
...
@@ -632,14 +632,31 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
/*
/*
Add an Equality_module element for a given predicate, if applicable
Add an Equality_module element for left=right condition
SYNOPSIS
add_eq_dep()
te Table elimination context
eq_mod INOUT Store created Equality_module here and increment ptr if
you do so
and_level AND-level ()
cond Condition we've inferred the left=right equality from.
left Left expression
right Right expression
usable_tables Create Equality_module only if Left_expression's table
belongs to this set.
DESCRIPTION
DESCRIPTION
This function is modeled after add_key_field().
Check if the passed equality means that 'left' expr is functionally dependent on
the 'right', and if yes, create an Equality_module object for it.
RETURN
FALSE OK
TRUE Out of memory
*/
*/
static
static
bool
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_
dep
,
bool
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_
mod
,
uint
and_level
,
Item_func
*
cond
,
Item
*
left
,
Item
*
right
,
uint
and_level
,
Item_func
*
cond
,
Item
*
left
,
Item
*
right
,
table_map
usable_tables
)
table_map
usable_tables
)
{
{
...
@@ -658,8 +675,8 @@ bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
...
@@ -658,8 +675,8 @@ bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
else
else
{
{
/*
/*
We can't
use indexes if the effective collation
We can't
assume there's a functional dependency if the effective
of the operation differ from the field collation.
collation
of the operation differ from the field collation.
*/
*/
if
(
field
->
cmp_type
()
==
STRING_RESULT
&&
if
(
field
->
cmp_type
()
==
STRING_RESULT
&&
((
Field_str
*
)
field
)
->
charset
()
!=
cond
->
compare_collation
())
((
Field_str
*
)
field
)
->
charset
()
!=
cond
->
compare_collation
())
...
@@ -667,12 +684,12 @@ bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
...
@@ -667,12 +684,12 @@ bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
}
}
}
}
(
*
eq_
dep
)
->
type
=
Module_dep
::
MODULE_EXPRESSION
;
//psergey-todo;
(
*
eq_
mod
)
->
type
=
Module_dep
::
MODULE_EXPRESSION
;
//psergey-todo;
if
(
!
((
*
eq_
dep
)
->
field
=
get_field_value
(
te
,
field
)))
if
(
!
((
*
eq_
mod
)
->
field
=
get_field_value
(
te
,
field
)))
return
TRUE
;
return
TRUE
;
(
*
eq_
dep
)
->
expression
=
right
;
(
*
eq_
mod
)
->
expression
=
right
;
(
*
eq_
dep
)
->
level
=
and_level
;
(
*
eq_
mod
)
->
level
=
and_level
;
(
*
eq_
dep
)
++
;
(
*
eq_
mod
)
++
;
}
}
return
FALSE
;
return
FALSE
;
}
}
...
@@ -754,7 +771,6 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
...
@@ -754,7 +771,6 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
Outer_join_module
*
oj_dep
;
Outer_join_module
*
oj_dep
;
if
(
!
(
oj_dep
=
new
Outer_join_module
(
/*outer_join, */
my_count_bits
(
deps_map
))))
if
(
!
(
oj_dep
=
new
Outer_join_module
(
/*outer_join, */
my_count_bits
(
deps_map
))))
return
NULL
;
return
NULL
;
te
->
n_outer_joins
++
;
/*
/*
Collect a bitmap fo tables that we depend on, and also set parent pointer
Collect a bitmap fo tables that we depend on, and also set parent pointer
...
@@ -786,25 +802,7 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
...
@@ -786,25 +802,7 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
if
(
!
(
table_dep
=
get_table_value
(
te
,
table
)))
if
(
!
(
table_dep
=
get_table_value
(
te
,
table
)))
return
NULL
;
return
NULL
;
}
}
table_dep
->
outer_join_dep
=
oj_dep
;
/*
Walk from the table up to its embedding outer joins. The goal is to
find the least embedded outer join nest and set its parent pointer to
point to the newly created Outer_join_module.
to set the pointer of its near
*/
//if (!table_dep->outer_join_dep)
table_dep
->
outer_join_dep
=
oj_dep
;
/*
else
{
Outer_join_module *oj= table_dep->outer_join_dep;
while (oj->parent)
oj= oj->parent;
if (oj != oj_dep)
oj->parent=oj_dep;
}
*/
}
}
return
oj_dep
;
return
oj_dep
;
}
}
...
@@ -815,10 +813,10 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
...
@@ -815,10 +813,10 @@ Outer_join_module *get_outer_join_dep(Table_elimination *te,
that we can figure out which fields the expression depends on.
that we can figure out which fields the expression depends on.
*/
*/
class
Field_dependency_
sett
er
:
public
Field_enumerator
class
Field_dependency_
record
er
:
public
Field_enumerator
{
{
public:
public:
Field_dependency_
sett
er
(
Table_elimination
*
te_arg
)
:
te
(
te_arg
)
Field_dependency_
record
er
(
Table_elimination
*
te_arg
)
:
te
(
te_arg
)
{}
{}
void
see_field
(
Field
*
field
)
void
see_field
(
Field
*
field
)
...
@@ -856,13 +854,16 @@ public:
...
@@ -856,13 +854,16 @@ public:
/*
/*
Setup equality dependencies
Setup equality dependencies
SYNOPSIS
SYNOPSIS
setup_equality_deps()
setup_equality_deps()
te Table elimination context
te Table elimination context
bound_deps_list OUT Start of linked list of elements that were found to
bound_deps_list OUT Start of linked list of elements that were found to
be bound (caller will use this to see if that
be bound (caller will use this to see if that
allows to declare further elements bound)
allows to declare further elements bound)
DESCRIPTION
RETURN
*/
*/
static
static
...
@@ -907,15 +908,15 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
...
@@ -907,15 +908,15 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
Also collect a linked list of equalities that are bound.
Also collect a linked list of equalities that are bound.
*/
*/
Module_dep
*
bound_dep
=
NULL
;
Module_dep
*
bound_dep
=
NULL
;
Field_dependency_
setter
deps_sett
er
(
te
);
Field_dependency_
recorder
deps_record
er
(
te
);
for
(
Equality_module
*
eq_dep
=
te
->
equality_deps
;
for
(
Equality_module
*
eq_dep
=
te
->
equality_deps
;
eq_dep
<
te
->
equality_deps
+
te
->
n_equality_deps
;
eq_dep
<
te
->
equality_deps
+
te
->
n_equality_deps
;
eq_dep
++
)
eq_dep
++
)
{
{
deps_
sett
er
.
expr_offset
=
eq_dep
-
te
->
equality_deps
;
deps_
record
er
.
expr_offset
=
eq_dep
-
te
->
equality_deps
;
eq_dep
->
unknown_args
=
0
;
eq_dep
->
unknown_args
=
0
;
eq_dep
->
expression
->
walk
(
&
Item
::
check_column_usage_processor
,
FALSE
,
eq_dep
->
expression
->
walk
(
&
Item
::
check_column_usage_processor
,
FALSE
,
(
uchar
*
)
&
deps_sett
er
);
(
uchar
*
)
&
deps_record
er
);
if
(
!
eq_dep
->
unknown_args
)
if
(
!
eq_dep
->
unknown_args
)
{
{
eq_dep
->
next
=
bound_dep
;
eq_dep
->
next
=
bound_dep
;
...
@@ -935,12 +936,11 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
...
@@ -935,12 +936,11 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
SYNOPSIS
SYNOPSIS
eliminate_tables()
eliminate_tables()
join Join to work on
join Join to work on
const_tbl_count INOUT Number of constant tables (this includes
eliminated tables)
const_tables INOUT Bitmap of constant tables
DESCRIPTION
DESCRIPTION
This function is the entry point for table elimination.
This is the entry point for table elimination. Grep for MODULE INTERFACE
section in this file for calling convention.
The idea behind table elimination is that if we have an outer join:
The idea behind table elimination is that if we have an outer join:
SELECT * FROM t1 LEFT JOIN
SELECT * FROM t1 LEFT JOIN
...
@@ -968,12 +968,6 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
...
@@ -968,12 +968,6 @@ bool setup_equality_deps(Table_elimination *te, Module_dep **bound_deps_list)
See the OVERVIEW section at the top of this file.
See the OVERVIEW section at the top of this file.
*/
*/
static
uint
eliminate_tables_for_list
(
Table_elimination
*
te
,
List
<
TABLE_LIST
>
*
join_list
,
Item
*
on_expr
,
table_map
tables_in_list
,
table_map
tables_used_elsewhere
);
void
eliminate_tables
(
JOIN
*
join
)
void
eliminate_tables
(
JOIN
*
join
)
{
{
...
@@ -1023,101 +1017,54 @@ void eliminate_tables(JOIN *join)
...
@@ -1023,101 +1017,54 @@ void eliminate_tables(JOIN *join)
if
(
all_tables
&
~
used_tables
)
if
(
all_tables
&
~
used_tables
)
{
{
/* There are some tables that we probably could eliminate. Try it. */
/* There are some tables that we probably could eliminate. Try it. */
//psergey-todo: move allocs to somewhere else.
Table_elimination
te
(
join
);
Table_elimination
te
(
join
);
uint
m
=
max
(
thd
->
lex
->
current_select
->
max_equal_elems
,
1
);
uint
m
=
max
(
thd
->
lex
->
current_select
->
max_equal_elems
,
1
);
uint
max_elems
=
((
thd
->
lex
->
current_select
->
cond_count
+
1
)
*
2
+
uint
max_elems
=
((
thd
->
lex
->
current_select
->
cond_count
+
1
)
*
2
+
thd
->
lex
->
current_select
->
between_count
)
*
m
+
1
+
10
;
thd
->
lex
->
current_select
->
between_count
)
*
m
+
1
+
10
;
if
(
!
(
te
.
equality_deps
=
new
Equality_module
[
max_elems
]))
if
(
!
(
te
.
equality_deps
=
new
Equality_module
[
max_elems
]))
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
//Equality_module *eq_deps_end= te.equality_deps;
//table_map eliminable_tables= 0;
/*
if (collect_funcdeps_for_join_list(&te, join->join_list,
FALSE,
used_tables,
&eliminable_tables,
&eq_deps))
DBUG_VOID_RETURN;
*/
eliminate_tables_for_list
(
&
te
,
join
->
join_list
,
NULL
,
(
table_map
(
1
)
<<
join
->
tables
)
-
1
,
used_tables
);
/*te.n_equality_deps= eq_deps_end - te.equality_deps;
eliminate_tables_for_list
(
&
te
,
join
->
join_list
,
all_tables
,
NULL
,
used_tables
);
Module_dep *bound_modules;
//Value_dep *bound_values;
if (setup_equality_deps(&te, &bound_modules))
DBUG_VOID_RETURN;
run_elimination_wave(&te, bound_modules);
*/
}
}
DBUG_VOID_RETURN
;
DBUG_VOID_RETURN
;
}
}
////////////////////////////
/*
/*
Perform table elimination in a given join list
Perform table elimination in a given join list
SYNOPSIS
SYNOPSIS
eliminate_tables_for_list()
eliminate_tables_for_list()
join The join
te Table elimination context
leaves_arr OUT Store here an array of leaf (base) tables that
join_list Join list to work on
are descendants of the join_list, and increment
list_tables Bitmap of tables embedded in the join_list.
the pointer to point right above the array.
on_expr ON expression, if the join list is the inner side
join_list Join list to work on
of an outer join.
its_outer_join TRUE <=> join_list is an inner side of an outer
NULL means it's not an outer join but rather a
join
top-level join list.
FALSE <=> otherwise (this is top-level join list)
tables_in_list Bitmap of tables embedded in the join_list.
tables_used_elsewhere Bitmap of tables that are referred to from
tables_used_elsewhere Bitmap of tables that are referred to from
somewhere outside of the join list (e.g.
somewhere outside of the join list (e.g.
select list, HAVING, etc).
select list, HAVING,
other ON expressions,
etc).
DESCRIPTION
DESCRIPTION
Perform table elimination for a join list.
Perform table elimination in a given join list.
Try eliminating children nests first.
The "all tables in join nest can produce only one matching record
combination" property checking is modeled after constant table detection,
plus we reuse info attempts to eliminate child join nests.
RETURN
RETURN
Number of children left after elimination. 0 means everything was
TRUE The entire join list eliminated
eliminated.
FALSE Join list wasn't eliminated (but some of its possibly were)
*/
*/
bool
try_eliminating
(
Table_elimination
*
te
,
table_map
tables_in_list
,
static
bool
Item
*
on_expr
)
{
uint
and_level
=
0
;
Equality_module
*
eq_dep
=
te
->
equality_deps
;
build_eq_deps_for_cond
(
te
,
&
eq_dep
,
&
and_level
,
on_expr
,
tables_in_list
);
te
->
n_equality_deps
=
eq_dep
-
te
->
equality_deps
;
Module_dep
*
bound_modules
;
get_outer_join_dep
(
te
,
tables_in_list
);
if
(
!
setup_equality_deps
(
te
,
&
bound_modules
)
&&
run_elimination_wave
(
te
,
bound_modules
))
return
TRUE
;
// eliminated
return
FALSE
;
}
static
uint
eliminate_tables_for_list
(
Table_elimination
*
te
,
List
<
TABLE_LIST
>
*
join_list
,
eliminate_tables_for_list
(
Table_elimination
*
te
,
List
<
TABLE_LIST
>
*
join_list
,
Item
*
on_expr
,
table_map
list_tables
,
Item
*
on_expr
,
table_map
tables_in_list
,
table_map
tables_used_elsewhere
)
table_map
tables_used_elsewhere
)
{
{
TABLE_LIST
*
tbl
;
TABLE_LIST
*
tbl
;
List_iterator
<
TABLE_LIST
>
it
(
*
join_list
);
List_iterator
<
TABLE_LIST
>
it
(
*
join_list
);
table_map
tables_used_on_left
=
0
;
table_map
tables_used_on_left
=
0
;
bool
not_eliminated
=
FALS
E
;
bool
all_eliminated
=
TRU
E
;
while
((
tbl
=
it
++
))
while
((
tbl
=
it
++
))
{
{
...
@@ -1130,26 +1077,25 @@ eliminate_tables_for_list(Table_elimination *te, List<TABLE_LIST> *join_list,
...
@@ -1130,26 +1077,25 @@ eliminate_tables_for_list(Table_elimination *te, List<TABLE_LIST> *join_list,
/* This is "... LEFT JOIN (join_nest) ON cond" */
/* This is "... LEFT JOIN (join_nest) ON cond" */
if
(
eliminate_tables_for_list
(
te
,
if
(
eliminate_tables_for_list
(
te
,
&
tbl
->
nested_join
->
join_list
,
&
tbl
->
nested_join
->
join_list
,
tbl
->
on_expr
,
tbl
->
nested_join
->
used_tables
,
tbl
->
nested_join
->
used_tables
,
tbl
->
on_expr
,
outside_used_tables
))
outside_used_tables
))
{
{
mark_as_eliminated
(
te
->
join
,
tbl
);
mark_as_eliminated
(
te
->
join
,
tbl
);
}
}
else
else
not_eliminated
=
TRUE
;
all_eliminated
=
FALSE
;
}
}
else
else
{
{
/* This is "... LEFT JOIN tbl ON cond" */
/* This is "... LEFT JOIN tbl ON cond" */
if
(
!
(
tbl
->
table
->
map
&
outside_used_tables
)
&&
if
(
!
(
tbl
->
table
->
map
&
outside_used_tables
)
&&
try_eliminating
(
te
,
tbl
->
table
->
map
,
tbl
->
on_expr
))
check_func_dependency
(
te
,
tbl
->
table
->
map
,
tbl
->
on_expr
))
{
{
mark_as_eliminated
(
te
->
join
,
tbl
);
mark_as_eliminated
(
te
->
join
,
tbl
);
}
}
else
else
not_eliminated
=
TRU
E
;
all_eliminated
=
FALS
E
;
}
}
tables_used_on_left
|=
tbl
->
on_expr
->
used_tables
();
tables_used_on_left
|=
tbl
->
on_expr
->
used_tables
();
}
}
...
@@ -1160,98 +1106,51 @@ eliminate_tables_for_list(Table_elimination *te, List<TABLE_LIST> *join_list,
...
@@ -1160,98 +1106,51 @@ eliminate_tables_for_list(Table_elimination *te, List<TABLE_LIST> *join_list,
}
}
/* Try eliminating the nest we're called for */
/* Try eliminating the nest we're called for */
if
(
!
not_eliminated
&&
on_expr
&&
!
(
tables_in_list
&
tables_used_elsewhere
))
if
(
all_eliminated
&&
on_expr
&&
!
(
list_tables
&
tables_used_elsewhere
))
return
try_eliminating
(
te
,
tables_in_list
&
~
te
->
join
->
eliminated_tables
,
{
on_expr
);
return
check_func_dependency
(
te
,
list_tables
&
~
te
->
join
->
eliminated_tables
,
on_expr
);
}
return
FALSE
;
/* not eliminated */
return
FALSE
;
/* not eliminated */
}
}
#if 0
/*
/*
Build functional dependency graph for elements of given join lis
t
Check if condition makes the a set of tables functionally-dependen
t
SYNOPSIS
SYNOPSIS
collect_funcdeps_for_join_list()
check_func_dependency()
te Table elimination context.
te Table elimination context
join_list Join list to work on
tables Set of tables we want to be functionally dependent
build_eq_deps TRUE <=> build Equality_module elements for all
cond Condition to use
members of the join list, even if they cannot
be individually eliminated
tables_used_elsewhere Bitmap of tables that are referred to from
somewhere outside of this join list (e.g.
select list, HAVING, ON expressions of parent
joins, etc).
eliminable_tables INOUT Tables that can potentially be eliminated
(needed so we know for which tables to build
dependencies for)
eq_dep INOUT End of array of equality dependencies.
DESCRIPTION
DESCRIPTION
.
Check if condition allows to conclude that the table set is functionally
dependent on everything else.
RETURN
TRUE - Yes, functionally dependent
FALSE - No, or error
*/
*/
static bool
static
collect_funcdeps_for_join_list(Table_elimination *te,
bool
check_func_dependency
(
Table_elimination
*
te
,
table_map
tables
,
Item
*
cond
)
List<TABLE_LIST> *join_list,
bool build_eq_deps,
table_map tables_used_elsewhere,
table_map *eliminable_tables,
Equality_module **eq_dep)
{
{
TABLE_LIST *tbl;
uint
and_level
=
0
;
List_iterator<TABLE_LIST> it(*join_list);
Equality_module
*
eq_dep
=
te
->
equality_deps
;
table_map tables_used_on_left= 0;
if
(
build_eq_deps_for_cond
(
te
,
&
eq_dep
,
&
and_level
,
cond
,
tables
))
return
TRUE
;
while ((tbl= it++))
te
->
n_equality_deps
=
eq_dep
-
te
->
equality_deps
;
Module_dep
*
bound_modules
;
if
(
!
get_outer_join_dep
(
te
,
tables
)
&&
!
setup_equality_deps
(
te
,
&
bound_modules
)
&&
run_elimination_wave
(
te
,
bound_modules
))
{
{
if (tbl->on_expr)
return
TRUE
;
/* eliminated */
{
table_map outside_used_tables= tables_used_elsewhere |
tables_used_on_left;
bool eliminable;
table_map cur_map;
if (tbl->nested_join)
{
/* This is "... LEFT JOIN (join_nest) ON cond" */
cur_map= tbl->nested_join->used_tables;
eliminable= !(cur_map & outside_used_tables);
if (eliminable)
*eliminable_tables |= cur_map;
if (collect_funcdeps_for_join_list(te, &tbl->nested_join->join_list,
eliminable || build_eq_deps,
outside_used_tables,
eliminable_tables,
eq_dep))
return TRUE;
}
else
{
/* This is "... LEFT JOIN tbl ON cond" */
cur_map= tbl->table->map;
eliminable= !(tbl->table->map & outside_used_tables);
*eliminable_tables |= cur_map;
}
if (eliminable || build_eq_deps)
{
// build comp_cond from ON expression
uint and_level=0;
build_eq_deps_for_cond(te, eq_dep, &and_level, tbl->on_expr,
*eliminable_tables);
}
if (eliminable && !get_outer_join_dep(te, tbl, cur_map))
return TRUE;
tables_used_on_left |= tbl->on_expr->used_tables();
}
}
}
return
FALSE
;
return
FALSE
;
}
}
#endif
////////////////////////////
static
static
void
signal_from_field_to_exprs
(
Table_elimination
*
te
,
Field_value
*
field_dep
,
void
signal_from_field_to_exprs
(
Table_elimination
*
te
,
Field_value
*
field_dep
,
...
@@ -1272,18 +1171,18 @@ void signal_from_field_to_exprs(Table_elimination* te, Field_value *field_dep,
...
@@ -1272,18 +1171,18 @@ void signal_from_field_to_exprs(Table_elimination* te, Field_value *field_dep,
}
}
/*
Run the wave.
All Func_dep-derived objects are divided into three classes:
- Those that have bound=FALSE
- Those that have bound=TRUE
- Those that have bound=TRUE and are in the list..
*/
static
static
bool
run_elimination_wave
(
Table_elimination
*
te
,
Module_dep
*
bound_modules
)
bool
run_elimination_wave
(
Table_elimination
*
te
,
Module_dep
*
bound_modules
)
{
{
Value_dep
*
bound_values
=
NULL
;
Value_dep
*
bound_values
=
NULL
;
/*
Run the wave.
All Func_dep-derived objects are divided into three classes:
- Those that have bound=FALSE
- Those that have bound=TRUE
- Those that have bound=TRUE and are in the list..
*/
while
(
bound_modules
)
while
(
bound_modules
)
{
{
for
(;
bound_modules
;
bound_modules
=
bound_modules
->
next
)
for
(;
bound_modules
;
bound_modules
=
bound_modules
->
next
)
...
@@ -1318,14 +1217,8 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
...
@@ -1318,14 +1217,8 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
}
}
case
Module_dep
:
:
MODULE_OUTER_JOIN
:
case
Module_dep
:
:
MODULE_OUTER_JOIN
:
{
{
//Outer_join_module *outer_join_dep= (Outer_join_module*)bound_modules;
DBUG_PRINT
(
"info"
,
(
"Outer join eliminated"
));
//mark_as_eliminated(te->join, outer_join_dep->table_list);
return
TRUE
;
//if (!--te->n_outer_joins)
{
DBUG_PRINT
(
"info"
,
(
"Table elimination eliminated everything"
" it theoretically could"
));
return
TRUE
;
}
break
;
break
;
}
}
case
Module_dep
:
:
MODULE_MULTI_EQUALITY
:
case
Module_dep
:
:
MODULE_MULTI_EQUALITY
:
...
@@ -1373,10 +1266,20 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
...
@@ -1373,10 +1266,20 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
DBUG_PRINT
(
"info"
,
(
"table %s is now bound"
,
DBUG_PRINT
(
"info"
,
(
"table %s is now bound"
,
table_dep
->
table
->
alias
));
table_dep
->
table
->
alias
));
/*
/*
Table is known means
Table is known means that
- all its fields are known
- one more element in outer join nest is known
- one more element in outer join nest is known
- all its fields are known
*/
*/
Outer_join_module
*
outer_join_dep
=
table_dep
->
outer_join_dep
;
if
(
outer_join_dep
->
unknown_args
&&
!--
outer_join_dep
->
unknown_args
)
{
/* Mark as bound and add to the list */
outer_join_dep
->
next
=
bound_modules
;
bound_modules
=
outer_join_dep
;
break
;
}
for
(
Field_value
*
field_dep
=
table_dep
->
fields
;
field_dep
;
for
(
Field_value
*
field_dep
=
table_dep
->
fields
;
field_dep
;
field_dep
=
field_dep
->
next_table_field
)
field_dep
=
field_dep
->
next_table_field
)
{
{
...
@@ -1387,18 +1290,6 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
...
@@ -1387,18 +1290,6 @@ bool run_elimination_wave(Table_elimination *te, Module_dep *bound_modules)
signal_from_field_to_exprs
(
te
,
field_dep
,
&
bound_modules
);
signal_from_field_to_exprs
(
te
,
field_dep
,
&
bound_modules
);
}
}
}
}
//for (
Outer_join_module
*
outer_join_dep
=
table_dep
->
outer_join_dep
;
// outer_join_dep; outer_join_dep= outer_join_dep->parent)
{
if
(
outer_join_dep
->
unknown_args
&&
!--
outer_join_dep
->
unknown_args
)
{
/* Mark as bound and add to the list */
outer_join_dep
->
next
=
bound_modules
;
bound_modules
=
outer_join_dep
;
}
}
break
;
break
;
}
}
default:
default:
...
...
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