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

support multi-schema-change for drop index #20

Merged
merged 2 commits into from
Mar 14, 2022

Conversation

tangenta
Copy link
Owner

@tangenta tangenta commented Mar 11, 2022

What problem does this PR solve?

Issue Number: close #21

Problem Summary:

What is changed and how it works?

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

None

// Move all the dependent hidden columns to the end.
endOffset := len(tblInfo.Columns) - 1
for _, offset := range hiddenColOffs {
tblInfo.MoveColumnInfo(offset, endOffset)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
tblInfo.MoveColumnInfo(offset, endOffset)
tblInfo.MoveColumnInfo(offset, endOffset)
endOffset--

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think the order does not matter, because the columns will be removed anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It will reduce the number of exchanges

@@ -217,6 +217,9 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
}

func locateOffsetForColumn(pos *ast.ColumnPosition, tblInfo *model.TableInfo) (offset int, err error) {
if pos == nil {
return -1, nil
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

locateOffsetForColumn is also used by AddColumn so the pos can be null.

@@ -362,7 +365,7 @@ func onAddColumns(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error
case model.StateWriteReorganization:
// reorganization -> public
// Adjust table column offsets.
for i, newCol := range tblInfo.Columns[:len(tblInfo.Columns)-len(positions)] {
for i, newCol := range tblInfo.Columns[len(tblInfo.Columns)-len(positions):] {
Copy link
Owner Author

@tangenta tangenta Mar 14, 2022

Choose a reason for hiding this comment

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

Added test in TestMultiSchemaChangeAddColumns:

create table t (a int, b int, c int);
alter table t add column (d int default 4, e int default 5);

@Defined2014 Defined2014 merged commit bd47071 into multi-schema-change Mar 14, 2022
tangenta added a commit that referenced this pull request Aug 22, 2022
tangenta pushed a commit that referenced this pull request Jul 17, 2023
make system variables take effects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support multi-schema change for drop index
2 participants