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
2c274c64
Commit
2c274c64
authored
Jun 09, 2002
by
monty@hundin.mysql.fi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fix for complicated GROUP BY ... ORDER BY query.
Fixed problem in access rights testing (from last patch)
parent
01094b13
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
62 deletions
+21
-62
mysql-test/r/group_by.result
mysql-test/r/group_by.result
+5
-26
mysql-test/t/group_by.test
mysql-test/t/group_by.test
+11
-26
sql/sql_parse.cc
sql/sql_parse.cc
+1
-1
sql/sql_select.cc
sql/sql_select.cc
+4
-9
No files found.
mysql-test/r/group_by.result
View file @
2c274c64
...
...
@@ -375,38 +375,17 @@ hijklm 2
DROP TABLE t1;
drop table if exists t1;
create table t1 (One int unsigned, Two int unsigned, Three int unsigned, Four int unsigned);
insert into t1 values (1,2,1,4);
insert into t1 values (1,2,2,4);
insert into t1 values (1,2,3,4);
insert into t1 values (1,2,4,4);
insert into t1 values (1,1,1,4);
insert into t1 values (1,1,2,4);
insert into t1 values (1,1,3,4);
insert into t1 values (1,1,4,4);
insert into t1 values (1,3,1,4);
insert into t1 values (1,3,2,4);
insert into t1 values (1,3,3,4);
insert into t1 values (1,3,4,4);
insert into t1 values (1,2,1,4),(1,2,2,4),(1,2,3,4),(1,2,4,4),(1,1,1,4),(1,1,2,4),(1,1,3,4),(1,1,4,4),(1,3,1,4),(1,3,2,4),(1,3,3,4),(1,3,4,4);
select One, Two, sum(Four) from t1 group by One,Two;
One Two sum(Four)
1 1 16
1 2 16
1 3 16
drop table if exists t1;
drop table if exists t1,t2;
drop table t1;
create table t1 (id integer primary key not null auto_increment, gender char(1));
insert into t1 values(NULL, 'M');
insert into t1 values(NULL, 'F');
insert into t1 values(NULL, 'F');
insert into t1 values(NULL, 'F');
insert into t1 values(NULL, 'M');
create table t2 (user_id integer not null, timestamp datetime);
insert into t2 values (1, sysdate());
insert into t2 values (2, sysdate());
insert into t2 values (1, sysdate());
insert into t2 values (3, sysdate());
insert into t2 values (4, sysdate());
insert into t2 values (4, sysdate());
insert into t1 values (NULL, 'M'), (NULL, 'F'),(NULL, 'F'),(NULL, 'F'),(NULL, 'M');
create table t2 (user_id integer not null, date date);
insert into t2 values (1, '2002-06-09'),(2, '2002-06-09'),(1, '2002-06-09'),(3, '2002-06-09'),(4, '2002-06-09'),(4, '2002-06-09');
select u.gender as gender, count(distinct u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender;
gender dist_count percentage
F 3 60.00
...
...
mysql-test/t/group_by.test
View file @
2c274c64
...
...
@@ -284,35 +284,20 @@ INSERT INTO t1 values ('hij','klm');
SELECT
CONCAT
(
a
,
b
),
count
(
*
)
FROM
t1
GROUP
BY
1
;
DROP
TABLE
t1
;
drop
table
if
exists
t1
;
#
# Test problem with ORDER BY on a SUM() column
#
create
table
t1
(
One
int
unsigned
,
Two
int
unsigned
,
Three
int
unsigned
,
Four
int
unsigned
);
insert
into
t1
values
(
1
,
2
,
1
,
4
);
insert
into
t1
values
(
1
,
2
,
2
,
4
);
insert
into
t1
values
(
1
,
2
,
3
,
4
);
insert
into
t1
values
(
1
,
2
,
4
,
4
);
insert
into
t1
values
(
1
,
1
,
1
,
4
);
insert
into
t1
values
(
1
,
1
,
2
,
4
);
insert
into
t1
values
(
1
,
1
,
3
,
4
);
insert
into
t1
values
(
1
,
1
,
4
,
4
);
insert
into
t1
values
(
1
,
3
,
1
,
4
);
insert
into
t1
values
(
1
,
3
,
2
,
4
);
insert
into
t1
values
(
1
,
3
,
3
,
4
);
insert
into
t1
values
(
1
,
3
,
4
,
4
);
insert
into
t1
values
(
1
,
2
,
1
,
4
),(
1
,
2
,
2
,
4
),(
1
,
2
,
3
,
4
),(
1
,
2
,
4
,
4
),(
1
,
1
,
1
,
4
),(
1
,
1
,
2
,
4
),(
1
,
1
,
3
,
4
),(
1
,
1
,
4
,
4
),(
1
,
3
,
1
,
4
),(
1
,
3
,
2
,
4
),(
1
,
3
,
3
,
4
),(
1
,
3
,
4
,
4
);
select
One
,
Two
,
sum
(
Four
)
from
t1
group
by
One
,
Two
;
drop
table
if
exists
t1
;
drop
table
if
exists
t1
,
t2
;
drop
table
t1
;
create
table
t1
(
id
integer
primary
key
not
null
auto_increment
,
gender
char
(
1
));
insert
into
t1
values
(
NULL
,
'M'
);
insert
into
t1
values
(
NULL
,
'F'
);
insert
into
t1
values
(
NULL
,
'F'
);
insert
into
t1
values
(
NULL
,
'F'
);
insert
into
t1
values
(
NULL
,
'M'
);
create
table
t2
(
user_id
integer
not
null
,
timestamp
datetime
);
insert
into
t2
values
(
1
,
sysdate
());
insert
into
t2
values
(
2
,
sysdate
());
insert
into
t2
values
(
1
,
sysdate
());
insert
into
t2
values
(
3
,
sysdate
());
insert
into
t2
values
(
4
,
sysdate
());
insert
into
t2
values
(
4
,
sysdate
());
insert
into
t1
values
(
NULL
,
'M'
),
(
NULL
,
'F'
),(
NULL
,
'F'
),(
NULL
,
'F'
),(
NULL
,
'M'
);
create
table
t2
(
user_id
integer
not
null
,
date
date
);
insert
into
t2
values
(
1
,
'2002-06-09'
),(
2
,
'2002-06-09'
),(
1
,
'2002-06-09'
),(
3
,
'2002-06-09'
),(
4
,
'2002-06-09'
),(
4
,
'2002-06-09'
);
select
u
.
gender
as
gender
,
count
(
distinct
u
.
id
)
as
dist_count
,
(
count
(
distinct
u
.
id
)
/
5
*
100
)
as
percentage
from
t1
u
,
t2
l
where
l
.
user_id
=
u
.
id
group
by
u
.
gender
;
select
u
.
gender
as
gender
,
count
(
distinct
u
.
id
)
as
dist_count
,
(
count
(
distinct
u
.
id
)
/
5
*
100
)
as
percentage
from
t1
u
,
t2
l
where
l
.
user_id
=
u
.
id
group
by
u
.
gender
order
by
percentage
;
drop
table
t1
,
t2
;
sql/sql_parse.cc
View file @
2c274c64
...
...
@@ -2565,7 +2565,7 @@ check_table_access(THD *thd,uint want_access,TABLE_LIST *tables,
}
}
else
if
(
check_access
(
thd
,
want_access
,
tables
->
db
,
&
tables
->
grant
.
privilege
,
0
,
no_errors
|
grant_option
))
0
,
no_errors
))
return
TRUE
;
}
if
(
grant_option
)
...
...
sql/sql_select.cc
View file @
2c274c64
...
...
@@ -135,7 +135,7 @@ static TABLE *get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables);
static
void
calc_group_buffer
(
JOIN
*
join
,
ORDER
*
group
);
static
bool
alloc_group_fields
(
JOIN
*
join
,
ORDER
*
group
);
static
bool
make_sum_func_list
(
JOIN
*
join
,
List
<
Item
>
&
fields
);
static
bool
change_to_use_tmp_fields
(
List
<
Item
>
&
func
,
bool
change
=
false
);
static
bool
change_to_use_tmp_fields
(
List
<
Item
>
&
func
);
static
bool
change_refs_to_tmp_fields
(
THD
*
thd
,
List
<
Item
>
&
func
);
static
void
init_tmptable_sum_functions
(
Item_sum
**
func
);
static
void
update_tmptable_sum_func
(
Item_sum
**
func
,
TABLE
*
tmp_table
);
...
...
@@ -788,7 +788,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
tmp_table
=
tmp_table2
;
join
.
join_tab
[
0
].
table
=
0
;
// Table is freed
if
(
change_to_use_tmp_fields
(
all_fields
,
true
))
// No sum funcs anymore
if
(
change_to_use_tmp_fields
(
all_fields
))
// No sum funcs anymore
goto
err
;
join
.
tmp_table_param
.
field_count
+=
join
.
tmp_table_param
.
sum_func_count
;
join
.
tmp_table_param
.
sum_func_count
=
0
;
...
...
@@ -3676,7 +3676,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if
(
blob_count
==
0
)
{
/* We need to ensure that first byte is not 0 for the delete link */
if
(
hidden_null
_count
)
if
(
param
->
hidden_field
_count
)
hidden_null_count
++
;
else
null_count
++
;
...
...
@@ -6764,7 +6764,7 @@ make_sum_func_list(JOIN *join,List<Item> &fields)
*/
static
bool
change_to_use_tmp_fields
(
List
<
Item
>
&
items
,
bool
change
)
change_to_use_tmp_fields
(
List
<
Item
>
&
items
)
{
List_iterator
<
Item
>
it
(
items
);
Item
*
item_field
,
*
item
;
...
...
@@ -6776,11 +6776,6 @@ change_to_use_tmp_fields(List<Item> &items, bool change)
continue
;
if
(
item
->
type
()
==
Item
::
FIELD_ITEM
)
{
if
(
change
)
{
((
Item_field
*
)
item
)
->
result_field
->
null_ptr
=
0
;
item
->
maybe_null
=
0
;
}
((
Item_field
*
)
item
)
->
field
=
((
Item_field
*
)
item
)
->
result_field
;
}
...
...
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