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
10fedf67
Commit
10fedf67
authored
Jun 10, 2011
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change test_if_equality_guarantees_uniqueness()
from an ad hoc set of limitations to a correct rule
parent
fdfeb4be
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
17 deletions
+58
-17
mysql-test/r/distinct.result
mysql-test/r/distinct.result
+26
-0
mysql-test/t/distinct.test
mysql-test/t/distinct.test
+19
-0
sql/sql_select.cc
sql/sql_select.cc
+13
-17
No files found.
mysql-test/r/distinct.result
View file @
10fedf67
...
...
@@ -804,6 +804,32 @@ select distinct a from t1 where a = DATE('2010-10-10');
a
2010-10-10
20101010
explain select distinct a from t1 where a = DATE('2010-10-10');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary
drop table t1;
# date = string
create table t1 (a date);
insert t1 values ('2010-10-10'), ('20101010');
explain select distinct a from t1 where a = '2010-10-10';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
drop table t1;
# double = string
create table t1 (a double);
insert t1 values (2), (2);
explain select distinct a from t1 where a = '2';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
# double = int
explain select distinct a from t1 where a = 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
# string = double
alter table t1 modify a varchar(100);
explain select distinct a from t1 where a = 2e0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary
drop table t1;
create table t1 (f1 varchar(40));
insert into t1 values ('2010-10-10 00:00:00.0001'),('2010-10-10 00:00:00.0002'),('2010-10-10 00:00:00.0003');
...
...
mysql-test/t/distinct.test
View file @
10fedf67
...
...
@@ -622,6 +622,25 @@ create table t1 (a varchar(100));
insert
t1
values
(
'2010-10-10'
),
(
'20101010'
);
select
*
from
t1
where
a
=
DATE
(
'2010-10-10'
);
select
distinct
a
from
t1
where
a
=
DATE
(
'2010-10-10'
);
explain
select
distinct
a
from
t1
where
a
=
DATE
(
'2010-10-10'
);
drop
table
t1
;
#
# test_if_equality_guarantees_uniqueness() and different type combinations
#
--
echo
# date = string
create
table
t1
(
a
date
);
insert
t1
values
(
'2010-10-10'
),
(
'20101010'
);
explain
select
distinct
a
from
t1
where
a
=
'2010-10-10'
;
drop
table
t1
;
--
echo
# double = string
create
table
t1
(
a
double
);
insert
t1
values
(
2
),
(
2
);
explain
select
distinct
a
from
t1
where
a
=
'2'
;
--
echo
# double = int
explain
select
distinct
a
from
t1
where
a
=
2
;
--
echo
# string = double
alter
table
t1
modify
a
varchar
(
100
);
explain
select
distinct
a
from
t1
where
a
=
2
e0
;
drop
table
t1
;
#
...
...
sql/sql_select.cc
View file @
10fedf67
...
...
@@ -12171,15 +12171,15 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
Checks if an equality predicate can be used to take away
DISTINCT/GROUP BY because it is known to be true for exactly one
distinct value (e.g. <expr> == <const>).
Arguments must be
of the same type because e.g.
<string_field> = <int_const> may match more than 1 distinct value from
the column.
Additionally, strings must have the same collation.
Or the *field* must be a datetime - if the constant is a datetime
and a field is not - this is not enough, consider:
create table t1 (a varchar(100));
insert t1 values ('2010-01-02'), ('2010-1-2'), ('20100102');
select distinct t1 from t1 where a=date('2010-01-02');
Arguments must be
compared in the native type of the left argument
and (for strings) in the native collation of the left argument.
Otherwise, for example,
<string_field> = <int_const> may match more than 1 distinct value or
the <string_field>.
@note We don't need to aggregate l and r collations here, because r -
the constant item - has already been converted to a proper collation
for comparison. We only need to compare this collation with field's collation.
@retval true can be used
@retval false cannot be used
...
...
@@ -12188,13 +12188,9 @@ static bool
test_if_equality_guarantees_uniqueness
(
Item
*
l
,
Item
*
r
)
{
return
r
->
const_item
()
&&
/* the field is a date (the const will be converted to a date) */
(
l
->
cmp_type
()
==
TIME_RESULT
||
/* or arguments are of the same result type */
(
r
->
result_type
()
==
l
->
result_type
()
&&
/* and must have the same collation if compared as strings */
(
l
->
result_type
()
!=
STRING_RESULT
||
l
->
collation
.
collation
==
r
->
collation
.
collation
)));
item_cmp_type
(
l
->
cmp_type
(),
r
->
cmp_type
())
==
l
->
cmp_type
()
&&
(
l
->
cmp_type
()
!=
STRING_RESULT
||
l
->
collation
.
collation
==
r
->
collation
.
collation
);
}
/**
...
...
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