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
2c25a86b
Commit
2c25a86b
authored
Dec 10, 2003
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-4.0
into mysql.com:/home/kostja/mysql/mysql-4.0-1335
parents
5d0cd256
08e7fb2d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
3 deletions
+66
-3
mysql-test/r/group_by.result
mysql-test/r/group_by.result
+30
-1
mysql-test/t/group_by.test
mysql-test/t/group_by.test
+24
-0
sql/sql_select.cc
sql/sql_select.cc
+12
-2
No files found.
mysql-test/r/group_by.result
View file @
2c25a86b
...
@@ -287,7 +287,7 @@ table type possible_keys key key_len ref rows Extra
...
@@ -287,7 +287,7 @@ table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 8 Using filesort
t1 ALL NULL NULL NULL NULL 8 Using filesort
explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null;
explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null;
table type possible_keys key key_len ref rows Extra
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 8
t1 ALL NULL NULL NULL NULL 8
Using filesort
select sql_big_result spid,sum(userid) from t1 group by spid desc;
select sql_big_result spid,sum(userid) from t1 group by spid desc;
spid sum(userid)
spid sum(userid)
7 3
7 3
...
@@ -597,3 +597,32 @@ count(*) category
...
@@ -597,3 +597,32 @@ count(*) category
1 3
1 3
1 4
1 4
drop table t1;
drop table t1;
CREATE TABLE t1 (
userid int(10) unsigned,
score smallint(5) unsigned,
key (score)
);
INSERT INTO t1 VALUES (1,1),(2,2),(1,1),(3,3),(3,3),(3,3),(3,3),(3,3);
SELECT userid,count(*) FROM t1 GROUP BY userid DESC;
userid count(*)
3 5
2 1
1 2
EXPLAIN SELECT userid,count(*) FROM t1 GROUP BY userid DESC;
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort
DROP TABLE t1;
CREATE TABLE t1 (
i int(11) default NULL,
j int(11) default NULL
);
INSERT INTO t1 VALUES (1,2),(2,3),(4,5),(3,5),(1,5),(23,5);
SELECT i, COUNT(DISTINCT(i)) FROM t1 GROUP BY j ORDER BY NULL;
i COUNT(DISTINCT(i))
1 1
2 1
4 4
explain SELECT i, COUNT(DISTINCT(i)) FROM t1 GROUP BY j ORDER BY NULL;
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 6 Using filesort
DROP TABLE t1;
mysql-test/t/group_by.test
View file @
2c25a86b
...
@@ -423,3 +423,27 @@ select id, sum(qty) as sqty, count(qty) as cqty from t1 group by id having sum(q
...
@@ -423,3 +423,27 @@ select id, sum(qty) as sqty, count(qty) as cqty from t1 group by id having sum(q
select
count
(
*
),
case
interval
(
qty
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
when
-
1
then
NULL
when
0
then
"zero"
when
1
then
"one"
when
2
then
"two"
end
as
category
from
t1
group
by
category
;
select
count
(
*
),
case
interval
(
qty
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
when
-
1
then
NULL
when
0
then
"zero"
when
1
then
"one"
when
2
then
"two"
end
as
category
from
t1
group
by
category
;
select
count
(
*
),
interval
(
qty
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
as
category
from
t1
group
by
category
;
select
count
(
*
),
interval
(
qty
,
2
,
3
,
4
,
5
,
6
,
7
,
8
)
as
category
from
t1
group
by
category
;
drop
table
t1
;
drop
table
t1
;
#
# Tests for bug #1355: 'Using filesort' is missing in EXPLAIN when ORDER BY
# NULL is used.
#
CREATE
TABLE
t1
(
userid
int
(
10
)
unsigned
,
score
smallint
(
5
)
unsigned
,
key
(
score
)
);
INSERT
INTO
t1
VALUES
(
1
,
1
),(
2
,
2
),(
1
,
1
),(
3
,
3
),(
3
,
3
),(
3
,
3
),(
3
,
3
),(
3
,
3
);
# Here we select unordered GROUP BY into a temporary talbe,
# and then sort it with filesort (GROUP BY in MySQL
# implies sorted order of results)
SELECT
userid
,
count
(
*
)
FROM
t1
GROUP
BY
userid
DESC
;
EXPLAIN
SELECT
userid
,
count
(
*
)
FROM
t1
GROUP
BY
userid
DESC
;
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
i
int
(
11
)
default
NULL
,
j
int
(
11
)
default
NULL
);
INSERT
INTO
t1
VALUES
(
1
,
2
),(
2
,
3
),(
4
,
5
),(
3
,
5
),(
1
,
5
),(
23
,
5
);
SELECT
i
,
COUNT
(
DISTINCT
(
i
))
FROM
t1
GROUP
BY
j
ORDER
BY
NULL
;
explain
SELECT
i
,
COUNT
(
DISTINCT
(
i
))
FROM
t1
GROUP
BY
j
ORDER
BY
NULL
;
DROP
TABLE
t1
;
sql/sql_select.cc
View file @
2c25a86b
...
@@ -696,8 +696,18 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
...
@@ -696,8 +696,18 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
if
(
select_options
&
SELECT_DESCRIBE
)
if
(
select_options
&
SELECT_DESCRIBE
)
{
{
if
(
!
order
&&
!
no_order
)
/*
order
=
group
;
Check if we managed to optimize ORDER BY away and don't use temporary
table to resolve ORDER BY: in that case, we only may need to do
filesort for GROUP BY.
*/
if
(
!
order
&&
!
no_order
&&
(
!
skip_sort_order
||
!
need_tmp
))
{
/* Reset 'order' to 'group' and reinit variables describing 'order' */
order
=
group
;
simple_order
=
simple_group
;
skip_sort_order
=
0
;
}
if
(
order
&&
if
(
order
&&
(
join
.
const_tables
==
join
.
tables
||
(
join
.
const_tables
==
join
.
tables
||
((
simple_order
||
skip_sort_order
)
&&
((
simple_order
||
skip_sort_order
)
&&
...
...
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