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
3ecd3c34
Commit
3ecd3c34
authored
18 years ago
by
igor@rurik.mysql.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge rurik.mysql.com:/home/igor/dev/mysql-5.0-0
into rurik.mysql.com:/home/igor/dev/mysql-5.1-0
parents
e9a8a765
de6eedd7
Branches unavailable
Tags unavailable
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
17 deletions
+66
-17
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+29
-3
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+22
-0
sql/sql_select.cc
sql/sql_select.cc
+15
-14
No files found.
mysql-test/r/subselect.result
View file @
3ecd3c34
...
...
@@ -215,9 +215,9 @@ select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from
a
select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)
8 7.5
8 4.5
9 7.5
8 7.5
000
8 4.5
000
9 7.5
000
explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t4 ALL NULL NULL NULL NULL 3
...
...
@@ -3131,3 +3131,29 @@ a sum
3 20
4 40
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (a varchar(5), b varchar(10));
INSERT INTO t1 VALUES
('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
a b
BBB 4
CCC 7
AAA 8
EXPLAIN
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 9 Using temporary; Using filesort
ALTER TABLE t1 ADD INDEX(a);
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
a b
BBB 4
CCC 7
AAA 8
EXPLAIN
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where
2 DEPENDENT SUBQUERY t1 index NULL a 8 NULL 9 Using filesort
DROP TABLE t1;
This diff is collapsed.
Click to expand it.
mysql-test/t/subselect.test
View file @
3ecd3c34
...
...
@@ -2051,3 +2051,25 @@ SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a
HAVING
t2
.
c
+
sum
>
20
);
DROP
TABLE
t1
,
t2
,
t3
;
#
# Test for bug #16603: GROUP BY in a row subquery with a quantifier
# when an index is defined on the grouping field
CREATE
TABLE
t1
(
a
varchar
(
5
),
b
varchar
(
10
));
INSERT
INTO
t1
VALUES
(
'AAA'
,
5
),
(
'BBB'
,
4
),
(
'BBB'
,
1
),
(
'CCC'
,
2
),
(
'CCC'
,
7
),
(
'AAA'
,
2
),
(
'AAA'
,
4
),
(
'BBB'
,
3
),
(
'AAA'
,
8
);
SELECT
*
FROM
t1
WHERE
(
a
,
b
)
=
ANY
(
SELECT
a
,
max
(
b
)
FROM
t1
GROUP
BY
a
);
EXPLAIN
SELECT
*
FROM
t1
WHERE
(
a
,
b
)
=
ANY
(
SELECT
a
,
max
(
b
)
FROM
t1
GROUP
BY
a
);
ALTER
TABLE
t1
ADD
INDEX
(
a
);
SELECT
*
FROM
t1
WHERE
(
a
,
b
)
=
ANY
(
SELECT
a
,
max
(
b
)
FROM
t1
GROUP
BY
a
);
EXPLAIN
SELECT
*
FROM
t1
WHERE
(
a
,
b
)
=
ANY
(
SELECT
a
,
max
(
b
)
FROM
t1
GROUP
BY
a
);
DROP
TABLE
t1
;
This diff is collapsed.
Click to expand it.
sql/sql_select.cc
View file @
3ecd3c34
...
...
@@ -364,22 +364,8 @@ JOIN::prepare(Item ***rref_pointer_array,
select_lex
->
having_fix_field
=
0
;
if
(
having_fix_rc
||
thd
->
net
.
report_error
)
DBUG_RETURN
(
-
1
);
/* purecov: inspected */
if
(
having
->
with_sum_func
)
having
->
split_sum_func2
(
thd
,
ref_pointer_array
,
all_fields
,
&
having
,
TRUE
);
thd
->
lex
->
allow_sum_func
=
save_allow_sum_func
;
}
if
(
select_lex
->
inner_sum_func_list
)
{
Item_sum
*
end
=
select_lex
->
inner_sum_func_list
;
Item_sum
*
item_sum
=
end
;
do
{
item_sum
=
item_sum
->
next
;
item_sum
->
split_sum_func2
(
thd
,
ref_pointer_array
,
all_fields
,
item_sum
->
ref_by
,
FALSE
);
}
while
(
item_sum
!=
end
);
}
if
(
!
thd
->
lex
->
view_prepare_mode
)
{
...
...
@@ -397,6 +383,21 @@ JOIN::prepare(Item ***rref_pointer_array,
}
}
if
(
having
&&
having
->
with_sum_func
)
having
->
split_sum_func2
(
thd
,
ref_pointer_array
,
all_fields
,
&
having
,
TRUE
);
if
(
select_lex
->
inner_sum_func_list
)
{
Item_sum
*
end
=
select_lex
->
inner_sum_func_list
;
Item_sum
*
item_sum
=
end
;
do
{
item_sum
=
item_sum
->
next
;
item_sum
->
split_sum_func2
(
thd
,
ref_pointer_array
,
all_fields
,
item_sum
->
ref_by
,
FALSE
);
}
while
(
item_sum
!=
end
);
}
if
(
setup_ftfuncs
(
select_lex
))
/* should be after having->fix_fields */
DBUG_RETURN
(
-
1
);
...
...
This diff is collapsed.
Click to expand 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