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
5db5e19a
Commit
5db5e19a
authored
Dec 17, 2009
by
Satya B
Browse files
Options
Browse Files
Download
Plain Diff
merge to mysql-5.1-bugteam
parents
bbf079cf
6863f7dc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
1 deletion
+77
-1
mysql-test/r/join_outer.result
mysql-test/r/join_outer.result
+35
-0
mysql-test/t/join_outer.test
mysql-test/t/join_outer.test
+29
-0
sql/sql_select.cc
sql/sql_select.cc
+13
-1
No files found.
mysql-test/r/join_outer.result
View file @
5db5e19a
...
...
@@ -1254,3 +1254,38 @@ SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d<=>NULL;
c e d
1 0 NULL
DROP TABLE t1,t2;
#
# Bug#47650: using group by with rollup without indexes returns incorrect
# results with where
#
CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (1);
CREATE TABLE t2 ( a INT, b INT );
INSERT INTO t2 VALUES (1, 1),(1, 2),(1, 3),(2, 4),(2, 5);
EXPLAIN
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 LEFT JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 5
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 LEFT JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
a COUNT( t2.b ) SUM( t2.b ) MAX( t2.b )
1 3 6 3
NULL 3 6 3
EXPLAIN
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where
SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
FROM t1 JOIN t2 USING( a )
GROUP BY t1.a WITH ROLLUP;
a COUNT( t2.b ) SUM( t2.b ) MAX( t2.b )
1 3 6 3
NULL 3 6 3
DROP TABLE t1, t2;
mysql-test/t/join_outer.test
View file @
5db5e19a
...
...
@@ -867,3 +867,32 @@ SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d<=>NULL;
DROP
TABLE
t1
,
t2
;
--
echo
#
--
echo
# Bug#47650: using group by with rollup without indexes returns incorrect
--
echo
# results with where
--
echo
#
CREATE
TABLE
t1
(
a
INT
);
INSERT
INTO
t1
VALUES
(
1
);
CREATE
TABLE
t2
(
a
INT
,
b
INT
);
INSERT
INTO
t2
VALUES
(
1
,
1
),(
1
,
2
),(
1
,
3
),(
2
,
4
),(
2
,
5
);
EXPLAIN
SELECT
t1
.
a
,
COUNT
(
t2
.
b
),
SUM
(
t2
.
b
),
MAX
(
t2
.
b
)
FROM
t1
LEFT
JOIN
t2
USING
(
a
)
GROUP
BY
t1
.
a
WITH
ROLLUP
;
SELECT
t1
.
a
,
COUNT
(
t2
.
b
),
SUM
(
t2
.
b
),
MAX
(
t2
.
b
)
FROM
t1
LEFT
JOIN
t2
USING
(
a
)
GROUP
BY
t1
.
a
WITH
ROLLUP
;
EXPLAIN
SELECT
t1
.
a
,
COUNT
(
t2
.
b
),
SUM
(
t2
.
b
),
MAX
(
t2
.
b
)
FROM
t1
JOIN
t2
USING
(
a
)
GROUP
BY
t1
.
a
WITH
ROLLUP
;
SELECT
t1
.
a
,
COUNT
(
t2
.
b
),
SUM
(
t2
.
b
),
MAX
(
t2
.
b
)
FROM
t1
JOIN
t2
USING
(
a
)
GROUP
BY
t1
.
a
WITH
ROLLUP
;
DROP
TABLE
t1
,
t2
;
sql/sql_select.cc
View file @
5db5e19a
...
...
@@ -7124,7 +7124,19 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
for
(
order
=
first_order
;
order
;
order
=
order
->
next
)
{
table_map
order_tables
=
order
->
item
[
0
]
->
used_tables
();
if
(
order
->
item
[
0
]
->
with_sum_func
)
if
(
order
->
item
[
0
]
->
with_sum_func
||
/*
If the outer table of an outer join is const (either by itself or
after applying WHERE condition), grouping on a field from such a
table will be optimized away and filesort without temporary table
will be used unless we prevent that now. Filesort is not fit to
handle joins and the join condition is not applied. We can't detect
the case without an expensive test, however, so we force temporary
table for all queries containing more than one table, ROLLUP, and an
outer join.
*/
(
join
->
tables
>
1
&&
join
->
rollup
.
state
==
ROLLUP
::
STATE_INITED
&&
join
->
outer_join
))
*
simple_order
=
0
;
// Must do a temp table to sort
else
if
(
!
(
order_tables
&
not_const_tables
))
{
...
...
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