code: func (a *baseFuncDesc) typeInfer4Avg(ctx sessionctx.Context) {
  	switch a.Args[0].GetType().Tp {
  	case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeNewDecimal:
  		a.RetTp = types.NewFieldType(mysql.TypeNewDecimal)
  		if a.Args[0].GetType().Decimal < 0 {
  			a.RetTp.Decimal = mysql.MaxDecimalScale
  		} else {
  			a.RetTp.Decimal = mathutil.Min(a.Args[0].GetType().Decimal+types.DivFracIncr, mysql.MaxDecimalScale)
  		}
  		a.RetTp.Flen = mysql.MaxDecimalWidth
  	case mysql.TypeDouble, mysql.TypeFloat:
  		a.RetTp = types.NewFieldType(mysql.TypeDouble)
  		a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxRealWidth, a.Args[0].GetType().Decimal
  	default:
  		a.RetTp = types.NewFieldType(mysql.TypeDouble)
  		a.RetTp.Flen, a.RetTp.Decimal = mysql.MaxRealWidth, types.UnspecifiedLength
  	}
  	types.SetBinChsClnFlag(a.RetTp)
  }
docs: // typeInfer4Avg should returns a "decimal", otherwise it returns a "double".
  // Because child returns integer or decimal type.