diff --git a/pkg/sql/sem/tree/cast.go b/pkg/sql/sem/tree/cast.go index c24479603938..025ed94d6d20 100644 --- a/pkg/sql/sem/tree/cast.go +++ b/pkg/sql/sem/tree/cast.go @@ -2755,12 +2755,12 @@ func performCastWithoutPrecisionTruncation( case *DTime: return NewDInterval(duration.MakeDuration(int64(*v)*1000, 0, 0), itm), nil case *DDecimal: - d := ctx.getTmpDec() + var d apd.Decimal dnanos := v.Decimal dnanos.Exponent += 9 // We need HighPrecisionCtx because duration values can contain // upward of 35 decimal digits and DecimalCtx only provides 25. - _, err := HighPrecisionCtx.Quantize(d, &dnanos, 0) + _, err := HighPrecisionCtx.Quantize(&d, &dnanos, 0) if err != nil { return nil, err } @@ -2921,8 +2921,8 @@ func performIntToOidCast(ctx *EvalContext, t *types.T, v DInt) (Datum, error) { } func roundDecimalToInt(ctx *EvalContext, d *apd.Decimal) (int64, error) { - newD := ctx.getTmpDec() - if _, err := DecimalCtx.RoundToIntegralValue(newD, d); err != nil { + var newD apd.Decimal + if _, err := DecimalCtx.RoundToIntegralValue(&newD, d); err != nil { return 0, err } i, err := newD.Int64() diff --git a/pkg/sql/sem/tree/datum.go b/pkg/sql/sem/tree/datum.go index 61c59066fae0..5b0a7cb23635 100644 --- a/pkg/sql/sem/tree/datum.go +++ b/pkg/sql/sem/tree/datum.go @@ -1057,10 +1057,10 @@ func (d *DDecimal) CompareError(ctx *EvalContext, other Datum) (int, error) { // NULL is less than any non-NULL value. return 1, nil } - v := ctx.getTmpDec() + var v apd.Decimal switch t := UnwrapDatum(ctx, other).(type) { case *DDecimal: - v = &t.Decimal + v.Set(&t.Decimal) case *DInt: v.SetInt64(int64(*t)) case *DFloat: @@ -1070,7 +1070,7 @@ func (d *DDecimal) CompareError(ctx *EvalContext, other Datum) (int, error) { default: return 0, makeUnsupportedComparisonMessage(d, other) } - res := CompareDecimals(&d.Decimal, v) + res := CompareDecimals(&d.Decimal, &v) return res, nil } diff --git a/pkg/sql/sem/tree/eval.go b/pkg/sql/sem/tree/eval.go index 91811b2592f1..21358f97642c 100644 --- a/pkg/sql/sem/tree/eval.go +++ b/pkg/sql/sem/tree/eval.go @@ -1428,10 +1428,11 @@ var BinOps = map[BinaryOperatorSymbol]binOpOverload{ if rInt == 0 { return nil, ErrDivByZero } - div := ctx.getTmpDec().SetInt64(int64(rInt)) + var div apd.Decimal + div.SetInt64(int64(rInt)) dd := &DDecimal{} dd.SetInt64(int64(MustBeDInt(left))) - _, err := DecimalCtx.Quo(&dd.Decimal, &dd.Decimal, div) + _, err := DecimalCtx.Quo(&dd.Decimal, &dd.Decimal, &div) return dd, err }, Volatility: VolatilityImmutable, @@ -3930,10 +3931,6 @@ func (ctx *EvalContext) Ctx() context.Context { return ctx.Context } -func (ctx *EvalContext) getTmpDec() *apd.Decimal { - return &ctx.tmpDec -} - // Eval implements the TypedExpr interface. func (expr *AndExpr) Eval(ctx *EvalContext) (Datum, error) { left, err := expr.Left.(TypedExpr).Eval(ctx)