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
c28d7cbe
Commit
c28d7cbe
authored
Dec 05, 2011
by
Igor Babaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
a85454de
7d1f4126
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
14 deletions
+135
-14
mysql-test/r/join_cache.result
mysql-test/r/join_cache.result
+47
-0
mysql-test/t/join_cache.test
mysql-test/t/join_cache.test
+40
-0
sql/sql_select.cc
sql/sql_select.cc
+46
-14
sql/sql_select.h
sql/sql_select.h
+2
-0
No files found.
mysql-test/r/join_cache.result
View file @
c28d7cbe
...
...
@@ -5179,4 +5179,51 @@ a b
SET SESSION join_cache_level = DEFAULT;
SET optimizer_switch=@tmp887479_optimizer_switch;
DROP TABLE t1,t2;
#
# Bug #899777: join_cache_level=4 + semijoin=on
#
CREATE TABLE t1 (a int, b int, c int, UNIQUE INDEX idx (a));
INSERT INTO t1 VALUES (1,8,6), (2,2,8);
CREATE TABLE t2 (a int, b int, c int, UNIQUE INDEX idx (a));
INSERT INTO t2 VALUES (1,8,6), (2,2,8);
CREATE TABLE t3 (a int, b int, c int, UNIQUE INDEX idx (a));
INSERT INTO t3 VALUES (1,8,6), (2,2,8);
CREATE TABLE t4 (a int, b int, c int, UNIQUE INDEX idx (a));
INSERT INTO t4 VALUES (1,8,6), (2,2,8);
SET @tmp_optimizer_switch=@@optimizer_switch;
SET SESSION optimizer_switch='semijoin=on';
SET SESSION optimizer_switch='semijoin_with_cache=on';
SET SESSION join_cache_level=1;
EXPLAIN
SELECT t1.* FROM t1,t2
WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
AND t1.a = 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const idx idx 5 const 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Start temporary; Using join buffer (flat, BNL join)
1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT t1.* FROM t1,t2
WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
AND t1.a = 1;
a b c
1 8 6
SET SESSION join_cache_level=4;
EXPLAIN
SELECT t1.* FROM t1,t2
WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
AND t1.a = 1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const idx idx 5 const 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY t3 hash_ALL NULL #hash#$hj 5 const 2 Using where; Start temporary; Using join buffer (flat, BNLH join)
1 PRIMARY t4 hash_ALL NULL #hash#$hj 10 const,test.t2.b 2 Using where; End temporary; Using join buffer (incremental, BNLH join)
SELECT t1.* FROM t1,t2
WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
AND t1.a = 1;
a b c
1 8 6
SET SESSION join_cache_level = DEFAULT;
SET optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2,t3,t4;
set @@optimizer_switch=@save_optimizer_switch;
mysql-test/t/join_cache.test
View file @
c28d7cbe
...
...
@@ -3254,5 +3254,45 @@ SET optimizer_switch=@tmp887479_optimizer_switch;
DROP
TABLE
t1
,
t2
;
--
echo
#
--
echo
# Bug #899777: join_cache_level=4 + semijoin=on
--
echo
#
CREATE
TABLE
t1
(
a
int
,
b
int
,
c
int
,
UNIQUE
INDEX
idx
(
a
));
INSERT
INTO
t1
VALUES
(
1
,
8
,
6
),
(
2
,
2
,
8
);
CREATE
TABLE
t2
(
a
int
,
b
int
,
c
int
,
UNIQUE
INDEX
idx
(
a
));
INSERT
INTO
t2
VALUES
(
1
,
8
,
6
),
(
2
,
2
,
8
);
CREATE
TABLE
t3
(
a
int
,
b
int
,
c
int
,
UNIQUE
INDEX
idx
(
a
));
INSERT
INTO
t3
VALUES
(
1
,
8
,
6
),
(
2
,
2
,
8
);
CREATE
TABLE
t4
(
a
int
,
b
int
,
c
int
,
UNIQUE
INDEX
idx
(
a
));
INSERT
INTO
t4
VALUES
(
1
,
8
,
6
),
(
2
,
2
,
8
);
SET
@
tmp_optimizer_switch
=@@
optimizer_switch
;
SET
SESSION
optimizer_switch
=
'semijoin=on'
;
SET
SESSION
optimizer_switch
=
'semijoin_with_cache=on'
;
SET
SESSION
join_cache_level
=
1
;
EXPLAIN
SELECT
t1
.*
FROM
t1
,
t2
WHERE
(
t1
.
b
,
t2
.
b
)
IN
(
SELECT
t3
.
b
,
t4
.
b
FROM
t3
,
t4
WHERE
t4
.
c
=
t3
.
b
)
AND
t1
.
a
=
1
;
SELECT
t1
.*
FROM
t1
,
t2
WHERE
(
t1
.
b
,
t2
.
b
)
IN
(
SELECT
t3
.
b
,
t4
.
b
FROM
t3
,
t4
WHERE
t4
.
c
=
t3
.
b
)
AND
t1
.
a
=
1
;
SET
SESSION
join_cache_level
=
4
;
EXPLAIN
SELECT
t1
.*
FROM
t1
,
t2
WHERE
(
t1
.
b
,
t2
.
b
)
IN
(
SELECT
t3
.
b
,
t4
.
b
FROM
t3
,
t4
WHERE
t4
.
c
=
t3
.
b
)
AND
t1
.
a
=
1
;
SELECT
t1
.*
FROM
t1
,
t2
WHERE
(
t1
.
b
,
t2
.
b
)
IN
(
SELECT
t3
.
b
,
t4
.
b
FROM
t3
,
t4
WHERE
t4
.
c
=
t3
.
b
)
AND
t1
.
a
=
1
;
SET
SESSION
join_cache_level
=
DEFAULT
;
SET
optimizer_switch
=@
tmp_optimizer_switch
;
DROP
TABLE
t1
,
t2
,
t3
,
t4
;
# this must be the last command in the file
set
@@
optimizer_switch
=@
save_optimizer_switch
;
sql/sql_select.cc
View file @
c28d7cbe
...
...
@@ -7183,10 +7183,26 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
do
{
if
(
!
(
~
used_tables
&
keyuse
->
used_tables
)
&&
(
first_keyuse
||
keyuse
->
keypart
!=
(
keyuse
-
1
)
->
keypart
))
key_parts
++
;
first_keyuse
=
FALSE
;
if
(
!
(
~
used_tables
&
keyuse
->
used_tables
))
{
if
(
first_keyuse
)
{
key_parts
++
;
first_keyuse
=
FALSE
;
}
else
{
KEYUSE
*
curr
=
org_keyuse
;
for
(
;
curr
<
keyuse
;
curr
++
)
{
if
(
curr
->
keypart
==
keyuse
->
keypart
&&
!
(
~
used_tables
&
curr
->
used_tables
))
break
;
}
if
(
curr
==
keyuse
)
key_parts
++
;
}
}
keyuse
++
;
}
while
(
keyuse
->
table
==
table
&&
keyuse
->
is_for_hash_join
());
if
(
!
key_parts
)
...
...
@@ -7211,15 +7227,31 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
keyuse
=
org_keyuse
;
do
{
if
(
!
(
~
used_tables
&
keyuse
->
used_tables
)
&&
(
first_keyuse
||
keyuse
->
keypart
!=
(
keyuse
-
1
)
->
keypart
))
{
Field
*
field
=
table
->
field
[
keyuse
->
keypart
];
uint
fieldnr
=
keyuse
->
keypart
+
1
;
table
->
create_key_part_by_field
(
keyinfo
,
key_part_info
,
field
,
fieldnr
);
first_keyuse
=
FALSE
;
key_part_info
++
;
if
(
!
(
~
used_tables
&
keyuse
->
used_tables
))
{
bool
add_key_part
=
TRUE
;
if
(
!
first_keyuse
)
{
for
(
KEYUSE
*
curr
=
org_keyuse
;
curr
<
keyuse
;
curr
++
)
{
if
(
curr
->
keypart
==
keyuse
->
keypart
&&
!
(
~
used_tables
&
curr
->
used_tables
))
{
keyuse
->
keypart
=
NO_KEYPART
;
add_key_part
=
FALSE
;
break
;
}
}
}
if
(
add_key_part
)
{
Field
*
field
=
table
->
field
[
keyuse
->
keypart
];
uint
fieldnr
=
keyuse
->
keypart
+
1
;
table
->
create_key_part_by_field
(
keyinfo
,
key_part_info
,
field
,
fieldnr
);
key_part_info
++
;
}
}
first_keyuse
=
FALSE
;
keyuse
++
;
}
while
(
keyuse
->
table
==
table
&&
keyuse
->
is_for_hash_join
());
...
...
@@ -7302,8 +7334,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
{
if
(
are_tables_local
(
j
,
keyuse
->
val
->
used_tables
()))
{
if
((
is_hash_join_key_no
(
key
)
&&
(
keyparts
==
0
||
keyuse
->
keypart
!=
(
keyuse
-
1
)
->
keypart
))
||
if
((
is_hash_join_key_no
(
key
)
&&
keyuse
->
keypart
!=
NO_KEYPART
)
||
(
!
is_hash_join_key_no
(
key
)
&&
keyparts
==
keyuse
->
keypart
&&
!
(
found_part_ref_or_null
&
keyuse
->
optimize
)))
{
...
...
@@ -7357,6 +7388,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
for
(
i
=
0
;
i
<
keyparts
;
keyuse
++
,
i
++
)
{
while
(((
~
used_tables
)
&
keyuse
->
used_tables
)
||
keyuse
->
keypart
==
NO_KEYPART
||
(
keyuse
->
keypart
!=
(
is_hash_join_key_no
(
key
)
?
keyinfo
->
key_part
[
i
].
field
->
field_index
:
i
))
||
...
...
sql/sql_select.h
View file @
c28d7cbe
...
...
@@ -77,6 +77,8 @@ typedef struct keyuse_t {
bool
is_for_hash_join
()
{
return
is_hash_join_key_no
(
key
);
}
}
KEYUSE
;
#define NO_KEYPART ((uint)(-1))
class
store_key
;
const
int
NO_REF_PART
=
uint
(
-
1
);
...
...
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