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

admin recover index miss some rows #32915

Closed
3pointer opened this issue Mar 8, 2022 · 3 comments · Fixed by #32960
Closed

admin recover index miss some rows #32915

3pointer opened this issue Mar 8, 2022 · 3 comments · Fixed by #32960
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@3pointer
Copy link
Contributor

3pointer commented Mar 8, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

MySQL [test]>  create table t(id bigint(20) primary key, col varchar(255) unique key);
Query OK, 0 rows affected (0.10 sec)

MySQL [test]> insert into t values(9223372036854775807, "test");
Query OK, 1 row affected (0.01 sec)

MySQL [test]> admin recover index t col;
+-------------+------------+
| ADDED_COUNT | SCAN_COUNT |
+-------------+------------+
|           0 |          0 |
+-------------+------------+
1 row in set (0.00 sec)

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

SCAN_COUNT should be 1.

3. What did you see instead (Required)

截屏2022-03-08 下午6 12 22

### 4. What is your TiDB version? (Required)

master

@3pointer 3pointer added the type/bug The issue is confirmed as a bug. label Mar 8, 2022
@3pointer
Copy link
Contributor Author

3pointer commented Mar 8, 2022

The root cause is here.
codec.EncodeKey(sctx, nil, types.MaxValueDatum() is the byte 250 which is not the unlimited end key.

For intHandle it should becodec.EncodeInt(nil, math.MaxInt64)

@wjhuang2016
Copy link
Member

The root cause is here. codec.EncodeKey(sctx, nil, types.MaxValueDatum() is the byte 250 which is not the unlimited end key.

For intHandle it should becodec.EncodeInt(nil, math.MaxInt64)

250 is fine, since we compare data by its prefix.
The problem is that in our implementation:

// 1. unique-key is duplicate and the handle is equal, skip it.
// 2. unique-key is duplicate and the handle is not equal, data is not consistent, log it and skip it.
// 3. non-unique-key is duplicate, skip it.

According to "unique-key is duplicate and the handle is equal, skip it.", the scan row is skipped. We don't count for that.
It's not a bug, but I still think we can improve it.

@3pointer
Copy link
Contributor Author

3pointer commented Mar 9, 2022

The root cause is here. codec.EncodeKey(sctx, nil, types.MaxValueDatum() is the byte 250 which is not the unlimited end key.
For intHandle it should becodec.EncodeInt(nil, math.MaxInt64)

250 is fine, since we compare data by its prefix. The problem is that in our implementation:

// 1. unique-key is duplicate and the handle is equal, skip it.
// 2. unique-key is duplicate and the handle is not equal, data is not consistent, log it and skip it.
// 3. non-unique-key is duplicate, skip it.

According to "unique-key is duplicate and the handle is equal, skip it.", the scan row is skipped. We don't count for that. It's not a bug, but I still think we can improve it.

I don't think so.
the scanRowCount has been added in fetchRecoverRows

result.scanRowCount++

whether skip or not, it will be recorded.

you can try add another record and the SCAN_COUNT will be 1. (which should be 2)
image

@tangenta tangenta changed the title admin recover index lost some rows admin recover index miss some rows Mar 9, 2022
@tangenta tangenta self-assigned this Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants