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

*: fix a bug that update statement uses point get and update plan with different tblInfo (#54183) #54259

Merged

Conversation

ti-chi-bot
Copy link
Member

@ti-chi-bot ti-chi-bot commented Jun 27, 2024

This is an automated cherry-pick of #54183

What problem does this PR solve?

Issue Number: close #53634

Problem Summary:

Case

Init SQLs:

CREATE TABLE stock ( a int NOT NULL, b char(30) NOT NULL,  c int, d char(64), PRIMARY KEY(a,b)) ;
insert into stock values(1, 'a', 11, 'x'), (2, 'b', 22, 'y');
alter table stock add column cct_1 int default 10;
alter table stock modify cct_1 json;
alter table stock add column adc_1 smallint;
  • Step1. using conn1
    prepare statements:
    begin;
    SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE;
    UPDATE stock SET c = ? WHERE a= ? AND b = 'a';
    UPDATE stock SET c = ?, d = 'z' WHERE a= ? AND b = 'b';
    commit;

run a statement:
begin;

  • Step2. using conn2
    do DDL:
    alter table stock drop column cct_1;
  • Step3. using conn1
    When the DDL is in Write-Only state
    exec statements:
    SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE;
    UPDATE stock SET c = ? WHERE a= ? AND b = 'a';
    UPDATE stock SET c = ?, d = 'z' WHERE a= ? AND b = 'b';
    commit;
  • Step4. using conn1
    Check the result
    select * from stock;

  • Statement execution order table

conn1 conn2
step1. prepare stmts
step1. begin;
step2. alter table stock drop column cct_1; (state public -> write-only)
step3. exec stmts write-only
step2. alter table stock drop column cct_1; (finish)
step4. select * from stock;

Conclusion

The update statement in step3 uses point get and update plan, but the tblInfo used by the two plans is inconsistent, resulting in incorrect data in real storage.

  • After executing step3. select statement, the stock is locked in GetRelatedTableForMDL, so stmt.tbls[i].Meta().Revision != newTbl.Meta().Revision is false. It means schemaNotMatch is false. So we needn't to Preprocess.

    newTbl, err := tryLockMDLAndUpdateSchemaIfNecessary(sctx.GetPlanCtx(), stmt.dbName[i], stmt.tbls[i], is)
    if err != nil {
    schemaNotMatch = true
    continue
    }
    if stmt.tbls[i].Meta().Revision != newTbl.Meta().Revision {

  • Step3. update statement using tblName.TableInfo(get it when preparing statements, cct_1 is public) in newPointGetPlan.

    tbl := tblName.TableInfo

  • Step3. update statement using t gets from is.TableByID(tbl.ID)( cct_1 is write-only)

    updatePlan.names = pointPlan.OutputNames()
    is := ctx.GetInfoSchema().(infoschema.InfoSchema)
    t, _ := is.TableByID(tbl.ID)
    updatePlan.tblID2Table = map[int64]table.Table{
    tbl.ID: t,
    }

What changed and how does it work?

Add the Revision field comparison of tbl(get from txn infoschema) and newTbl to confirm whether reprocess is required.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix an issue where improper use of metadata locks in some scenarios could cause abnormal data to be written when using the plan cache.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added ok-to-test release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Jun 27, 2024
@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jun 27, 2024
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 26, 2024
@fzzf678
Copy link
Contributor

fzzf678 commented Aug 27, 2024

/retest

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 29, 2024
@@ -142,6 +143,119 @@ func newDefaultCallBack(do DomainReloader) Callback {

// ****************************** End of Default DDL Callback Instance *********************************************

// ****************************** Start of Test DDL Callback Instance ***********************************************
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a code move in the file, for compatibility with the current PR test call issue.

Copy link

ti-chi-bot bot commented Aug 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Defined2014, qw4990

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fzzf678
Copy link
Contributor

fzzf678 commented Sep 2, 2024

/retest

5 similar comments
@fzzf678
Copy link
Contributor

fzzf678 commented Sep 2, 2024

/retest

@fzzf678
Copy link
Contributor

fzzf678 commented Sep 2, 2024

/retest

@fzzf678
Copy link
Contributor

fzzf678 commented Sep 2, 2024

/retest

@fzzf678
Copy link
Contributor

fzzf678 commented Sep 2, 2024

/retest

@fzzf678
Copy link
Contributor

fzzf678 commented Sep 3, 2024

/retest

@zimulala
Copy link
Contributor

zimulala commented Sep 6, 2024

/test unit-test

Copy link

tiprow bot commented Sep 6, 2024

@zimulala: No presubmit jobs available for pingcap/tidb@release-6.5

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@pingcap pingcap deleted a comment from ti-chi-bot bot Sep 6, 2024
@zimulala
Copy link
Contributor

zimulala commented Sep 6, 2024

/test unit-test

Copy link

tiprow bot commented Sep 6, 2024

@zimulala: No presubmit jobs available for pingcap/tidb@release-6.5

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Benjamin2037
Copy link
Collaborator

/retest

@JaySon-Huang
Copy link
Contributor

/test unit-test

Copy link

tiprow bot commented Sep 9, 2024

@JaySon-Huang: No presubmit jobs available for pingcap/tidb@release-6.5

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@pingcap pingcap deleted a comment from ti-chi-bot bot Sep 9, 2024
@zimulala
Copy link
Contributor

zimulala commented Sep 9, 2024

/test unit-test

Copy link

tiprow bot commented Sep 9, 2024

@zimulala: No presubmit jobs available for pingcap/tidb@release-6.5

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@zimulala zimulala force-pushed the cherry-pick-54183-to-release-6.5 branch from 2dc27ab to f135206 Compare September 10, 2024 00:30
@zimulala
Copy link
Contributor

/test unit-test

Copy link

tiprow bot commented Sep 10, 2024

@zimulala: No presubmit jobs available for pingcap/tidb@release-6.5

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@pingcap pingcap deleted a comment from ti-chi-bot bot Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 53.96825% with 29 lines in your changes missing coverage. Please review.

Please upload report for BASE (release-6.5@4ffd88c). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-6.5     #54259   +/-   ##
================================================
  Coverage               ?   73.6304%           
================================================
  Files                  ?       1097           
  Lines                  ?     352812           
  Branches               ?          0           
================================================
  Hits                   ?     259777           
  Misses                 ?      76330           
  Partials               ?      16705           

@ti-chi-bot ti-chi-bot bot merged commit 996098e into pingcap:release-6.5 Sep 10, 2024
10 checks passed
@JaySon-Huang JaySon-Huang deleted the cherry-pick-54183-to-release-6.5 branch September 11, 2024 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants