MCPcopy
hub / github.com/pingcap/tidb / CreateView

Method CreateView

pkg/ddl/schematracker/dm_tracker.go:263–291  ·  view source on GitHub ↗

CreateView implements the DDL interface.

(ctx sessionctx.Context, s *ast.CreateViewStmt)

Source from the content-addressed store, hash-verified

261
262// CreateView implements the DDL interface.
263func (d *SchemaTracker) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt) error {
264 viewInfo, err := ddl.BuildViewInfo(s)
265 if err != nil {
266 return err
267 }
268
269 cols := make([]*table.Column, len(s.Cols))
270 for i, v := range s.Cols {
271 cols[i] = table.ToColumn(&model.ColumnInfo{
272 Name: v,
273 ID: int64(i),
274 Offset: i,
275 State: model.StatePublic,
276 })
277 }
278
279 tbInfo, err := ddl.BuildTableInfo(ddl.NewMetaBuildContextWithSctx(ctx), s.ViewName.Name, cols, nil, "", "")
280 if err != nil {
281 return err
282 }
283 tbInfo.View = viewInfo
284
285 onExist := ddl.OnExistError
286 if s.OrReplace {
287 onExist = ddl.OnExistReplace
288 }
289
290 return d.CreateTableWithInfo(ctx, s.ViewName.Schema, tbInfo, nil, ddl.WithOnExist(onExist))
291}
292
293// DropTable implements the DDL interface.
294func (d *SchemaTracker) DropTable(_ sessionctx.Context, stmt *ast.DropTableStmt) (err error) {

Callers

nothing calls this directly

Calls 6

CreateTableWithInfoMethod · 0.95
BuildViewInfoFunction · 0.92
ToColumnFunction · 0.92
BuildTableInfoFunction · 0.92
WithOnExistFunction · 0.92

Tested by

no test coverage detected