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
c73d2318
Commit
c73d2318
authored
Sep 15, 2006
by
gkodinov/kgeorge@macbook.gmz
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal:/home/bk/mysql-4.1-opt
into macbook.gmz:/Users/kgeorge/mysql/work/B21180-4.1-opt
parents
5841147d
3183f736
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
3 deletions
+70
-3
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+29
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+26
-0
sql/opt_range.cc
sql/opt_range.cc
+13
-1
sql/opt_range.h
sql/opt_range.h
+2
-2
No files found.
mysql-test/r/subselect.result
View file @
c73d2318
...
...
@@ -2917,3 +2917,32 @@ retailerID statusID changed
0048 1 2006-01-06 12:37:50
0059 1 2006-01-06 12:37:50
drop table t1;
create table t1(a int, primary key (a));
insert into t1 values (10);
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b));
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 38 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
a a b
10 3 35989
explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system PRIMARY NULL NULL NULL 1
1 PRIMARY r const PRIMARY PRIMARY 4 const 1
2 DEPENDENT SUBQUERY t2 range b b 38 NULL 2 Using where
SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899'
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
a a b
10 1 359
drop table t1,t2;
mysql-test/t/subselect.test
View file @
c73d2318
...
...
@@ -1885,4 +1885,30 @@ select * from t1 r1
group
by
r2
.
retailerId
);
drop
table
t1
;
#
# Bug #21180: Subselect with index for both WHERE and ORDER BY
# produces empty result
#
create
table
t1
(
a
int
,
primary
key
(
a
));
insert
into
t1
values
(
10
);
create
table
t2
(
a
int
primary
key
,
b
varchar
(
32
),
c
int
,
unique
key
b
(
c
,
b
));
insert
into
t2
(
a
,
c
,
b
)
values
(
1
,
10
,
'359'
),
(
2
,
10
,
'35988'
),
(
3
,
10
,
'35989'
);
explain
SELECT
sql_no_cache
t1
.
a
,
r
.
a
,
r
.
b
FROM
t1
LEFT
JOIN
t2
r
ON
r
.
a
=
(
SELECT
t2
.
a
FROM
t2
WHERE
t2
.
c
=
t1
.
a
AND
t2
.
b
<=
'359899'
ORDER
BY
t2
.
c
DESC
,
t2
.
b
DESC
LIMIT
1
)
WHERE
t1
.
a
=
10
;
SELECT
sql_no_cache
t1
.
a
,
r
.
a
,
r
.
b
FROM
t1
LEFT
JOIN
t2
r
ON
r
.
a
=
(
SELECT
t2
.
a
FROM
t2
WHERE
t2
.
c
=
t1
.
a
AND
t2
.
b
<=
'359899'
ORDER
BY
t2
.
c
DESC
,
t2
.
b
DESC
LIMIT
1
)
WHERE
t1
.
a
=
10
;
explain
SELECT
sql_no_cache
t1
.
a
,
r
.
a
,
r
.
b
FROM
t1
LEFT
JOIN
t2
r
ON
r
.
a
=
(
SELECT
t2
.
a
FROM
t2
WHERE
t2
.
c
=
t1
.
a
AND
t2
.
b
<=
'359899'
ORDER
BY
t2
.
c
,
t2
.
b
LIMIT
1
)
WHERE
t1
.
a
=
10
;
SELECT
sql_no_cache
t1
.
a
,
r
.
a
,
r
.
b
FROM
t1
LEFT
JOIN
t2
r
ON
r
.
a
=
(
SELECT
t2
.
a
FROM
t2
WHERE
t2
.
c
=
t1
.
a
AND
t2
.
b
<=
'359899'
ORDER
BY
t2
.
c
,
t2
.
b
LIMIT
1
)
WHERE
t1
.
a
=
10
;
drop
table
t1
,
t2
;
# End of 4.1 tests
sql/opt_range.cc
View file @
c73d2318
...
...
@@ -2980,6 +2980,14 @@ int QUICK_SELECT::get_next()
}
}
void
QUICK_SELECT
::
reset
(
void
)
{
next
=
0
;
it
.
rewind
();
range
=
0
;
if
(
file
->
inited
==
handler
::
NONE
)
file
->
ha_index_init
(
index
);
}
/* Get next for geometrical indexes */
...
...
@@ -3201,7 +3209,11 @@ bool QUICK_SELECT_DESC::test_if_null_range(QUICK_RANGE *range_arg,
return
0
;
}
#endif
void
QUICK_SELECT_DESC
::
reset
(
void
)
{
rev_it
.
rewind
();
QUICK_SELECT
::
reset
();
}
/*****************************************************************************
** Print a quick range for debugging
...
...
sql/opt_range.h
View file @
c73d2318
...
...
@@ -86,7 +86,7 @@ public:
QUICK_SELECT
(
THD
*
thd
,
TABLE
*
table
,
uint
index_arg
,
bool
no_alloc
=
0
);
virtual
~
QUICK_SELECT
();
v
oid
reset
(
void
)
{
next
=
0
;
it
.
rewind
();
range
=
NULL
;}
v
irtual
void
reset
(
void
);
int
init
()
{
key_part_info
=
head
->
key_info
[
index
].
key_part
;
...
...
@@ -120,7 +120,7 @@ private:
#ifdef NOT_USED
bool
test_if_null_range
(
QUICK_RANGE
*
range
,
uint
used_key_parts
);
#endif
void
reset
(
void
)
{
next
=
0
;
rev_it
.
rewind
();
}
void
reset
(
void
)
;
List
<
QUICK_RANGE
>
rev_ranges
;
List_iterator
<
QUICK_RANGE
>
rev_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