Bug #26672:

 DATE/DATETIME values are out of the currently supported
 4 basic value types (INT,STRING,REAL and DECIMAL).
 So expressions (not fields) of compile type DATE/DATETIME are 
 generally considered as STRING values. This is not so
 when they are compared : then they are compared as 
 INTEGER values.
 But the rule for comparison as INTEGERS must be checked
 explicitly each time when a comparison is to be performed.
 filesort is one such place. However there the check was 
 not done and hence the expressions (not fields) of type 
 DATE/DATETIME were sorted by their string representation.
 Fixed to compare them as INTEGER values for filesort.
parent 7b77956f
......@@ -934,3 +934,25 @@ a ratio
19 1.3333
9 2.6667
drop table t1;
CREATE TABLE t1 (a INT UNSIGNED NOT NULL, b TIME);
INSERT INTO t1 (a) VALUES (100000), (0), (100), (1000000),(10000), (1000), (10);
UPDATE t1 SET b = SEC_TO_TIME(a);
SELECT a, b FROM t1 ORDER BY b DESC;
a b
1000000 277:46:40
100000 27:46:40
10000 02:46:40
1000 00:16:40
100 00:01:40
10 00:00:10
0 00:00:00
SELECT a, b FROM t1 ORDER BY SEC_TO_TIME(a) DESC;
a b
1000000 277:46:40
100000 27:46:40
10000 02:46:40
1000 00:16:40
100 00:01:40
10 00:00:10
0 00:00:00
DROP TABLE t1;
......@@ -648,3 +648,18 @@ create table t1 (a int, b int, c int);
insert into t1 values (1,2,3), (9,8,3), (19,4,3), (1,4,9);
select a,(sum(b)/sum(c)) as ratio from t1 group by a order by sum(b)/sum(c) asc;
drop table t1;
#
# Bug#26672: Incorrect SEC_TO_TIME() casting in ORDER BY
#
CREATE TABLE t1 (a INT UNSIGNED NOT NULL, b TIME);
INSERT INTO t1 (a) VALUES (100000), (0), (100), (1000000),(10000), (1000), (10);
UPDATE t1 SET b = SEC_TO_TIME(a);
-- Correct ORDER
SELECT a, b FROM t1 ORDER BY b DESC;
-- must be ordered as the above
SELECT a, b FROM t1 ORDER BY SEC_TO_TIME(a) DESC;
DROP TABLE t1;
......@@ -1298,7 +1298,10 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
}
else
{
switch ((sortorder->result_type=sortorder->item->result_type())) {
sortorder->result_type= sortorder->item->result_type();
if (sortorder->item->result_as_longlong())
sortorder->result_type= INT_RESULT;
switch (sortorder->result_type) {
case STRING_RESULT:
sortorder->length=sortorder->item->max_length;
set_if_smaller(sortorder->length, thd->variables.max_sort_length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment