row count estimation on DATETIME type is over-estimated when time span across years/months #50080
Open
Description
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
use test;
source test.sql;
load stats 'test.json';
explain select * from test where updated_date > '2023-12-31 23:40:00' and updated_date<'2023-12-31 23:50:00';
explain select * from test where updated_date > '2023-12-31 23:50:00' and updated_date<'2024-01-01 00:00:00';
2. What did you expect to see? (Required)
mysql> explain select * from test where updated_date > '2023-12-31 23:40:00' and updated_date<'2023-12-31 23:50:00';
+-------------------------------+---------+-----------+---------------------------------------------------+-------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------------+---------+-----------+---------------------------------------------------+-------------------------------------------------------------------+
| IndexLookUp_7 | 1382.13 | root | | |
| ├─IndexRangeScan_5(Build) | 1382.13 | cop[tikv] | table:test, index:IX_CUST_RELA_DATE(updated_date) | range:(2023-12-31 23:40:00,2023-12-31 23:50:00), keep order:false |
| └─TableRowIDScan_6(Probe) | 1382.13 | cop[tikv] | table:test | keep order:false |
+-------------------------------+---------+-----------+---------------------------------------------------+-------------------------------------------------------------------+
3 rows in set (0.00 sec)
3. What did you see instead (Required)
mysql> explain select * from test where updated_date > '2023-12-31 23:50:00' and updated_date<'2024-01-01 00:00:00';
+-------------------------------+------------+-----------+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------------+------------+-----------+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| IndexLookUp_10 | 9355819.67 | root | | |
| ├─IndexRangeScan_8(Build) | 9355819.67 | cop[tikv] | table:test, index:IX_CUST_RELA_DATE(updated_date) | range:(2023-12-31 23:50:00,2024-01-01 00:00:00), keep order:false, stats:partial[ix_tpcnr_bcn:allEvicted, ix_tpcnr_epn:allEvicted, ix_tpcnr_pan:allEvicted...(more: 1 allEvicted)] |
| └─TableRowIDScan_9(Probe) | 9355819.67 | cop[tikv] | table:test | keep order:false, stats:partial[ix_tpcnr_bcn:allEvicted, ix_tpcnr_epn:allEvicted, ix_tpcnr_pan:allEvicted...(more: 1 allEvicted)] |
+-------------------------------+------------+-----------+---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.01 sec)
4. What is your TiDB version? (Required)
v6.5.3
Activity