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

Data may be lost when changing column type with tidb_enable_amend_pessimistic_txn=on. #26203

Closed
wjhuang2016 opened this issue Jul 13, 2021 · 4 comments · Fixed by #26269
Closed
Assignees
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set global tidb_enable_amend_pessimistic_txn=ON;
CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
  `b` int(11) DEFAULT NULL
);

insert into t many rows (about 1 000 000)

                                    /* txn */ begin pessimistic;
                                    /* txn */ insert into t values (52000002, 502);
/* DDL */ alter table t change column b b smallint;
                                    /* txn  during DDL */  commit;
/* DDL */ finish DDL
mysql> select * from t where a=52000002;
+----------+------+
| a        | b    |
+----------+------+
| 52000002 | NULL |
+----------+------+
1 row in set (0.00 sec)

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

mysql> select * from t where a=52000002;
+----------+------+
| a        | b    |
+----------+------+
| 52000002 | 502  |
+----------+------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

NULL

4. What is your TiDB version? (Required)

master

@wjhuang2016 wjhuang2016 added the type/bug The issue is confirmed as a bug. label Jul 13, 2021
@bb7133 bb7133 changed the title change column type with tidb_enable_amend_pessimistic_txn=on may lost data Data may be lost when changing column type with tidb_enable_amend_pessimistic_txn=on. Jul 13, 2021
@cfzjywxk
Copy link
Contributor

@wjhuang2016
The current implementation of transaction amend is not compatible with column type change, in the earlier versions the column type is only allowed to be changed to certain types which does not need data reorgnization, but now the assumption is not true. It's needed to add rejection logic at https://github.com/pingcap/tidb/blob/master/session/schema_amender.go#L163.Also some compatibility test case are needed to verify the rejection.

@cfzjywxk
Copy link
Contributor

Seems the column id is also needed to be checked to ensure only field length is increased and other changes will be rejected.

@zimulala zimulala self-assigned this Jul 14, 2021
@zimulala
Copy link
Contributor

zimulala commented Jul 14, 2021

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
5 participants