Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#46343
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
jiyfhust authored and ti-chi-bot committed Oct 30, 2023
1 parent 78fc8b4 commit 17bb4b3
Show file tree
Hide file tree
Showing 4 changed files with 600 additions and 4 deletions.
7 changes: 7 additions & 0 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,17 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
dom := domain.GetDomain(e.ctx)
var job *model.Job
var tblInfo *model.TableInfo
<<<<<<< HEAD:executor/ddl.go
if s.JobID != 0 {
job, tblInfo, err = e.getRecoverTableByJobID(s, t, dom)
} else {
=======
// Let check table first. Related isssue #46296.
if s.Table != nil {
>>>>>>> f9f6bb35c2e (ddl: fix recover table by JobID bug when JobID is set to 0 tidb-server panic (#46343)):pkg/executor/ddl.go
job, tblInfo, err = e.getRecoverTableByTableName(s.Table)
} else {
job, tblInfo, err = e.getRecoverTableByJobID(s, dom)
}
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3905,16 +3905,16 @@ type RecoverTableStmt struct {
// Restore implements Node interface.
func (n *RecoverTableStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("RECOVER TABLE ")
if n.JobID != 0 {
ctx.WriteKeyWord("BY JOB ")
ctx.WritePlainf("%d", n.JobID)
} else {
if n.Table != nil {
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing RecoverTableStmt Table")
}
if n.JobNum > 0 {
ctx.WritePlainf(" %d", n.JobNum)
}
} else {
ctx.WriteKeyWord("BY JOB ")
ctx.WritePlainf("%d", n.JobID)
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3202,6 +3202,7 @@ func TestDDL(t *testing.T) {
{"recover table by job 11", true, "RECOVER TABLE BY JOB 11"},
{"recover table by job 11,12,13", false, ""},
{"recover table by job", false, ""},
{"recover table by job 0", true, "RECOVER TABLE BY JOB 0"},
{"recover table t1", true, "RECOVER TABLE `t1`"},
{"recover table t1,t2", false, ""},
{"recover table ", false, ""},
Expand Down
Loading

0 comments on commit 17bb4b3

Please sign in to comment.