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
e845f0f8
Commit
e845f0f8
authored
15 years ago
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Better comments
- Add OOM error checking
parent
f260de5c
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
37 deletions
+40
-37
sql/opt_table_elimination.cc
sql/opt_table_elimination.cc
+40
-37
No files found.
sql/opt_table_elimination.cc
View file @
e845f0f8
...
@@ -184,18 +184,11 @@ public:
...
@@ -184,18 +184,11 @@ public:
unknown_args
=
n_children
;
unknown_args
=
n_children
;
}
}
/*
/*
Outer join we're representing. This can be a join nest or
a
one table that
Outer join we're representing. This can be a join nest or one table that
is outer join'ed.
is outer join'ed.
*/
*/
TABLE_LIST
*
table_list
;
TABLE_LIST
*
table_list
;
/*
Tables within this outer join (and its descendants) that are not yet known
to be functionally dependent.
*/
table_map
missing_tables
;
//psergey-todo: remove
/* All tables within this outer join and its descendants */
table_map
all_tables
;
//psergey-todo: remove
/* Parent eliminable outer join, if any */
/* Parent eliminable outer join, if any */
Outer_join_module
*
parent
;
Outer_join_module
*
parent
;
};
};
...
@@ -229,11 +222,11 @@ public:
...
@@ -229,11 +222,11 @@ public:
};
};
static
static
void
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
bool
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
uint
*
and_level
,
Item
*
cond
,
uint
*
and_level
,
Item
*
cond
,
table_map
usable_tables
);
table_map
usable_tables
);
static
static
void
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_dep
,
bool
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_dep
,
uint
and_level
,
uint
and_level
,
Item_func
*
cond
,
Item
*
left
,
Item
*
right
,
Item_func
*
cond
,
Item
*
left
,
Item
*
right
,
table_map
usable_tables
);
table_map
usable_tables
);
...
@@ -270,7 +263,7 @@ static void dbug_print_deps(Table_elimination *te);
...
@@ -270,7 +263,7 @@ static void dbug_print_deps(Table_elimination *te);
*/
*/
static
static
void
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
bool
build_eq_deps_for_cond
(
Table_elimination
*
te
,
Equality_module
**
fdeps
,
uint
*
and_level
,
Item
*
cond
,
uint
*
and_level
,
Item
*
cond
,
table_map
usable_tables
)
table_map
usable_tables
)
{
{
...
@@ -285,7 +278,8 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -285,7 +278,8 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
Item
*
item
;
Item
*
item
;
while
((
item
=
li
++
))
while
((
item
=
li
++
))
{
{
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
;
}
}
/*
/*
TODO: inject here a "if we have {t.col=const AND t.col=smth_else}, then
TODO: inject here a "if we have {t.col=const AND t.col=smth_else}, then
...
@@ -297,47 +291,52 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -297,47 +291,52 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
else
else
{
{
(
*
and_level
)
++
;
(
*
and_level
)
++
;
build_eq_deps_for_cond
(
te
,
fdeps
,
and_level
,
li
++
,
usable_tables
);
if
(
build_eq_deps_for_cond
(
te
,
fdeps
,
and_level
,
li
++
,
usable_tables
))
return
TRUE
;
Item
*
item
;
Item
*
item
;
while
((
item
=
li
++
))
while
((
item
=
li
++
))
{
{
Equality_module
*
start_key_fields
=
*
fdeps
;
Equality_module
*
start_key_fields
=
*
fdeps
;
(
*
and_level
)
++
;
(
*
and_level
)
++
;
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
;
*
fdeps
=
merge_func_deps
(
org_key_fields
,
start_key_fields
,
*
fdeps
,
*
fdeps
=
merge_func_deps
(
org_key_fields
,
start_key_fields
,
*
fdeps
,
++
(
*
and_level
));
++
(
*
and_level
));
}
}
}
}
return
;
return
FALSE
;
}
}
if
(
cond
->
type
()
!=
Item
::
FUNC_ITEM
)
if
(
cond
->
type
()
!=
Item
::
FUNC_ITEM
)
return
;
return
FALSE
;
Item_func
*
cond_func
=
(
Item_func
*
)
cond
;
Item_func
*
cond_func
=
(
Item_func
*
)
cond
;
Item
**
args
=
cond_func
->
arguments
();
Item
**
args
=
cond_func
->
arguments
();
Item
*
fld
;
switch
(
cond_func
->
functype
())
{
switch
(
cond_func
->
functype
())
{
case
Item_func
:
:
IN_FUNC
:
case
Item_func
:
:
IN_FUNC
:
{
{
if
(
cond_func
->
argument_count
()
==
2
)
if
(
cond_func
->
argument_count
()
==
2
)
{
{
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
if
(
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
usable_tables
);
usable_tables
)
||
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
1
],
args
[
0
],
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
1
],
args
[
0
],
usable_tables
);
usable_tables
))
return
TRUE
;
}
}
}
}
case
Item_func
:
:
BETWEEN
:
case
Item_func
:
:
BETWEEN
:
{
{
Item
*
fld
;
if
(
!
((
Item_func_between
*
)
cond
)
->
negated
&&
if
(
!
((
Item_func_between
*
)
cond
)
->
negated
&&
(
fld
=
args
[
0
]
->
real_item
())
->
type
()
==
Item
::
FIELD_ITEM
&&
args
[
1
]
->
eq
(
args
[
2
],
((
Item_field
*
)
fld
)
->
field
->
binary
()))
args
[
1
]
->
eq
(
args
[
2
],
((
Item_field
*
)
fld
)
->
field
->
binary
()))
{
{
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
if
(
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
usable_tables
);
usable_tables
)
||
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
1
],
args
[
0
],
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
1
],
args
[
0
],
usable_tables
);
usable_tables
))
return
TRUE
;
}
}
break
;
break
;
}
}
...
@@ -353,10 +352,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -353,10 +352,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
case
Item_func
:
:
ISNULL_FUNC
:
case
Item_func
:
:
ISNULL_FUNC
:
{
{
Item
*
tmp
=
new
Item_null
;
Item
*
tmp
=
new
Item_null
;
if
(
unlikely
(
!
tmp
))
// Should never be true
if
(
!
tmp
||
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
return
;
usable_tables
))
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
args
[
0
],
args
[
1
],
return
TRUE
;
usable_tables
);
break
;
break
;
}
}
case
Item_func
:
:
MULT_EQUAL_FUNC
:
case
Item_func
:
:
MULT_EQUAL_FUNC
:
...
@@ -374,8 +372,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -374,8 +372,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
*/
*/
while
((
item
=
it
++
))
while
((
item
=
it
++
))
{
{
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
item
,
const_item
,
if
(
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
item
,
const_item
,
usable_tables
);
usable_tables
))
return
TRUE
;
}
}
}
}
else
else
...
@@ -395,8 +394,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -395,8 +394,9 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
{
{
if
(
!
field
->
eq
(
item2
->
field
))
if
(
!
field
->
eq
(
item2
->
field
))
{
{
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
item
,
item2
,
if
(
add_eq_dep
(
te
,
fdeps
,
*
and_level
,
cond_func
,
item
,
item2
,
usable_tables
);
usable_tables
))
return
TRUE
;
}
}
}
}
it
.
rewind
();
it
.
rewind
();
...
@@ -407,6 +407,7 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
...
@@ -407,6 +407,7 @@ void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps,
default:
default:
break
;
break
;
}
}
return
FALSE
;
}
}
...
@@ -536,7 +537,7 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
...
@@ -536,7 +537,7 @@ Equality_module *merge_func_deps(Equality_module *start, Equality_module *new_fi
*/
*/
static
static
void
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_dep
,
bool
add_eq_dep
(
Table_elimination
*
te
,
Equality_module
**
eq_dep
,
uint
and_level
,
Item_func
*
cond
,
uint
and_level
,
Item_func
*
cond
,
Item
*
left
,
Item
*
right
,
table_map
usable_tables
)
Item
*
left
,
Item
*
right
,
table_map
usable_tables
)
{
{
...
@@ -550,7 +551,7 @@ void add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
...
@@ -550,7 +551,7 @@ void add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
if
(
right
->
result_type
()
!=
STRING_RESULT
)
if
(
right
->
result_type
()
!=
STRING_RESULT
)
{
{
if
(
field
->
cmp_type
()
!=
right
->
result_type
())
if
(
field
->
cmp_type
()
!=
right
->
result_type
())
return
;
return
FALSE
;
}
}
else
else
{
{
...
@@ -560,17 +561,19 @@ void add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
...
@@ -560,17 +561,19 @@ void add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
*/
*/
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
())
return
;
return
FALSE
;
}
}
}
}
/* Store possible eq field */
/* Store possible eq field */
(
*
eq_dep
)
->
type
=
Module_dep
::
MODULE_EXPRESSION
;
//psergey-todo;
(
*
eq_dep
)
->
type
=
Module_dep
::
MODULE_EXPRESSION
;
//psergey-todo;
(
*
eq_dep
)
->
field
=
get_field_value
(
te
,
field
);
if
(
!
((
*
eq_dep
)
->
field
=
get_field_value
(
te
,
field
)))
return
TRUE
;
(
*
eq_dep
)
->
expression
=
right
;
(
*
eq_dep
)
->
expression
=
right
;
(
*
eq_dep
)
->
level
=
and_level
;
(
*
eq_dep
)
->
level
=
and_level
;
(
*
eq_dep
)
++
;
(
*
eq_dep
)
++
;
}
}
return
FALSE
;
}
}
...
...
This diff is collapsed.
Click to expand it.
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