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

infoschema: update raw args to make it drop correct table in RENAME TABLE #44585

Merged
merged 4 commits into from
Jun 12, 2023

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Jun 12, 2023

What problem does this PR solve?

Issue Number: close #43714

Problem Summary:

Reproducible step:

create table test.t1 (id int primary key,a text);
insert test.t1 values(1,'334'),(4,'3443435'),(5,'fdf43t536653');
rename table test.t1 to mysql.t1;
SELECT * FROM information_schema.TABLES WHERE (TABLE_SCHEMA = 'mysql') AND (TABLE_NAME = 't1');

#43341 changes the behavior of RENAME TABLE: it takes two schema versions to complete. However, applyDiff() doesn't handle two SchemaDiffs properly. The same table is created twice in infoschema, causing the phantom described in #43714.

What is changed and how it works?

During applying schema diff, we check if the table already exists before creating a new table. Thus, we can skip the second creation.

Other alternative fixes include

  • Drop the table first and then create a new table(like what CREATE TABLE with foreign key does).
    • Change job.Args at second step, so that it contains the new schema ID.
    • There are risks if we change job.Args, it is hard to guarantee all the components that relying on this work correctly.
  • Check if the old table is dropped. If it is not found, skip creating the second table.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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.

None

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Jun 12, 2023
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 12, 2023
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 12, 2023
@Ivy-YinSu
Copy link

/retest-required

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 12, 2023
@tangenta tangenta changed the title infoschema: only apply create table if not exists infoschema: update raw args to make it drop correct table in RENAME TABLE Jun 12, 2023
@@ -1177,10 +1178,17 @@ func finishJobRenameTable(d *ddlCtx, t *meta.Meta, job *model.Job) (int64, error
job.State = model.JobStateCancelled
return 0, errors.Trace(err)
}
oldRawArgs := job.RawArgs
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add comments for this logic?

@@ -1177,10 +1178,17 @@ func finishJobRenameTable(d *ddlCtx, t *meta.Meta, job *model.Job) (int64, error
job.State = model.JobStateCancelled
return 0, errors.Trace(err)
}
oldRawArgs := job.RawArgs
job.Args[0] = job.SchemaID
Copy link
Contributor

@zimulala zimulala Jun 12, 2023

Choose a reason for hiding this comment

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

I feel that the effect of create table in apply is diff.TableID why do we update job.SchemaID?
It can make drop the created table in the first apply.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 12, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Jun 12, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crazycs520, zimulala

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:
  • OWNERS [crazycs520,zimulala]

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

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 12, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 12, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-12 08:54:32.259405369 +0000 UTC m=+142621.714166671: ☑️ agreed by crazycs520.
  • 2023-06-12 09:01:53.019202897 +0000 UTC m=+143062.473964201: ☑️ agreed by zimulala.
  • 2023-06-12 10:18:56.687779941 +0000 UTC m=+147686.142541231: ✖️🔁 reset by tangenta.
  • 2023-06-12 11:21:27.393271978 +0000 UTC m=+151436.848033278: ☑️ agreed by zimulala.
  • 2023-06-12 11:26:47.211179873 +0000 UTC m=+151756.665941175: ☑️ agreed by crazycs520.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #44594.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 12, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #44595.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 12, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Jun 12, 2023
ti-chi-bot bot pushed a commit that referenced this pull request Jun 14, 2023
@tangenta tangenta added the needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. label Jun 29, 2023
@tangenta
Copy link
Contributor Author

/run-cherry-picker

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.1: #45056.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jun 29, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deleted system table still can be get from information_schema
5 participants