Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The estRows is wrong if SQL is executed multiple times #53119

Open
yedushusheng opened this issue May 9, 2024 · 1 comment
Open

The estRows is wrong if SQL is executed multiple times #53119

yedushusheng opened this issue May 9, 2024 · 1 comment

Comments

@yedushusheng
Copy link

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

@yedushusheng yedushusheng added the type/bug This issue is a bug. label May 9, 2024
@yedushusheng yedushusheng changed the title The estRows is wrong if SQL is executed in a different order The estRows is wrong if SQL is executed multiple times May 9, 2024
@qw4990 qw4990 added the epic/cardinality-estimation the optimizer cardinality estimation label May 16, 2024
@qw4990
Copy link
Contributor

qw4990 commented May 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants