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
801a4ebc
Commit
801a4ebc
authored
Jul 06, 2011
by
Igor Babaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge.
parents
4fadcc2b
b79316f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
13 deletions
+69
-13
mysql-test/r/derived_view.result
mysql-test/r/derived_view.result
+27
-0
mysql-test/t/derived_view.test
mysql-test/t/derived_view.test
+21
-0
sql/sql_select.cc
sql/sql_select.cc
+21
-13
No files found.
mysql-test/r/derived_view.result
View file @
801a4ebc
...
@@ -794,3 +794,30 @@ WHERE t4.f2 = t3.f2 AND t4.f2 = t.f1 ORDER BY f;
...
@@ -794,3 +794,30 @@ WHERE t4.f2 = t3.f2 AND t4.f2 = t.f1 ORDER BY f;
f
f
x
x
DROP TABLE t1,t2,t3,t4;
DROP TABLE t1,t2,t3,t4;
#
# LP bug #806431: join over materialized derived with key
#
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (0,0),(3,0),(1,0);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT a,b FROM t1 ;
SET SESSION optimizer_switch='derived_with_keys=off';
SELECT * FROM t1 AS t JOIN v1 AS v WHERE t.a = v.b AND t.b = v.b;
a b a b
0 0 0 0
0 0 3 0
0 0 1 0
SET SESSION optimizer_switch='derived_with_keys=on';
EXPLAIN
SELECT * FROM t1 AS t JOIN v1 AS v WHERE t.a = v.b AND t.b = v.b;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t.a 2
2 DERIVED t1 ALL NULL NULL NULL NULL 3
SELECT * FROM t1 AS t JOIN v1 AS v WHERE t.a = v.b AND t.b = v.b;
a b a b
0 0 1 0
0 0 3 0
0 0 0 0
SET SESSION optimizer_switch=default;
DROP VIEW v1;
DROP TABLE t1;
mysql-test/t/derived_view.test
View file @
801a4ebc
...
@@ -414,3 +414,24 @@ SELECT t.f1 AS f
...
@@ -414,3 +414,24 @@ SELECT t.f1 AS f
DROP
TABLE
t1
,
t2
,
t3
,
t4
;
DROP
TABLE
t1
,
t2
,
t3
,
t4
;
--
echo
#
--
echo
# LP bug #806431: join over materialized derived with key
--
echo
#
CREATE
TABLE
t1
(
a
int
,
b
int
);
INSERT
INTO
t1
VALUES
(
0
,
0
),(
3
,
0
),(
1
,
0
);
CREATE
ALGORITHM
=
TEMPTABLE
VIEW
v1
AS
SELECT
a
,
b
FROM
t1
;
SET
SESSION
optimizer_switch
=
'derived_with_keys=off'
;
SELECT
*
FROM
t1
AS
t
JOIN
v1
AS
v
WHERE
t
.
a
=
v
.
b
AND
t
.
b
=
v
.
b
;
SET
SESSION
optimizer_switch
=
'derived_with_keys=on'
;
EXPLAIN
SELECT
*
FROM
t1
AS
t
JOIN
v1
AS
v
WHERE
t
.
a
=
v
.
b
AND
t
.
b
=
v
.
b
;
SELECT
*
FROM
t1
AS
t
JOIN
v1
AS
v
WHERE
t
.
a
=
v
.
b
AND
t
.
b
=
v
.
b
;
SET
SESSION
optimizer_switch
=
default
;
DROP
VIEW
v1
;
DROP
TABLE
t1
;
sql/sql_select.cc
View file @
801a4ebc
...
@@ -8342,17 +8342,29 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys)
...
@@ -8342,17 +8342,29 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys)
return
TRUE
;
return
TRUE
;
uint
keyno
=
0
;
uint
keyno
=
0
;
KEYUSE
*
first_keyuse
=
keyuse
;
KEYUSE
*
first_keyuse
=
keyuse
;
uint
prev_part
=
(
uint
)
(
-
1
)
;
uint
prev_part
=
keyuse
->
keypart
;
uint
parts
=
0
;
uint
parts
=
0
;
uint
i
=
0
;
uint
i
=
0
;
do
for
(
;
i
<
count
&&
keyno
<
keys
;
)
{
{
keyuse
->
key
=
keyno
;
do
keyuse
->
keypart_map
=
(
key_part_map
)
(
1
<<
parts
);
{
keyuse
++
;
keyuse
->
key
=
keyno
;
if
(
++
i
==
count
||
keyuse
->
used_tables
!=
first_keyuse
->
used_tables
)
keyuse
->
keypart_map
=
(
key_part_map
)
(
1
<<
parts
);
keyuse
++
;
i
++
;
}
while
(
i
<
count
&&
keyuse
->
used_tables
==
first_keyuse
->
used_tables
&&
keyuse
->
keypart
==
prev_part
);
parts
++
;
if
(
i
<
count
&&
keyuse
->
used_tables
==
first_keyuse
->
used_tables
)
{
prev_part
=
keyuse
->
keypart
;
}
else
{
{
if
(
table
->
add_tmp_key
(
keyno
,
++
parts
,
if
(
table
->
add_tmp_key
(
keyno
,
parts
,
get_next_field_for_derived_key
,
get_next_field_for_derived_key
,
(
uchar
*
)
&
first_keyuse
,
(
uchar
*
)
&
first_keyuse
,
FALSE
))
FALSE
))
...
@@ -8361,14 +8373,10 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys)
...
@@ -8361,14 +8373,10 @@ bool generate_derived_keys_for_table(KEYUSE *keyuse, uint count, uint keys)
first_keyuse
=
keyuse
;
first_keyuse
=
keyuse
;
keyno
++
;
keyno
++
;
parts
=
0
;
parts
=
0
;
prev_part
=
(
uint
)
(
-
1
);
}
else
if
(
keyuse
->
keypart
!=
prev_part
)
{
parts
++
;
prev_part
=
keyuse
->
keypart
;
prev_part
=
keyuse
->
keypart
;
}
}
}
while
(
keyno
<
keys
);
}
return
FALSE
;
return
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