Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySQL Compat] SUM result types #1482

Open
vmg opened this issue Dec 16, 2022 · 2 comments
Open

[MySQL Compat] SUM result types #1482

vmg opened this issue Dec 16, 2022 · 2 comments

Comments

@vmg
Copy link
Contributor

vmg commented Dec 16, 2022

As discussed in #1476 (comment) --

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 SUMs is as follows:

  • Any accurate numeric type (e.g. INT, BIGINT, SMALLINT, TINYINT, DECIMAL, etc) sums into DECIMAL.
  • Any approximate numeric type (e.g. FLOAT, DOUBLE) sums into DOUBLE.

Would you be interested on a PR to mimic this behavior much more closely?

@timsehn
Copy link
Sponsor Contributor

timsehn commented Dec 16, 2022

Yes. We would definitely take a PR here.

@jycor
Copy link
Contributor

jycor commented Feb 28, 2024

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants