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

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

Closed
xuyifangreeneyes opened this issue Apr 25, 2023 · 2 comments · Fixed by #43381
Closed

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

xuyifangreeneyes opened this issue Apr 25, 2023 · 2 comments · Fixed by #43381

Comments

@xuyifangreeneyes
Copy link
Contributor

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

@xuyifangreeneyes xuyifangreeneyes added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner component/statistics affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 severity/major labels Apr 25, 2023
@winoros
Copy link
Member

winoros commented Apr 25, 2023

The behavior affects a lot. But we only want to solve problem with TiDB no less than 7.1-LTS

@winoros
Copy link
Member

winoros commented Apr 26, 2023

We decide to port the config setting to v6.5.
But you need to remember that v6.5's statistics initialization can be pretty long. If you open the setting, TiDB may need to wait for a long time between its startup and the time it's ready to provide service.

@winoros winoros removed affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 labels Apr 26, 2023
ti-chi-bot bot pushed a commit that referenced this issue Apr 26, 2023
ti-chi-bot bot pushed a commit that referenced this issue May 4, 2023
ti-chi-bot bot pushed a commit that referenced this issue Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants