// QuoteSimpleTableName quotes a simple table name.
// A simple table name does not contain any schema prefix.
966203
func (b *SqliteBuilder) QuoteSimpleTableName(s string) string {
	if strings.ContainsAny(s, "`") {
		return s
	}
	return "`" + s + "`"
}
147406
func maybeQuote(s string) string {
	for _, r := range s {
		if !('0' <= r && r <= '9' || 'a' <= r && r <= 'z' ||
			'A' <= r && r <= 'Z' || r == '-' || r == '_') {
			return quote(s)
		}
	}
	return s
}
1038904
func (b *MysqlBuilder) QuoteSimpleTableName(s string) string {
	if strings.ContainsAny(s, "`") {
		return s
	}
	return "`" + s + "`"
}
23021
func (nr *nameResolver) handleTableName(tn *ast.TableName) {
	if tn.Schema.L == "" {
		tn.Schema = nr.DefaultSchema
	}
	ctx := nr.currentContext()
	if ctx.inCreateOrDropTable {
		// The table may not exist in create table or drop table statement.
		// Skip resolving the table to avoid error.
		return
	}
	if ctx.inDeleteTableList {
		idx, ok := ctx.tableMap[nr.tableUniqueName(tn.Schema, tn.Name)]
		if !ok {
			nr.Err = errors.Errorf("Unknown table %s", tn.Name.O)
			return
		}
		ts := ctx.tables[idx]
		tableName := ts.Source.(*ast.TableName)
		tn.DBInfo = tableName.DBInfo
		tn.TableInfo = tableName.TableInfo
		tn.SetResultFields(tableName.GetResultFields())
		return
	}
	table, err := nr.Info.TableByName(tn.Schema, tn.Name)
	if err != nil {
		nr.Err = errors.Trace(err)
		return
	}
	tn.TableInfo = table.Meta()
	dbInfo, _ := nr.Info.SchemaByName(tn.Schema)
	tn.DBInfo = dbInfo

	rfs := make([]*ast.ResultField, 0, len(tn.TableInfo.Columns))
	tmp := make([]struct {
		ast.ValueExpr
		ast.ResultField
	}, len(tn.TableInfo.Columns))
	for i, v := range tn.TableInfo.Columns {
		expr := &tmp[i].ValueExpr
		rf := &tmp[i].ResultField
		expr.SetType(&v.FieldType)
		*rf = ast.ResultField{
			Column:    v,
			Table:     tn.TableInfo,
			DBName:    tn.Schema,
			Expr:      expr,
			TableName: tn,
		}
		rfs = append(rfs, rf)
	}
	tn.SetResultFields(rfs)
	return
}
152286
func (scope *Scope) TableName() string {
	if scope.Search != nil && len(scope.Search.tableName) > 0 {
		return scope.Search.tableName
	}

	if tabler, ok := scope.Value.(tabler); ok {
		return tabler.TableName()
	}

	if tabler, ok := scope.Value.(dbTabler); ok {
		return tabler.TableName(scope.db)
	}

	return scope.GetModelStruct().TableName(scope.db.Model(scope.Value))
}
1118917
func (s *TableDescription) SetTableName(v string) *TableDescription {
	s.TableName = &v
	return s
}
465429
func (s *TableStatistics) SetTableName(v string) *TableStatistics {
	s.TableName = &v
	return s
}
752990
func (s *ListStreamsInput) SetTableName(v string) *ListStreamsInput {
	s.TableName = &v
	return s
}
82547
func (s *BatchDeleteTableVersionInput) SetTableName(v string) *BatchDeleteTableVersionInput {
	s.TableName = &v
	return s
}
444721
func (pb *primitiveBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTableExpr, tableName sqlparser.TableName) error {
	alias := tableName
	if !tableExpr.As.IsEmpty() {
		alias = sqlparser.TableName{Name: tableExpr.As}
	}
	sel := &sqlparser.Select{From: sqlparser.TableExprs([]sqlparser.TableExpr{tableExpr})}

	if systemTable(tableName.Qualifier.String()) {
		ks, err := pb.vschema.DefaultKeyspace()
		if err != nil {
			return err
		}
		rb, st := newRoute(sel)
		rb.routeOptions = []*routeOption{newSimpleRouteOption(rb, engine.NewSimpleRoute(engine.SelectDBA, ks))}
		pb.bldr, pb.st = rb, st
		return nil
	}

	vschemaTables, vindex, _, destTableType, destTarget, err := pb.vschema.FindTablesOrVindex(tableName)
	if err != nil {
		return err
	}
	if vindex != nil {
		pb.bldr, pb.st = newVindexFunc(alias, vindex)
		return nil
	}

	rb, st := newRoute(sel)
	pb.bldr, pb.st = rb, st
	vindexMaps, err := st.AddVSchemaTable(alias, vschemaTables, rb)
	if err != nil {
		return err
	}
	for i, vst := range vschemaTables {
		sub := &tableSubstitution{
			oldExpr: tableExpr,
		}
		if tableExpr.As.IsEmpty() {
			if tableName.Name != vst.Name {
				// Table name does not match. Change and alias it to old name.
				sub.newExpr = &sqlparser.AliasedTableExpr{
					Expr: sqlparser.TableName{Name: vst.Name},
					As:   tableName.Name,
				}
			}
		} else {
			// Table is already aliased.
			if tableName.Name != vst.Name {
				// Table name does not match. Change it and reuse existing alias.
				sub.newExpr = &sqlparser.AliasedTableExpr{
					Expr: sqlparser.TableName{Name: vst.Name},
					As:   tableExpr.As,
				}
			}
		}
		var eroute *engine.Route
		switch {
		case vst.Type == vindexes.TypeSequence:
			eroute = engine.NewSimpleRoute(engine.SelectNext, vst.Keyspace)
		case vst.Type == vindexes.TypeReference:
			eroute = engine.NewSimpleRoute(engine.SelectReference, vst.Keyspace)
		case !vst.Keyspace.Sharded:
			eroute = engine.NewSimpleRoute(engine.SelectUnsharded, vst.Keyspace)
		case vst.Pinned == nil:
			eroute = engine.NewSimpleRoute(engine.SelectScatter, vst.Keyspace)
			eroute.TargetDestination = destTarget
			eroute.TargetTabletType = destTableType
		default:
			// Pinned tables have their keyspace ids already assigned.
			// Use the Binary vindex, which is the identity function
			// for keyspace id. Currently only dual tables are pinned.
			eroute = engine.NewSimpleRoute(engine.SelectEqualUnique, vst.Keyspace)
			eroute.Vindex, _ = vindexes.NewBinary("binary", nil)
			eroute.Values = []sqltypes.PlanValue{{Value: sqltypes.MakeTrusted(sqltypes.VarBinary, vst.Pinned)}}
		}
		rb.routeOptions = append(rb.routeOptions, newRouteOption(rb, vst, sub, vindexMaps[i], eroute))
	}
	return nil
}
26892
func (plan *Plan) TableName() sqlparser.TableIdent {
	var tableName sqlparser.TableIdent
	if plan.Table != nil {
		tableName = plan.Table.Name
	}
	return tableName
}
431367
func (m *DbMap) AddTableWithName(i interface{}, name string) *TableMap {
	return m.AddTable(i, name)
}
887657
func (s *DeletePartitionInput) SetTableName(v string) *DeletePartitionInput {
	s.TableName = &v
	return s
}
958544
func (s *ConsumedCapacity) SetTableName(v string) *ConsumedCapacity {
	s.TableName = &v
	return s
}
186692
func (s *ColumnInfo) SetTableName(v string) *ColumnInfo {
	s.TableName = &v
	return s
}
319049
func (s *TableVersionError) SetTableName(v string) *TableVersionError {
	s.TableName = &v
	return s
}
927970
func (s *DeleteTableVersionInput) SetTableName(v string) *DeleteTableVersionInput {
	s.TableName = &v
	return s
}