Skip to content

row count estimation on DATETIME type is over-estimated when time span across years/months #50080

Open
@pcqz

Description

@pcqz

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

test.zip

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

Metadata

Metadata

Labels

affects-7.1This bug affects the 7.1.x(LTS) versions.found/gsfound by gssig/plannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions