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
2da037c7
Commit
2da037c7
authored
Sep 19, 2006
by
gkodinov/kgeorge@rakia.(none)
Browse files
Options
Browse Files
Download
Plain Diff
Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.0-opt
into rakia.(none):/home/kgeorge/mysql/autopush/B21540-5.0-opt
parents
cf9d1c91
5bc16fd9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
2 deletions
+114
-2
mysql-test/r/func_group.result
mysql-test/r/func_group.result
+1
-1
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+61
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+31
-0
sql/item_sum.cc
sql/item_sum.cc
+21
-1
No files found.
mysql-test/r/func_group.result
View file @
2da037c7
...
...
@@ -1013,7 +1013,7 @@ SELECT SQL_NO_CACHE
WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid
FROM t1 t, t2 c WHERE t.a = c.b;
minid
NULL
1
DROP TABLE t1,t2;
create table t1 select variance(0);
show create table t1;
...
...
mysql-test/r/subselect.result
View file @
2da037c7
...
...
@@ -3422,3 +3422,64 @@ id select_type table type possible_keys key key_len ref rows Extra
4 UNION t12 system NULL NULL NULL NULL 0 const row not found
NULL UNION RESULT <union2,4> ALL NULL NULL NULL NULL NULL
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT);
INSERT INTO t2 values (1);
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
(SELECT COUNT(DISTINCT t1.b) from t2)
2
1
1
SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
FROM t1 GROUP BY t1.a;
(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
2
1
1
SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b))
2 2
1 1
1 1
SELECT COUNT(DISTINCT t1.b),
(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
FROM t1 GROUP BY t1.a;
COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3)
2 2
1 1
1 1
SELECT (
SELECT (
SELECT COUNT(DISTINCT t1.b)
)
)
FROM t1 GROUP BY t1.a;
(
SELECT (
SELECT COUNT(DISTINCT t1.b)
)
)
2
1
1
SELECT (
SELECT (
SELECT (
SELECT COUNT(DISTINCT t1.b)
)
)
FROM t1 GROUP BY t1.a LIMIT 1)
FROM t1 t2
GROUP BY t2.a;
(
SELECT (
SELECT (
SELECT COUNT(DISTINCT t1.b)
)
)
FROM t1 GROUP BY t1.a LIMIT 1)
2
2
2
DROP TABLE t1,t2;
mysql-test/t/subselect.test
View file @
2da037c7
...
...
@@ -2332,3 +2332,34 @@ explain select * from t1 where not exists
((
select
t11
.
i
from
t1
t11
)
union
(
select
t12
.
i
from
t1
t12
));
DROP
TABLE
t1
;
#
# Bug #21540: Subqueries with no from and aggregate functions return
# wrong results
CREATE
TABLE
t1
(
a
INT
,
b
INT
);
CREATE
TABLE
t2
(
a
INT
);
INSERT
INTO
t2
values
(
1
);
INSERT
INTO
t1
VALUES
(
1
,
1
),(
1
,
2
),(
2
,
3
),(
3
,
4
);
SELECT
(
SELECT
COUNT
(
DISTINCT
t1
.
b
)
from
t2
)
FROM
t1
GROUP
BY
t1
.
a
;
SELECT
(
SELECT
COUNT
(
DISTINCT
t1
.
b
)
from
t2
union
select
1
from
t2
where
12
<
3
)
FROM
t1
GROUP
BY
t1
.
a
;
SELECT
COUNT
(
DISTINCT
t1
.
b
),
(
SELECT
COUNT
(
DISTINCT
t1
.
b
))
FROM
t1
GROUP
BY
t1
.
a
;
SELECT
COUNT
(
DISTINCT
t1
.
b
),
(
SELECT
COUNT
(
DISTINCT
t1
.
b
)
union
select
1
from
DUAL
where
12
<
3
)
FROM
t1
GROUP
BY
t1
.
a
;
SELECT
(
SELECT
(
SELECT
COUNT
(
DISTINCT
t1
.
b
)
)
)
FROM
t1
GROUP
BY
t1
.
a
;
SELECT
(
SELECT
(
SELECT
(
SELECT
COUNT
(
DISTINCT
t1
.
b
)
)
)
FROM
t1
GROUP
BY
t1
.
a
LIMIT
1
)
FROM
t1
t2
GROUP
BY
t2
.
a
;
DROP
TABLE
t1
,
t2
;
sql/item_sum.cc
View file @
2da037c7
...
...
@@ -246,7 +246,27 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
aggr_sl
->
inner_sum_func_list
->
next
=
this
;
}
aggr_sl
->
inner_sum_func_list
=
this
;
aggr_sl
->
with_sum_func
=
1
;
/*
Mark Item_subselect(s) as containing aggregate function all the way up
to aggregate function's calculation context.
Note that we must not mark the Item of calculation context itself
because with_sum_func on the calculation context st_select_lex is
already set above.
with_sum_func being set for an Item means that this Item refers
(somewhere in it, e.g. one of its arguments if it's a function) directly
or through intermediate items to an aggregate function that is calculated
in a context "outside" of the Item (e.g. in the current or outer select).
with_sum_func being set for an st_select_lex means that this st_select_lex
has aggregate functions directly referenced (i.e. not through a sub-select).
*/
for
(
sl
=
thd
->
lex
->
current_select
;
sl
&&
sl
!=
aggr_sl
&&
sl
->
master_unit
()
->
item
;
sl
=
sl
->
master_unit
()
->
outer_select
()
)
sl
->
master_unit
()
->
item
->
with_sum_func
=
1
;
}
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