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
31373e00
Commit
31373e00
authored
Aug 23, 2006
by
timour/timka@lamia.home
Browse files
Options
Browse Files
Download
Plain Diff
Merge lamia.home:/home/timka/mysql/src/4.1-virgin
into lamia.home:/home/timka/mysql/src/4.1-bug-21456
parents
6f16cb37
de723f29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
30 deletions
+52
-30
mysql-test/r/distinct.result
mysql-test/r/distinct.result
+11
-0
mysql-test/t/distinct.test
mysql-test/t/distinct.test
+11
-0
sql/sql_select.cc
sql/sql_select.cc
+30
-30
No files found.
mysql-test/r/distinct.result
View file @
31373e00
...
...
@@ -555,3 +555,14 @@ EXPLAIN SELECT DISTINCT a,b,d FROM t2 GROUP BY c,b,d;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3
DROP TABLE t1,t2;
CREATE TABLE t1 (a int primary key, b int);
INSERT INTO t1 (a,b) values (1,1), (2,3), (3,2);
explain SELECT DISTINCT a, b FROM t1 ORDER BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
SELECT DISTINCT a, b FROM t1 ORDER BY b;
a b
1 1
3 2
2 3
DROP TABLE t1;
mysql-test/t/distinct.test
View file @
31373e00
...
...
@@ -378,4 +378,15 @@ EXPLAIN SELECT DISTINCT a,b,d FROM t2 GROUP BY c,b,d;
DROP
TABLE
t1
,
t2
;
#
# Bug 21456: SELECT DISTINCT(x) produces incorrect results when using order by
#
CREATE
TABLE
t1
(
a
int
primary
key
,
b
int
);
INSERT
INTO
t1
(
a
,
b
)
values
(
1
,
1
),
(
2
,
3
),
(
3
,
2
);
explain
SELECT
DISTINCT
a
,
b
FROM
t1
ORDER
BY
b
;
SELECT
DISTINCT
a
,
b
FROM
t1
ORDER
BY
b
;
DROP
TABLE
t1
;
# End of 4.1 tests
sql/sql_select.cc
View file @
31373e00
...
...
@@ -648,6 +648,36 @@ JOIN::optimize()
if
(
!
order
&&
org_order
)
skip_sort_order
=
1
;
}
/*
Check if we can optimize away GROUP BY/DISTINCT.
We can do that if there are no aggregate functions and the
fields in DISTINCT clause (if present) and/or columns in GROUP BY
(if present) contain direct references to all key parts of
an unique index (in whatever order).
Note that the unique keys for DISTINCT and GROUP BY should not
be the same (as long as they are unique).
The FROM clause must contain a single non-constant table.
*/
if
(
tables
-
const_tables
==
1
&&
(
group_list
||
select_distinct
)
&&
!
tmp_table_param
.
sum_func_count
)
{
if
(
group_list
&&
list_contains_unique_index
(
join_tab
[
const_tables
].
table
,
find_field_in_order_list
,
(
void
*
)
group_list
))
{
group_list
=
0
;
group
=
0
;
}
if
(
select_distinct
&&
list_contains_unique_index
(
join_tab
[
const_tables
].
table
,
find_field_in_item_list
,
(
void
*
)
&
fields_list
))
{
select_distinct
=
0
;
}
}
if
(
group_list
||
tmp_table_param
.
sum_func_count
)
{
if
(
!
hidden_group_fields
&&
rollup
.
state
==
ROLLUP
::
STATE_NONE
)
...
...
@@ -717,36 +747,6 @@ JOIN::optimize()
if
(
old_group_list
&&
!
group_list
)
select_distinct
=
0
;
}
/*
Check if we can optimize away GROUP BY/DISTINCT.
We can do that if there are no aggregate functions and the
fields in DISTINCT clause (if present) and/or columns in GROUP BY
(if present) contain direct references to all key parts of
an unique index (in whatever order).
Note that the unique keys for DISTINCT and GROUP BY should not
be the same (as long as they are unique).
The FROM clause must contain a single non-constant table.
*/
if
(
tables
-
const_tables
==
1
&&
(
group_list
||
select_distinct
)
&&
!
tmp_table_param
.
sum_func_count
)
{
if
(
group_list
&&
list_contains_unique_index
(
join_tab
[
const_tables
].
table
,
find_field_in_order_list
,
(
void
*
)
group_list
))
{
group_list
=
0
;
group
=
0
;
}
if
(
select_distinct
&&
list_contains_unique_index
(
join_tab
[
const_tables
].
table
,
find_field_in_item_list
,
(
void
*
)
&
fields_list
))
{
select_distinct
=
0
;
}
}
if
(
!
group_list
&&
group
)
{
order
=
0
;
// The output has only one row
...
...
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