pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/

Home Page:https://pingcap.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The estRows is wrong if SQL is executed multiple times

yedushusheng opened this issue · comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. create table:
    CREATE TABLE tb (
    id int(11) NOT NULL,
    f1 int(11) DEFAULT NULL,
    f2 int(11) DEFAULT NULL,
    f3 int(11) DEFAULT NULL,
    PRIMARY KEY (id),
    KEY idx_f1 (f1) ,
    KEY idx_f2 (f2)
    ) partition by hash(id)
    (partition p0,
    partition p1,
    partition p2);
  2. insert data:
    insert into tb (id,f1,f2,f3) values(1,1,1,1),(2,2,2,2) ......(1000,1000,1000,1000);
    insert into tb (id,f1,f2,f3) values(10000,10000,10000,10000),(20000,20000,20000,20000);
  3. analyze table:
    analyze table tb;
  4. Query
    Execute the following Query first time:
    image
    the estRows of Query 'select * from tb where f2>=1000 and f2<=2000' is right.
    Then execute the same Querys again:
    image
    the estRows of Query 'select * from tb where f2>=1000 and f2<=2000' deviates greatly from the previous one.
    Why is there such a large estimation error?

2. What did you expect to see? (Required)

If we execute the same query multiple times, without new DML operation, estRows should be the same
image

3. What did you see instead (Required)

image

4. What is your TiDB version? (Required)

pd instance:v8.0.0
tikv instance:v8.0.0
tidb instance:v8.0.0
tiflash instance:v8.0.0

Degrade this issue to moderate since it doesn't affect the result directly.