(ctx sessionctx.Context, s *ast.CreateTableStmt)
| 990 | } |
| 991 | |
| 992 | func (e *executor) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err error) { |
| 993 | ident := ast.Ident{Schema: s.Table.Schema, Name: s.Table.Name} |
| 994 | is := e.infoCache.GetLatest() |
| 995 | schema, ok := is.SchemaByName(ident.Schema) |
| 996 | if !ok { |
| 997 | return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema) |
| 998 | } |
| 999 | |
| 1000 | var ( |
| 1001 | referTbl table.Table |
| 1002 | involvingRef []model.InvolvingSchemaInfo |
| 1003 | ) |
| 1004 | if s.ReferTable != nil { |
| 1005 | referIdent := ast.Ident{Schema: s.ReferTable.Schema, Name: s.ReferTable.Name} |
| 1006 | _, ok := is.SchemaByName(referIdent.Schema) |
| 1007 | if !ok { |
| 1008 | return infoschema.ErrTableNotExists.GenWithStackByArgs(referIdent.Schema, referIdent.Name) |
| 1009 | } |
| 1010 | referTbl, err = is.TableByName(e.ctx, referIdent.Schema, referIdent.Name) |
| 1011 | if err != nil { |
| 1012 | return infoschema.ErrTableNotExists.GenWithStackByArgs(referIdent.Schema, referIdent.Name) |
| 1013 | } |
| 1014 | involvingRef = append(involvingRef, model.InvolvingSchemaInfo{ |
| 1015 | Database: s.ReferTable.Schema.L, |
| 1016 | Table: s.ReferTable.Name.L, |
| 1017 | Mode: model.SharedInvolving, |
| 1018 | }) |
| 1019 | } |
| 1020 | |
| 1021 | // build tableInfo |
| 1022 | metaBuildCtx := NewMetaBuildContextWithSctx(ctx) |
| 1023 | var tbInfo *model.TableInfo |
| 1024 | if s.ReferTable != nil { |
| 1025 | tbInfo, err = BuildTableInfoWithLike(ident, referTbl.Meta(), s) |
| 1026 | } else { |
| 1027 | tbInfo, err = BuildTableInfoWithStmt(metaBuildCtx, s, schema.Charset, schema.Collate, schema.PlacementPolicyRef) |
| 1028 | } |
| 1029 | if err != nil { |
| 1030 | return errors.Trace(err) |
| 1031 | } |
| 1032 | |
| 1033 | if err = rewritePartitionQueryString(ctx, s.Partition, tbInfo); err != nil { |
| 1034 | return err |
| 1035 | } |
| 1036 | |
| 1037 | if err = checkTableInfoValidWithStmt(metaBuildCtx, tbInfo, s); err != nil { |
| 1038 | return err |
| 1039 | } |
| 1040 | if err = checkTableForeignKeysValid(ctx, is, schema.Name.L, tbInfo); err != nil { |
| 1041 | return err |
| 1042 | } |
| 1043 | |
| 1044 | onExist := OnExistError |
| 1045 | if s.IfNotExists { |
| 1046 | onExist = OnExistIgnore |
| 1047 | } |
| 1048 | |
| 1049 | return e.CreateTableWithInfo(ctx, schema.Name, tbInfo, involvingRef, WithOnExist(onExist)) |
nothing calls this directly
no test coverage detected