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
7a6dda50
Commit
7a6dda50
authored
Jan 15, 2009
by
Georgi Kodinov
Browse files
Options
Browse Files
Download
Plain Diff
merged Bug 38795 to 5.0-bugteam
parents
50a8cdc6
83823a14
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
168 additions
and
9 deletions
+168
-9
mysql-test/r/greedy_optimizer.result
mysql-test/r/greedy_optimizer.result
+77
-0
mysql-test/t/greedy_optimizer.test
mysql-test/t/greedy_optimizer.test
+73
-0
sql/sql_select.cc
sql/sql_select.cc
+18
-9
No files found.
mysql-test/r/greedy_optimizer.result
View file @
7a6dda50
...
@@ -655,3 +655,80 @@ show status like 'Last_query_cost';
...
@@ -655,3 +655,80 @@ show status like 'Last_query_cost';
Variable_name Value
Variable_name Value
Last_query_cost 794.837037
Last_query_cost 794.837037
drop table t1,t2,t3,t4,t5,t6,t7;
drop table t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1 (a int, b int, d int, i int);
INSERT INTO t1 VALUES (1,1,1,1);
CREATE TABLE t2 (b int, c int, j int);
INSERT INTO t2 VALUES (1,1,1);
CREATE TABLE t2_1 (j int);
INSERT INTO t2_1 VALUES (1);
CREATE TABLE t3 (c int, f int);
INSERT INTO t3 VALUES (1,1);
CREATE TABLE t3_1 (f int);
INSERT INTO t3_1 VALUES (1);
CREATE TABLE t4 (d int, e int, k int);
INSERT INTO t4 VALUES (1,1,1);
CREATE TABLE t4_1 (k int);
INSERT INTO t4_1 VALUES (1);
CREATE TABLE t5 (g int, d int, h int, l int);
INSERT INTO t5 VALUES (1,1,1,1);
CREATE TABLE t5_1 (l int);
INSERT INTO t5_1 VALUES (1);
SET optimizer_search_depth = 3;
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
1
1
SELECT 1
FROM t1
LEFT JOIN (
t2 LEFT JOIN (t3 JOIN t3_1 ON t3.f = t3_1.f) ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
1
1
SELECT 1
FROM t1
LEFT JOIN (
(t2 JOIN t2_1 ON t2.j = t2_1.j) JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
1
1
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
(t4 JOIN t4_1 ON t4.k = t4_1.k) LEFT JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
1
1
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 LEFT JOIN (t5 JOIN t5_1 ON t5.l = t5_1.l) ON t5.d = t4.d
) ON t4.d = t1.d
;
1
1
SET optimizer_search_depth = DEFAULT;
DROP TABLE t1,t2,t2_1,t3,t3_1,t4,t4_1,t5,t5_1;
End of 5.0 tests
mysql-test/t/greedy_optimizer.test
View file @
7a6dda50
...
@@ -311,3 +311,76 @@ explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and
...
@@ -311,3 +311,76 @@ explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and
show
status
like
'Last_query_cost'
;
show
status
like
'Last_query_cost'
;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
;
#
# Bug # 38795: Automatic search depth and nested join's results in server
# crash
#
CREATE
TABLE
t1
(
a
int
,
b
int
,
d
int
,
i
int
);
INSERT
INTO
t1
VALUES
(
1
,
1
,
1
,
1
);
CREATE
TABLE
t2
(
b
int
,
c
int
,
j
int
);
INSERT
INTO
t2
VALUES
(
1
,
1
,
1
);
CREATE
TABLE
t2_1
(
j
int
);
INSERT
INTO
t2_1
VALUES
(
1
);
CREATE
TABLE
t3
(
c
int
,
f
int
);
INSERT
INTO
t3
VALUES
(
1
,
1
);
CREATE
TABLE
t3_1
(
f
int
);
INSERT
INTO
t3_1
VALUES
(
1
);
CREATE
TABLE
t4
(
d
int
,
e
int
,
k
int
);
INSERT
INTO
t4
VALUES
(
1
,
1
,
1
);
CREATE
TABLE
t4_1
(
k
int
);
INSERT
INTO
t4_1
VALUES
(
1
);
CREATE
TABLE
t5
(
g
int
,
d
int
,
h
int
,
l
int
);
INSERT
INTO
t5
VALUES
(
1
,
1
,
1
,
1
);
CREATE
TABLE
t5_1
(
l
int
);
INSERT
INTO
t5_1
VALUES
(
1
);
SET
optimizer_search_depth
=
3
;
SELECT
1
FROM
t1
LEFT
JOIN
(
t2
JOIN
t3
ON
t3
.
c
=
t2
.
c
)
ON
t2
.
b
=
t1
.
b
LEFT
JOIN
(
t4
JOIN
t5
ON
t5
.
d
=
t4
.
d
)
ON
t4
.
d
=
t1
.
d
;
SELECT
1
FROM
t1
LEFT
JOIN
(
t2
LEFT
JOIN
(
t3
JOIN
t3_1
ON
t3
.
f
=
t3_1
.
f
)
ON
t3
.
c
=
t2
.
c
)
ON
t2
.
b
=
t1
.
b
LEFT
JOIN
(
t4
JOIN
t5
ON
t5
.
d
=
t4
.
d
)
ON
t4
.
d
=
t1
.
d
;
SELECT
1
FROM
t1
LEFT
JOIN
(
(
t2
JOIN
t2_1
ON
t2
.
j
=
t2_1
.
j
)
JOIN
t3
ON
t3
.
c
=
t2
.
c
)
ON
t2
.
b
=
t1
.
b
LEFT
JOIN
(
t4
JOIN
t5
ON
t5
.
d
=
t4
.
d
)
ON
t4
.
d
=
t1
.
d
;
SELECT
1
FROM
t1
LEFT
JOIN
(
t2
JOIN
t3
ON
t3
.
c
=
t2
.
c
)
ON
t2
.
b
=
t1
.
b
LEFT
JOIN
(
(
t4
JOIN
t4_1
ON
t4
.
k
=
t4_1
.
k
)
LEFT
JOIN
t5
ON
t5
.
d
=
t4
.
d
)
ON
t4
.
d
=
t1
.
d
;
SELECT
1
FROM
t1
LEFT
JOIN
(
t2
JOIN
t3
ON
t3
.
c
=
t2
.
c
)
ON
t2
.
b
=
t1
.
b
LEFT
JOIN
(
t4
LEFT
JOIN
(
t5
JOIN
t5_1
ON
t5
.
l
=
t5_1
.
l
)
ON
t5
.
d
=
t4
.
d
)
ON
t4
.
d
=
t1
.
d
;
SET
optimizer_search_depth
=
DEFAULT
;
DROP
TABLE
t1
,
t2
,
t2_1
,
t3
,
t3_1
,
t4
,
t4_1
,
t5
,
t5_1
;
--
echo
End
of
5.0
tests
sql/sql_select.cc
View file @
7a6dda50
...
@@ -100,7 +100,7 @@ static COND* substitute_for_best_equal_field(COND *cond,
...
@@ -100,7 +100,7 @@ static COND* substitute_for_best_equal_field(COND *cond,
void
*
table_join_idx
);
void
*
table_join_idx
);
static
COND
*
simplify_joins
(
JOIN
*
join
,
List
<
TABLE_LIST
>
*
join_list
,
static
COND
*
simplify_joins
(
JOIN
*
join
,
List
<
TABLE_LIST
>
*
join_list
,
COND
*
conds
,
bool
top
);
COND
*
conds
,
bool
top
);
static
bool
check_interleaving_with_nj
(
JOIN_TAB
*
last
,
JOIN_TAB
*
next
);
static
bool
check_interleaving_with_nj
(
JOIN_TAB
*
next
);
static
void
restore_prev_nj_state
(
JOIN_TAB
*
last
);
static
void
restore_prev_nj_state
(
JOIN_TAB
*
last
);
static
void
reset_nj_counters
(
List
<
TABLE_LIST
>
*
join_list
);
static
void
reset_nj_counters
(
List
<
TABLE_LIST
>
*
join_list
);
static
uint
build_bitmap_for_nested_joins
(
List
<
TABLE_LIST
>
*
join_list
,
static
uint
build_bitmap_for_nested_joins
(
List
<
TABLE_LIST
>
*
join_list
,
...
@@ -4718,6 +4718,18 @@ greedy_search(JOIN *join,
...
@@ -4718,6 +4718,18 @@ greedy_search(JOIN *join,
*/
*/
join
->
positions
[
idx
]
=
best_pos
;
join
->
positions
[
idx
]
=
best_pos
;
/*
Update the interleaving state after extending the current partial plan
with a new table.
We are doing this here because best_extension_by_limited_search reverts
the interleaving state to the one of the non-extended partial plan
on exit.
*/
IF_DBUG
(
bool
is_interleave_error
=
)
check_interleaving_with_nj
(
best_table
);
/* This has been already checked by best_extension_by_limited_search */
DBUG_ASSERT
(
!
is_interleave_error
);
/* find the position of 'best_table' in 'join->best_ref' */
/* find the position of 'best_table' in 'join->best_ref' */
best_idx
=
idx
;
best_idx
=
idx
;
JOIN_TAB
*
pos
=
join
->
best_ref
[
best_idx
];
JOIN_TAB
*
pos
=
join
->
best_ref
[
best_idx
];
...
@@ -4735,7 +4747,7 @@ greedy_search(JOIN *join,
...
@@ -4735,7 +4747,7 @@ greedy_search(JOIN *join,
--
size_remain
;
--
size_remain
;
++
idx
;
++
idx
;
DBUG_EXECUTE
(
"opt"
,
print_plan
(
join
,
join
->
tables
,
DBUG_EXECUTE
(
"opt"
,
print_plan
(
join
,
idx
,
record_count
,
read_time
,
read_time
,
record_count
,
read_time
,
read_time
,
"extended"
););
"extended"
););
}
while
(
TRUE
);
}
while
(
TRUE
);
...
@@ -4886,7 +4898,7 @@ best_extension_by_limited_search(JOIN *join,
...
@@ -4886,7 +4898,7 @@ best_extension_by_limited_search(JOIN *join,
table_map
real_table_bit
=
s
->
table
->
map
;
table_map
real_table_bit
=
s
->
table
->
map
;
if
((
remaining_tables
&
real_table_bit
)
&&
if
((
remaining_tables
&
real_table_bit
)
&&
!
(
remaining_tables
&
s
->
dependent
)
&&
!
(
remaining_tables
&
s
->
dependent
)
&&
(
!
idx
||
!
check_interleaving_with_nj
(
join
->
positions
[
idx
-
1
].
table
,
s
)))
(
!
idx
||
!
check_interleaving_with_nj
(
s
)))
{
{
double
current_record_count
,
current_read_time
;
double
current_record_count
,
current_read_time
;
...
@@ -5031,7 +5043,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
...
@@ -5031,7 +5043,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
{
{
table_map
real_table_bit
=
s
->
table
->
map
;
table_map
real_table_bit
=
s
->
table
->
map
;
if
((
rest_tables
&
real_table_bit
)
&&
!
(
rest_tables
&
s
->
dependent
)
&&
if
((
rest_tables
&
real_table_bit
)
&&
!
(
rest_tables
&
s
->
dependent
)
&&
(
!
idx
||
!
check_interleaving_with_nj
(
join
->
positions
[
idx
-
1
].
table
,
s
)))
(
!
idx
||
!
check_interleaving_with_nj
(
s
)))
{
{
double
records
,
best
;
double
records
,
best
;
best_access_path
(
join
,
s
,
thd
,
rest_tables
,
idx
,
record_count
,
best_access_path
(
join
,
s
,
thd
,
rest_tables
,
idx
,
record_count
,
...
@@ -8403,9 +8415,6 @@ static void reset_nj_counters(List<TABLE_LIST> *join_list)
...
@@ -8403,9 +8415,6 @@ static void reset_nj_counters(List<TABLE_LIST> *join_list)
SYNOPSIS
SYNOPSIS
check_interleaving_with_nj()
check_interleaving_with_nj()
join Join being processed
last_tab Last table in current partial join order (this function is
not called for empty partial join orders)
next_tab Table we're going to extend the current partial join with
next_tab Table we're going to extend the current partial join with
DESCRIPTION
DESCRIPTION
...
@@ -8490,10 +8499,10 @@ static void reset_nj_counters(List<TABLE_LIST> *join_list)
...
@@ -8490,10 +8499,10 @@ static void reset_nj_counters(List<TABLE_LIST> *join_list)
TRUE Requested join order extension not allowed.
TRUE Requested join order extension not allowed.
*/
*/
static
bool
check_interleaving_with_nj
(
JOIN_TAB
*
last_tab
,
JOIN_TAB
*
next_tab
)
static
bool
check_interleaving_with_nj
(
JOIN_TAB
*
next_tab
)
{
{
TABLE_LIST
*
next_emb
=
next_tab
->
table
->
pos_in_table_list
->
embedding
;
TABLE_LIST
*
next_emb
=
next_tab
->
table
->
pos_in_table_list
->
embedding
;
JOIN
*
join
=
las
t_tab
->
join
;
JOIN
*
join
=
nex
t_tab
->
join
;
if
(
join
->
cur_embedding_map
&
~
next_tab
->
embedding_map
)
if
(
join
->
cur_embedding_map
&
~
next_tab
->
embedding_map
)
{
{
...
...
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