func EncodeDecimal(b []byte, dec *types.MyDecimal, precision, frac int) ([]byte, error) {
	if precision == 0 {
		precision, frac = dec.PrecisionAndFrac()
	}
	b = append(b, byte(precision), byte(frac))
	bin, err := dec.ToBin(precision, frac)
	b = append(b, bin...)
	return b, errors.Trace(err)
}
EncodeDecimal encodes a decimal into a byte slice which can be sorted lexicographically later.
package codec
import (
	"github.com/pingcap/errors"
	"github.com/pingcap/failpoint"
	"github.com/pingcap/tidb/types"
)