Example #1
0
func (s *ShowPlan) fetchShowTableStatus(ctx context.Context) error {
	is := sessionctx.GetDomain(ctx).InfoSchema()
	dbName := model.NewCIStr(s.DBName)
	if !is.SchemaExists(dbName) {
		return errors.Errorf("Can not find DB: %s", dbName)
	}

	// sort for tables
	var tableNames []string
	for _, v := range is.SchemaTables(dbName) {
		tableNames = append(tableNames, v.TableName().L)
	}

	sort.Strings(tableNames)

	m := map[interface{}]interface{}{}
	for _, v := range tableNames {
		// Check like/where clause.
		if s.Pattern != nil {
			s.Pattern.Expr = expression.Value{Val: v}
		} else if s.Where != nil {
			m[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
				return nil, errors.Errorf("unknown field %s", name)
			}
		}
		match, err := s.evalCondition(ctx, m)
		if err != nil {
			return errors.Trace(err)
		}
		if !match {
			continue
		}
		now := mysql.CurrentTime(mysql.TypeDatetime)
		data := []interface{}{
			v, "InnoDB", "10", "Compact", 100, 100,
			100, 100, 100, 100, 100,
			now, now, now, "utf8_general_ci", "",
			"", "",
		}
		s.rows = append(s.rows, &plan.Row{Data: data})
	}
	return nil
}
Example #2
0
func (e *ShowExec) fetchShowTableStatus() error {
	if !e.is.SchemaExists(e.DBName) {
		return errors.Errorf("Can not find DB: %s", e.DBName)
	}

	// sort for tables
	var tableNames []string
	for _, v := range e.is.SchemaTables(e.DBName) {
		tableNames = append(tableNames, v.Meta().Name.O)
	}
	sort.Strings(tableNames)

	for _, v := range tableNames {
		now := mysql.CurrentTime(mysql.TypeDatetime)
		data := types.MakeDatums(v, "InnoDB", "10", "Compact", 100, 100, 100, 100, 100, 100, 100,
			now, now, now, "utf8_general_ci", "", "", "")
		e.rows = append(e.rows, &Row{Data: data})
	}
	return nil
}