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
6ae24e69
Commit
6ae24e69
authored
Mar 22, 2011
by
Sergey Petrunya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MWL#90: Address review feedback part #4
parent
ba0bc916
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
40 deletions
+42
-40
sql/opt_subselect.cc
sql/opt_subselect.cc
+32
-14
sql/sql_base.cc
sql/sql_base.cc
+1
-1
sql/sql_select.cc
sql/sql_select.cc
+9
-23
sql/sql_show.cc
sql/sql_show.cc
+0
-2
No files found.
sql/opt_subselect.cc
View file @
6ae24e69
...
@@ -687,18 +687,22 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
...
@@ -687,18 +687,22 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
arena
=
thd
->
activate_stmt_arena_if_needed
(
&
backup
);
arena
=
thd
->
activate_stmt_arena_if_needed
(
&
backup
);
for
(
in_subq
=
join
->
sj_subselects
.
front
();
for
(
in_subq
=
join
->
sj_subselects
.
front
();
in_subq
!=
in_subq_end
&&
in_subq
!=
in_subq_end
;
join
->
tables
+
(
*
in_subq
)
->
unit
->
first_select
()
->
join
->
tables
<
MAX_TABLES
;
in_subq
++
)
in_subq
++
)
{
{
bool
remove_item
=
TRUE
;
bool
remove_item
=
TRUE
;
if
((
*
in_subq
)
->
is_flattenable_semijoin
)
if
((
*
in_subq
)
->
is_flattenable_semijoin
)
{
{
if
(
join
->
tables
+
(
*
in_subq
)
->
unit
->
first_select
()
->
join
->
tables
>=
MAX_TABLES
)
break
;
if
(
convert_subq_to_sj
(
join
,
*
in_subq
))
if
(
convert_subq_to_sj
(
join
,
*
in_subq
))
DBUG_RETURN
(
TRUE
);
DBUG_RETURN
(
TRUE
);
}
}
else
else
{
{
if
(
join
->
tables
+
1
>=
MAX_TABLES
)
break
;
if
(
convert_subq_to_jtbm
(
join
,
*
in_subq
,
&
remove_item
))
if
(
convert_subq_to_jtbm
(
join
,
*
in_subq
,
&
remove_item
))
DBUG_RETURN
(
TRUE
);
DBUG_RETURN
(
TRUE
);
}
}
...
@@ -1211,6 +1215,17 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
...
@@ -1211,6 +1215,17 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
}
}
const
int
SUBQERY_TEMPTABLE_NAME_MAX_LEN
=
20
;
static
void
create_subquery_temptable_name
(
char
*
to
,
uint
number
)
{
DBUG_ASSERT
(
number
<
10000
);
to
=
strmov
(
to
,
"<subquery"
);
to
=
int10_to_str
((
int
)
number
,
to
,
10
);
to
[
0
]
=
'>'
;
to
[
1
]
=
0
;
}
/*
/*
Convert subquery predicate into non-mergeable semi-join nest.
Convert subquery predicate into non-mergeable semi-join nest.
...
@@ -1241,15 +1256,15 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
...
@@ -1241,15 +1256,15 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
if
(
subq_pred
->
engine
->
engine_type
()
!=
subselect_engine
::
HASH_SJ_ENGINE
)
if
(
subq_pred
->
engine
->
engine_type
()
!=
subselect_engine
::
HASH_SJ_ENGINE
)
{
{
*
remove_item
=
FALSE
;
*
remove_item
=
FALSE
;
make_in_exists_conversion
(
parent_join
->
thd
,
parent_join
,
subq_pred
);
bool
res
;
DBUG_RETURN
(
FALSE
);
res
=
make_in_exists_conversion
(
parent_join
->
thd
,
parent_join
,
subq_pred
);
DBUG_RETURN
(
res
);
}
}
*
remove_item
=
TRUE
;
*
remove_item
=
TRUE
;
TABLE_LIST
*
jtbm
;
TABLE_LIST
*
jtbm
;
char
*
tbl_alias
;
char
*
tbl_alias
;
const
char
alias_mask
[]
=
"<subquery%d>"
;
if
(
!
(
tbl_alias
=
(
char
*
)
parent_join
->
thd
->
calloc
(
SUBQERY_TEMPTABLE_NAME_MAX_LEN
))
||
if
(
!
(
tbl_alias
=
(
char
*
)
parent_join
->
thd
->
calloc
(
sizeof
(
alias_mask
)
+
5
))
||
!
(
jtbm
=
alloc_join_nest
(
parent_join
->
thd
)))
//todo: this is not a join nest!
!
(
jtbm
=
alloc_join_nest
(
parent_join
->
thd
)))
//todo: this is not a join nest!
{
{
DBUG_RETURN
(
TRUE
);
DBUG_RETURN
(
TRUE
);
...
@@ -1268,7 +1283,8 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
...
@@ -1268,7 +1283,8 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
Inject the jtbm table into TABLE_LIST::next_leaf list, so that
Inject the jtbm table into TABLE_LIST::next_leaf list, so that
make_join_statistics() and co. can find it.
make_join_statistics() and co. can find it.
*/
*/
for
(
tl
=
parent_lex
->
leaf_tables
;
tl
->
next_leaf
;
tl
=
tl
->
next_leaf
)
;
for
(
tl
=
parent_lex
->
leaf_tables
;
tl
->
next_leaf
;
tl
=
tl
->
next_leaf
)
{}
tl
->
next_leaf
=
jtbm
;
tl
->
next_leaf
=
jtbm
;
/*
/*
...
@@ -1276,7 +1292,8 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
...
@@ -1276,7 +1292,8 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
(a theory: a next_local chain always starts with ::leaf_tables
(a theory: a next_local chain always starts with ::leaf_tables
because view's tables are inserted after the view)
because view's tables are inserted after the view)
*/
*/
for
(
tl
=
parent_lex
->
leaf_tables
;
tl
->
next_local
;
tl
=
tl
->
next_local
)
;
for
(
tl
=
parent_lex
->
leaf_tables
;
tl
->
next_local
;
tl
=
tl
->
next_local
)
{}
tl
->
next_local
=
jtbm
;
tl
->
next_local
=
jtbm
;
/* A theory: no need to re-connect the next_global chain */
/* A theory: no need to re-connect the next_global chain */
...
@@ -1289,15 +1306,16 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
...
@@ -1289,15 +1306,16 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
jtbm
->
table
->
map
=
table_map
(
1
)
<<
(
parent_join
->
tables
);
jtbm
->
table
->
map
=
table_map
(
1
)
<<
(
parent_join
->
tables
);
parent_join
->
tables
++
;
parent_join
->
tables
++
;
DBUG_ASSERT
(
parent_join
->
tables
<
MAX_TABLES
);
Item
*
conds
=
hash_sj_engine
->
semi_join_conds
;
Item
*
conds
=
hash_sj_engine
->
semi_join_conds
;
conds
->
fix_after_pullout
(
parent_lex
,
&
conds
);
conds
->
fix_after_pullout
(
parent_lex
,
&
conds
);
DBUG_EXECUTE
(
"where"
,
print_where
(
conds
,
"SJ-EXPR"
,
QT_ORDINARY
););
DBUG_EXECUTE
(
"where"
,
print_where
(
conds
,
"SJ-EXPR"
,
QT_ORDINARY
););
my_snprintf
(
tbl_alias
,
sizeof
(
alias_mask
)
+
5
,
alias_mask
,
create_subquery_temptable_name
(
tbl_alias
,
hash_sj_engine
->
materialize_join
->
hash_sj_engine
->
materialize_join
->
select_lex
->
select_number
);
select_lex
->
select_number
);
jtbm
->
alias
=
tbl_alias
;
jtbm
->
alias
=
tbl_alias
;
/* Inject sj_on_expr into the parent's WHERE or ON */
/* Inject sj_on_expr into the parent's WHERE or ON */
if
(
emb_tbl_nest
)
if
(
emb_tbl_nest
)
...
@@ -4017,13 +4035,13 @@ enum_nested_loop_state join_tab_execution_startup(JOIN_TAB *tab)
...
@@ -4017,13 +4035,13 @@ enum_nested_loop_state join_tab_execution_startup(JOIN_TAB *tab)
{
{
/* It's a merged SJM nest */
/* It's a merged SJM nest */
enum_nested_loop_state
rc
;
enum_nested_loop_state
rc
;
JOIN
*
join
=
tab
->
join
;
SJ_MATERIALIZATION_INFO
*
sjm
=
tab
->
bush_children
->
start
->
emb_sj_nest
->
sj_mat_info
;
SJ_MATERIALIZATION_INFO
*
sjm
=
tab
->
bush_children
->
start
->
emb_sj_nest
->
sj_mat_info
;
JOIN_TAB
*
join_tab
=
tab
->
bush_children
->
start
;
JOIN_TAB
*
save_return_tab
=
join
->
return_tab
;
if
(
!
sjm
->
materialized
)
if
(
!
sjm
->
materialized
)
{
{
JOIN
*
join
=
tab
->
join
;
JOIN_TAB
*
join_tab
=
tab
->
bush_children
->
start
;
JOIN_TAB
*
save_return_tab
=
join
->
return_tab
;
/*
/*
Now run the join for the inner tables. The first call is to run the
Now run the join for the inner tables. The first call is to run the
join, the second one is to signal EOF (this is essential for some
join, the second one is to signal EOF (this is essential for some
...
...
sql/sql_base.cc
View file @
6ae24e69
...
@@ -7784,7 +7784,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
...
@@ -7784,7 +7784,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
Item
*
item
=
table_list
->
jtbm_subselect
;
Item
*
item
=
table_list
->
jtbm_subselect
;
if
(
item
->
fix_fields
(
thd
,
&
item
))
if
(
item
->
fix_fields
(
thd
,
&
item
))
{
{
my_error
(
ER_TOO_MANY_TABLES
,
MYF
(
0
),
MAX_TABLES
);
my_error
(
ER_TOO_MANY_TABLES
,
MYF
(
0
),
MAX_TABLES
);
/* psergey-todo: WHY ER_TOO_MANY_TABLES ???*/
DBUG_RETURN
(
1
);
DBUG_RETURN
(
1
);
}
}
DBUG_ASSERT
(
item
==
table_list
->
jtbm_subselect
);
DBUG_ASSERT
(
item
==
table_list
->
jtbm_subselect
);
...
...
sql/sql_select.cc
View file @
6ae24e69
...
@@ -6991,9 +6991,8 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
...
@@ -6991,9 +6991,8 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
join_tab
=
parent
->
join_tab_reexec
;
join_tab
=
parent
->
join_tab_reexec
;
table
=
&
parent
->
table_reexec
[
0
];
parent
->
table_reexec
[
0
]
=
temp_table
;
table
=
&
parent
->
table_reexec
[
0
];
parent
->
table_reexec
[
0
]
=
temp_table
;
top_jtrange_tables
=
1
;
t
ables
=
t
op_jtrange_tables
=
1
;
tables
=
1
;
const_tables
=
0
;
const_tables
=
0
;
const_table_map
=
0
;
const_table_map
=
0
;
eliminated_tables
=
0
;
eliminated_tables
=
0
;
...
@@ -8417,11 +8416,8 @@ uint check_join_cache_usage(JOIN_TAB *tab,
...
@@ -8417,11 +8416,8 @@ uint check_join_cache_usage(JOIN_TAB *tab,
void
check_join_cache_usage_for_tables
(
JOIN
*
join
,
ulonglong
options
,
void
check_join_cache_usage_for_tables
(
JOIN
*
join
,
ulonglong
options
,
uint
no_jbuf_after
)
uint
no_jbuf_after
)
{
{
//JOIN_TAB *first_sjm_table= NULL;
//JOIN_TAB *last_sjm_table= NULL;
JOIN_TAB
*
tab
;
JOIN_TAB
*
tab
;
//for (uint i= join->const_tables; i < join->tables; i++)
for
(
tab
=
first_linear_tab
(
join
,
TRUE
);
for
(
tab
=
first_linear_tab
(
join
,
TRUE
);
tab
;
tab
;
tab
=
next_linear_tab
(
join
,
tab
,
TRUE
))
tab
=
next_linear_tab
(
join
,
tab
,
TRUE
))
...
@@ -8429,23 +8425,10 @@ void check_join_cache_usage_for_tables(JOIN *join, ulonglong options,
...
@@ -8429,23 +8425,10 @@ void check_join_cache_usage_for_tables(JOIN *join, ulonglong options,
tab
->
used_join_cache_level
=
join
->
max_allowed_join_cache_level
;
tab
->
used_join_cache_level
=
join
->
max_allowed_join_cache_level
;
}
}
//for (uint i= join->const_tables; i < join->tables; i++)
for
(
tab
=
first_linear_tab
(
join
,
TRUE
);
for
(
tab
=
first_linear_tab
(
join
,
TRUE
);
tab
;
tab
;
tab
=
next_linear_tab
(
join
,
tab
,
TRUE
))
tab
=
next_linear_tab
(
join
,
tab
,
TRUE
))
{
{
#if 0
if (sj_is_materialize_strategy(join->best_positions[i].sj_strategy))
{
first_sjm_table= tab;
last_sjm_table= tab + join->best_positions[i].n_sj_tables;
for (JOIN_TAB *sjm_tab= first_sjm_table;
sjm_tab != last_sjm_table; sjm_tab++)
sjm_tab->first_sjm_sibling= first_sjm_table;
}
if (!(tab >= first_sjm_table && tab < last_sjm_table))
tab->first_sjm_sibling= NULL;
#endif
JOIN_TAB
*
prev_tab
;
JOIN_TAB
*
prev_tab
;
restart:
restart:
tab
->
icp_other_tables_ok
=
TRUE
;
tab
->
icp_other_tables_ok
=
TRUE
;
...
@@ -8471,10 +8454,6 @@ void check_join_cache_usage_for_tables(JOIN *join, ulonglong options,
...
@@ -8471,10 +8454,6 @@ void check_join_cache_usage_for_tables(JOIN *join, ulonglong options,
we can first allocate a join buffer, then decide not to use it and free
we can first allocate a join buffer, then decide not to use it and free
it.
it.
*/
*/
/*
if (join->return_tab)
i= join->return_tab-join->join_tab-1; // always >= 0
*/
if
(
join
->
return_tab
)
if
(
join
->
return_tab
)
{
{
tab
=
join
->
return_tab
;
tab
=
join
->
return_tab
;
...
@@ -19617,12 +19596,19 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
...
@@ -19617,12 +19596,19 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
examined_rows
=
tab
->
limit
;
examined_rows
=
tab
->
limit
;
else
else
{
{
//tab->table->file->info(HA_STATUS_VARIABLE);
if
(
!
tab
->
table
->
pos_in_table_list
||
if
(
!
tab
->
table
->
pos_in_table_list
||
tab
->
table
->
is_filled_at_execution
())
// temporary, is_filled_at_execution
tab
->
table
->
is_filled_at_execution
())
// temporary, is_filled_at_execution
{
examined_rows
=
tab
->
records
;
examined_rows
=
tab
->
records
;
}
else
else
{
/*
handler->info(HA_STATUS_VARIABLE) has been called in
make_join_statistics()
*/
examined_rows
=
tab
->
table
->
file
->
stats
.
records
;
examined_rows
=
tab
->
table
->
file
->
stats
.
records
;
}
}
}
}
}
else
else
...
...
sql/sql_show.cc
View file @
6ae24e69
...
@@ -6600,14 +6600,12 @@ int make_schema_select(THD *thd, SELECT_LEX *sel,
...
@@ -6600,14 +6600,12 @@ int make_schema_select(THD *thd, SELECT_LEX *sel,
bool
get_schema_tables_result
(
JOIN
*
join
,
bool
get_schema_tables_result
(
JOIN
*
join
,
enum
enum_schema_table_state
executed_place
)
enum
enum_schema_table_state
executed_place
)
{
{
//JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
THD
*
thd
=
join
->
thd
;
THD
*
thd
=
join
->
thd
;
LEX
*
lex
=
thd
->
lex
;
LEX
*
lex
=
thd
->
lex
;
bool
result
=
0
;
bool
result
=
0
;
DBUG_ENTER
(
"get_schema_tables_result"
);
DBUG_ENTER
(
"get_schema_tables_result"
);
thd
->
no_warnings_for_error
=
1
;
thd
->
no_warnings_for_error
=
1
;
//for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
for
(
JOIN_TAB
*
tab
=
first_linear_tab
(
join
,
FALSE
);
for
(
JOIN_TAB
*
tab
=
first_linear_tab
(
join
,
FALSE
);
tab
;
tab
;
tab
=
next_linear_tab
(
join
,
tab
,
FALSE
))
tab
=
next_linear_tab
(
join
,
tab
,
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