-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ANALYZE TABLE immediately after bulk update is unreliable #16570
Comments
I'm sorry, I can not reproduce this issue. Here is my test step:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
id BIGINT NOT NULL PRIMARY KEY auto_increment,
b BIGINT NOT NULL,
pad VARBINARY(255),
INDEX (b)
);
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM dual;
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM t1 a INNER JOIN t1 b INNER JOIN t1 c LIMIT 10000;
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM t1 a INNER JOIN t1 b INNER JOIN t1 c LIMIT 10000;
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM t1 a INNER JOIN t1 b INNER JOIN t1 c LIMIT 10000;
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM t1 a INNER JOIN t1 b INNER JOIN t1 c LIMIT 10000;
INSERT INTO t1 SELECT NULL, 1, RANDOM_BYTES(255) FROM t1 a INNER JOIN t1 b INNER JOIN t1 c LIMIT 10000;
UPDATE t1 SET b=id;
ANALYZE TABLE t1;
EXPLAIN ANALYZE SELECT * FROM t1 WHERE b < 5;
The execution plan is not the same as the issue described. @wwar Could you provide a detailed reproduce step to help us locate the root cause? |
I cannot reproduce with mocktikv as the store. Could that be the issue? I am using the default configuration, with a single tikv server which is local (tikv + pd are from nightly, tidb-server I have tried both master and nightly):
Version of tidb-server:
|
Thanks @wwar, I reproduced this issue with tikv as well:
I got this output:
|
It looks like a bug in tikv coprocessor. I turned off auto-analyze, statistics feedback, and increased the stats-lease to 100s, the problem can still be reproduced. I added some debugging logs in @breeswish can you please check if it is the bug in |
Sorry currently I'm not very familiar with the Analyze part of the Coprocessor, since it is maintained by TiDB member previously 🤣I can help check whether Coprocessor Analyze successfully scanned recently data (but cannot help check what happens next). Does it help? |
I've confirmed that indeed Analyze did not scanned latest data, although received max_ts. I will ask txn member to look at this issue. |
@breeswish thanks, it helps |
Confirming this is fixed:
Note: This is a case where it would have really helped if tikv version was included in |
The root cause of the problem is that in tikv 4.0, commit of secondary lock is in asynchronous way, and |
I tested this again after your comment, and it is indeed not fixed (due to a race). May I suggest documenting the maximum delay that is expected until |
From the investigation result:
@wwar What's the time period between your bulk insert and analyze operation? |
In my case, I know of this issue and I will probably just use a My suggestion was to update the docs to make this clearer. i.e. on https://pingcap.com/docs/stable/reference/sql/statements/analyze-table/ under "MySQL Compatibility" it says:
This should be updated to mention both this issue and
|
pingcap/docs#3151 has updated the documentation, so I am going to close this issue. |
Please edit this comment or add a new comment to complete the following informationNot a bug
Duplicate bug
BugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA) (optional)2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)5. Affected versions6. Fixed versions |
Bug Report
1. What did you do?
After I bulk updated rows, I ran
ANALYZE TABLE
. TheANALYZE
did not take into account the recent update, and statistics remained out of date.This appears to be a race condition. Consider the following:
If you remove the
SLEEP(5)
you will get incorrect statistics.2. What did you expect to see?
With the sleep call:
3. What did you see instead?
Without the sleep call:
4. What version of TiDB are you using? (
tidb-server -V
or runselect tidb_version();
on TiDB)The text was updated successfully, but these errors were encountered: