-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ddl:support alter table drop partition #6460
Changes from all commits
83450d7
1358251
41a420f
a1cec0e
63b5e74
d175ea5
7edcb1b
f571a49
1b0f57c
553faa3
b6f117d
e493083
0708ecd
6e524b0
0c86c04
63fc315
3e856ab
ef9063c
cf97e71
8ce934c
b0f421c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -976,6 +976,8 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A | |
err = d.DropColumn(ctx, ident, spec.OldColumnName.Name) | ||
case ast.AlterTableDropIndex: | ||
err = d.DropIndex(ctx, ident, model.NewCIStr(spec.Name)) | ||
case ast.AlterTableDropPartition: | ||
err = d.DropTablePartition(ctx, ident, spec) | ||
case ast.AlterTableAddConstraint: | ||
constr := spec.Constraint | ||
switch spec.Constraint.Tp { | ||
|
@@ -1211,7 +1213,7 @@ func (d *ddl) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, spec * | |
} | ||
|
||
meta := t.Meta() | ||
if meta.GetPartitionInfo() == nil && meta.Partition == nil { | ||
if meta.GetPartitionInfo() == nil { | ||
return errors.Trace(ErrPartitionMgmtOnNonpartitioned) | ||
} | ||
partInfo, err := buildPartitionInfo(meta, d, spec) | ||
|
@@ -1242,6 +1244,41 @@ func (d *ddl) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, spec * | |
return errors.Trace(err) | ||
} | ||
|
||
func (d *ddl) DropTablePartition(ctx sessionctx.Context, ident ast.Ident, spec *ast.AlterTableSpec) error { | ||
is := d.infoHandle.Get() | ||
schema, ok := is.SchemaByName(ident.Schema) | ||
if !ok { | ||
return errors.Trace(infoschema.ErrDatabaseNotExists.GenByArgs(schema)) | ||
} | ||
t, err := is.TableByName(ident.Schema, ident.Name) | ||
if err != nil { | ||
return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name)) | ||
} | ||
meta := t.Meta() | ||
if meta.GetPartitionInfo() == nil { | ||
return errors.Trace(ErrPartitionMgmtOnNonpartitioned) | ||
} | ||
err = checkDropTablePartition(meta, spec.Name) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
job := &model.Job{ | ||
SchemaID: schema.ID, | ||
TableID: meta.ID, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the tableID or partitionID? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the |
||
Type: model.ActionDropTablePartition, | ||
BinlogInfo: &model.HistoryInfo{}, | ||
Args: []interface{}{spec.Name}, | ||
} | ||
|
||
err = d.doDDLJob(ctx, job) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check this error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
err = d.callHookOnChanged(err) | ||
return errors.Trace(err) | ||
} | ||
|
||
// DropColumn will drop a column from the table, now we don't support drop the column with index covered. | ||
func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, colName model.CIStr) error { | ||
is := d.GetInformationSchema(ctx) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a key for
purchased
? And check the index rows.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zimulala Need to wait for this
PR
#6814 to complete before adding it.