Skip to content

optimizer may make bad decisions due to pseudo stats during init stats #43385

@xuyifangreeneyes

Description

@xuyifangreeneyes

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Here is a small example to demonstrate the issue.

I add time.Sleep(20 * time.Minute) into (*Handle).InitStats to simulate slow init stats.

mysql> create table t1(a int, b int, index idx(a));
Query OK, 0 rows affected (0.02 sec)

-- insert data into t1

mysql> analyze table t1;
Query OK, 0 rows affected, 1 warning (0.05 sec)

Then restart the tidb-server.

mysql> explain select * from t1 where a > 1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 3333.33  | root      |               | data:Selection_6               |
| └─Selection_6           | 3333.33  | cop[tikv] |               | gt(test.t1.a, 1)               |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> show stats_meta;
Empty set (0.00 sec)

mysql> show stats_histograms;
Empty set (0.00 sec)

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

We hope the optimizer avoids using pseudo stats to make decisions. For example, tidb can choose to wait for init stats to finish before providing service.

3. What did you see instead (Required)

The optimizer uses pseudo stats during init stats, which may lead to bad plans.

4. What is your TiDB version? (Required)

master

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions