Bug #95020 select no rows return but check profile process Creating sort index
Submitted: 15 Apr 10:11 Modified: 23 Apr 15:11
Reporter: cui jacky Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S5 (Performance)
Version:5.7.25 OS:CentOS
Assigned to: CPU Architecture:Any
Tags: Creating sort index

[15 Apr 10:11] cui jacky
Description:
excute query statements: 
   select *from t1 where  task_statu=0 order by create_time 

result: There is no suitable result , no rows return

use  profiling find “Creating sort index”

i think this a bug;

when no data have ,profiling no have "Creating sort index" 

How to repeat:
mysql>CREATE TABLE `t1` (
  `id` int(11) primary key,
  `task_statu` int(11) DEFAULT NULL,
  `create_time` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

mysql>INSERT INTO T1(id,task_statu,create_time) values(1,2,now()),(2,3,now()),(3,4,now());

mysql> set global profiling = 1;
mysql> show profiles;

mysql> select *from t1 where  task_statu=0 order by create_time;
Empty set (0.00 sec)

mysql> show profile for query 21;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000093 |
| checking permissions | 0.000007 |
| Opening tables       | 0.000019 |
| init                 | 0.000052 |
| System lock          | 0.000013 |
| optimizing           | 0.000012 |
| statistics           | 0.000020 |
| preparing            | 0.000012 |
| Sorting result       | 0.000005 |
| executing            | 0.000002 |
| Sending data         | 0.000008 |
| Creating sort index  | 0.000053 |
| end                  | 0.000003 |
| query end            | 0.000008 |
| closing tables       | 0.000009 |
| freeing items        | 0.000021 |
| cleaning up          | 0.000012 |
+----------------------+----------+
17 rows in set, 1 warning (0.00 sec)

Suggested fix:
sql\filresort.cc first step add some of  things 
if don't have data ,not excuter process
[23 Apr 15:11] Bogdan Kecman
Hi,

Thanks for the report. I'm not 100% sure this is a bug but it is reproducible behavior so I'll let optimizer team decide how to handle it. In any way it is not S3 bug but a performance issue so S5

thanks
bogdan