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

ddl: table meta should store column without db and table name (#50978) #51019

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ func checkTableInfoValidWithStmt(ctx sessionctx.Context, tbInfo *model.TableInfo
return errors.Trace(err)
}
if s.Partition != nil {
if err := checkPartitionFuncType(ctx, s.Partition.Expr, tbInfo); err != nil {
if err := checkPartitionFuncType(ctx, s.Partition.Expr, s.Table.Schema, tbInfo); err != nil {
return errors.Trace(err)
}
if err := checkPartitioningKeysConstraints(ctx, s, tbInfo); err != nil {
Expand Down
19 changes: 17 additions & 2 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb
return errors.Trace(err)
}
buf := new(bytes.Buffer)
restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags|format.RestoreBracketAroundBinaryOperation, buf)
restoreFlags := format.DefaultRestoreFlags | format.RestoreBracketAroundBinaryOperation |
format.RestoreWithoutSchemaName | format.RestoreWithoutTableName
restoreCtx := format.NewRestoreCtx(restoreFlags, buf)
if err := s.Expr.Restore(restoreCtx); err != nil {
return err
}
Expand Down Expand Up @@ -1392,12 +1394,25 @@ func checkResultOK(ok bool) error {
}

// checkPartitionFuncType checks partition function return type.
func checkPartitionFuncType(ctx sessionctx.Context, expr ast.ExprNode, tblInfo *model.TableInfo) error {
func checkPartitionFuncType(ctx sessionctx.Context, expr ast.ExprNode, dbName model.CIStr, tblInfo *model.TableInfo) error {
if expr == nil {
return nil
}

<<<<<<< HEAD:ddl/partition.go
e, err := expression.RewriteSimpleExprWithTableInfo(ctx, tblInfo, expr)
=======
if dbName.L == "" {
dbName = model.NewCIStr(ctx.GetSessionVars().CurrentDB)
}

columns, names, err := expression.ColumnInfos2ColumnsAndNames(ctx, dbName, tblInfo.Name, tblInfo.Cols(), tblInfo)
if err != nil {
return err
}

e, err := expression.RewriteAstExpr(ctx, expr, expression.NewSchema(columns...), names, false)
>>>>>>> 5c8b559854b (ddl: table meta should store column without db and table name (#50978)):pkg/ddl/partition.go
if err != nil {
return errors.Trace(err)
}
Expand Down
Loading
Loading