Loading mysql-test/r/order_by.result +22 −0 Original line number Diff line number Diff line Loading @@ -958,3 +958,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; mysql-test/t/order_by.test +15 −0 Original line number Diff line number Diff line Loading @@ -677,3 +677,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; sql/filesort.cc +4 −1 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
mysql-test/r/order_by.result +22 −0 Original line number Diff line number Diff line Loading @@ -958,3 +958,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;
mysql-test/t/order_by.test +15 −0 Original line number Diff line number Diff line Loading @@ -677,3 +677,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;
sql/filesort.cc +4 −1 Original line number Diff line number Diff line Loading @@ -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); Loading