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

Method CreateTable

br/pkg/restore/internal/prealloc_db/db.go:307–342  ·  view source on GitHub ↗

CreateTable executes a CREATE TABLE SQL.

(ctx context.Context, table *metautil.Table,
	ddlTables map[restore.UniqueTableName]bool, supportPolicy bool, policyMap *sync.Map)

Source from the content-addressed store, hash-verified

305
306// CreateTable executes a CREATE TABLE SQL.
307func (db *DB) CreateTable(ctx context.Context, table *metautil.Table,
308 ddlTables map[restore.UniqueTableName]bool, supportPolicy bool, policyMap *sync.Map) error {
309 if !supportPolicy {
310 log.Info("set placementPolicyRef to nil when target tidb not support policy",
311 zap.Stringer("table", table.Info.Name), zap.Stringer("db", table.DB.Name))
312 table.Info.ClearPlacement()
313 } else {
314 if err := db.ensureTablePlacementPolicies(ctx, table.Info, policyMap); err != nil {
315 return errors.Trace(err)
316 }
317 }
318
319 if ttlInfo := table.Info.TTLInfo; ttlInfo != nil {
320 ttlInfo.Enable = false
321 }
322
323 infoClone, err := db.preallocedIDs.RewriteTableInfo(table.Info)
324 if err != nil {
325 return errors.Trace(err)
326 }
327 err = db.se.CreateTable(ctx, table.DB.Name, infoClone, ddl.WithIDAllocated(true))
328 if err != nil {
329 log.Error("create table failed",
330 zap.Stringer("db", table.DB.Name),
331 zap.Stringer("table", table.Info.Name),
332 zap.Error(err))
333 return errors.Trace(err)
334 }
335
336 err = db.CreateTablePostRestore(ctx, table, ddlTables)
337 if err != nil {
338 return errors.Trace(err)
339 }
340
341 return err
342}
343
344// Close closes the connection.
345func (db *DB) Close() {

Callers 3

TestRestoreAutoIncIDFunction · 0.95
TestPolicyModeFunction · 0.95

Calls 7

WithIDAllocatedFunction · 0.92
ClearPlacementMethod · 0.80
RewriteTableInfoMethod · 0.80
CreateTableMethod · 0.65
ErrorMethod · 0.65

Tested by 3

TestRestoreAutoIncIDFunction · 0.76
TestPolicyModeFunction · 0.76