在 4.0.12 上面没有复现你说的这个问题,麻烦贴下 select tidb_version() 和复现过程吧。
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.12
Edition: Community
Git Commit Hash: 11a9254bec522c1991033a6098f6dccadc6eb7c1
Git Branch: HEAD
UTC Build Time: 2021-04-16 05:40:45
GoVersion: go1.15.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
mysql>
mysql>
mysql> SELECT * FROM (SELECT *,ROW_NUMBER() over(PARTITION BY user_id order BY leave_end_time DESC) r FROM base_user_leave )t WHERE r = 1 AND leave_status in (0,1) and IS_DELETED = '0';
Empty set (0.00 sec)