go-mysql-server
go-mysql-server copied to clipboard
[MySQL Compat] SUM result types
As discussed in https://github.com/dolthub/go-mysql-server/pull/1476#issuecomment-1352731490 --
The result type for SUM
aggregations in go-mysql-server
does not match MySQL's. Even though the actual SumBuffer
that performs the computation internally uses either float64
or Decimal
, the type for the resulting column in the planned schema defaults to the type of the underlying column.
As an example: in MySQL, summing a column of INT
(i.e. int32
) results in a DECIMAL
result for the output row. This is the same when summing any other integral type, regardless of whether the type has overflowed or not. In go-mysql-server
, summing a column of INT
returns INT
. In fact, summing any integral type returns the same integral type.
The general rule for MySQL types in SUM
s is as follows:
- Any accurate numeric type (e.g.
INT
,BIGINT
,SMALLINT
,TINYINT
,DECIMAL
, etc) sums intoDECIMAL
. - Any approximate numeric type (e.g.
FLOAT
,DOUBLE
) sums intoDOUBLE
.
Would you be interested on a PR to mimic this behavior much more closely?
Yes. We would definitely take a PR here.
Hey @vmg,
GMS behavior here has changed.
We currently always return DOUBLE
regardless of the input types (this might also be the case for COUNT
).
We can start fixing this soon. Unless you still want to :)
Is there any progress?
we got float64
even from select unix_timestamp('2000-01-01')