Skip to content

[Bug]: FLOAT/DOUBLE results never use scientific notation on the MySQL text wire, unlike MySQL 8.0 #30521

Open

Description

@iamlinjunhong

Is there an existing issue for the same bug?

I have checked the existing issues (see duplicates_checked). The nearest ones are #28660 (GROUP_CONCAT uses scientific notation where MySQL does not - opposite direction, aggregate-specific), #25605 (SELECT INTO OUTFILE DOUBLE precision loss - export path), #28485 (DEGREES persists infinity for finite input - arithmetic/persistence), #8719 (2023, CAST to string printed scientific notation where MySQL prints plain - again the opposite direction, fixed in V0.8 era). None of them covers "the result-set text wire never uses scientific notation where MySQL does".

Branch Name

main

Commit ID

3fc0070

Other Environment Information

  • Hardware parameters: Apple Silicon dev machine, arm64
  • OS type: macOS (Darwin arm64)
  • Others: MatrixOne standalone launched with ./mo-service -launch .loom-test/launch/launch.toml (config copied from etc/launch with all ports +20000 per LOOM_TEST_PORT_OFFSET, LOCAL FileService data dir under .loom-test/; no special session variables, defaults only). Comparison oracle: MySQL 8.0.46 Homebrew instance (mysqld, port 33306). Client for both engines: /opt/homebrew/opt/[email protected]/bin/mysql --protocol=TCP -h 127.0.0.1 -P <port> -B --raw.

Actual Behavior

Every FLOAT/DOUBLE value returned over the MySQL text protocol is formatted with Go's fixed-point format strconv.FormatFloat(v, 'f', -1, 64), which never emits an exponent, so MatrixOne and MySQL return different bytes for the same DOUBLE/FLOAT values whenever the magnitude falls outside MySQL's plain-decimal band:

  1. select cast(1e22 as double) returns 10000000000000000000000 (23 chars). MySQL 8.0.46 returns 1e22.
  2. select cast(1e15 as double) returns 1000000000000000; MySQL returns 1e15.
  3. A DOUBLE column holding DBL_MAX (1.7976931348623157e308) is returned as a 309-character expansion 17976931348623157 followed by 292 0s; MySQL returns 1.7976931348623157e308.
  4. Small magnitudes: select cast(1e-16 as double) returns 0.0000000000000001; MySQL returns 1e-16. select cast(1e-30 as double) returns a 33-digit fraction; MySQL returns 1e-30.
  5. Window-function results over FLOAT/DOUBLE inputs reproduce the divergence identically: over td(k int, a double) with rows (1,1e22),(2,1.7976931348623157e308),(3,1e-20), the query select k, a, last_value(a) over () lv, max(a) over () mx, lag(a, 1, 1e15) over (order by k) lg from td order by k returns, for every one of a,lv,mx,lg, the full fixed-point expansion (e.g. lg of row 3 is the 309-digit expansion) where MySQL returns 1e-20 / 1.7976931348623157e308 / 1e22 / 1e15 style tokens.
  6. Over a FLOAT column tf(k int, a float) with (1,1e20),(2,1e15), sum(a) over () returns 100001002004074730000; MySQL returns 1.0000100200407473e20.
  7. The CAST-to-string path is affected as well and is even inconsistent with the result-set path inside MatrixOne itself: cast(1e22 as char(40)) returns 1E+22 and cast(1.7976931348623157e308 as char(40)) returns 1.7976931348623157E+308 (Go capital-E exponent style), while the result-set path for the same values returns the fixed-point expansions. MySQL's CAST output is 1e22 / 1.7976931348623157e308.

Impact: any MySQL client or tool that byte-compares, diffs, or round-trips FLOAT/DOUBLE text (ETL compare tools, export/dump round-trips, ORM caches keyed on string representations, int64-parsers that receive a 309-digit integer token in a DOUBLE column) sees values that differ from what real MySQL sends for the same data. This was discovered during window-function differential testing (window outputs over FLOAT/DOUBLE columns), but the divergence is not window-specific: it is the general result-set rendering path.

Expected Behavior

MySQL 8.0 renders DOUBLE/FLOAT values on the text protocol with the shortest round-trip representation, using plain decimal notation within roughly 1e-15 <= |x| < 1e15 and scientific notation outside that band (measured on 8.0.46: cast(1e14 as double) -> 100000000000000, cast(1e15 as double) -> 1e15, cast(1e-15 as double) -> 0.000000000000001, cast(1e-16 as double) -> 1e-16, DBL_MAX -> 1.7976931348623157e308). Since MatrixOne targets MySQL compatibility (same wire protocol, mysql client connects transparently), FLOAT/DOUBLE rendering should match MySQL's, i.e. use a shortest-round-trim formatter with exponent form outside the plain band (MySQL implements this with my_gcvt). Both engines agree inside the plain band, which is why ordinary small-scale tests pass.

Steps to Reproduce

  1. Build and start a standalone instance; no special configuration or session variables are needed (I used etc/launch copied to .loom-test/launch with every port offset by +20000 and the data dir under .loom-test/, defaults elsewhere).
  2. Connect with any MySQL-protocol client (here mysql -P 26001 -u dump -p111 -B --raw) and run the SQL from repro below, or just: select cast(1e22 as double);
  3. Run the identical SQL against MySQL 8.0.46 (here mysql -P 33306 -u root -B --raw).
  4. Compare outputs: MatrixOne emits fixed-point expansions (10000000000000000000000, 309-digit strings for DBL_MAX, 0.0000000000000001), MySQL emits scientific tokens (1e22, 1.7976931348623157e308, 1e-16).

Additional information

Root cause (analysis):

  • pkg/frontend/resultset.go, MysqlResultSet.GetString(): case float32: return strconv.FormatFloat(float64(v), 'f', -1, 32) (line 473) and case float64: return strconv.FormatFloat(v, 'f', -1, 64) (line 475). Go's 'f' format never emits an exponent; -1 precision makes it the shortest round-trip digits rendered in fixed-point position. This is the MySQL text-protocol row-serialization path, so every FLOAT/DOUBLE column value and every window/aggregate/scalar expression evaluated into float64 flows through here.
  • pkg/common/assertx/float64.go line 27 documents this as a deliberate global convention: "strconv.FormatFloat(float64(value), 'f', -1, 64) we use for outputting float64 values".
  • pkg/sql/plan/function/func_cast.go line 10852 (CAST double->string) uses the same 'f' format... which produces yet another style for CAST (1E+22 observed - Go exponent formatting), so the CAST path and the result-set path disagree with each other and with MySQL.
  • Other internal float-to-string sites using 'f' -1: pkg/frontend/export.go lines 550-559 (SELECT INTO OUTFILE), pkg/sql/colexec/externalwrite/encode.go lines 236-244 (external write), pkg/sql/datastream/filter.go lines 134-136, pkg/container/types/array.go lines 77-83 (VECTOR/ARRAY toString), pkg/sql/colexec/aggexec/agg_payload.go line 143, while pkg/container/types/tuple.go lines 1028/1037 uses 'G' - there is no single MySQL-compatible (my_gcvt-style) formatter anywhere in the tree.

Suggested fix direction: add one MySQL-compatible float formatter (port MySQL's my_gcvt behavior: shortest round-trip digits, plain notation while the decimal exponent stays in roughly [-15, 15), scientific otherwise, lowercase e, no +/leading zeros - i.e. 1e15, 1e-16, 1.7976931348623157e308) and use it for the result-set writer, CAST-to-string, export paths; keep the existing exact expansions only where MySQL itself would print exact decimal (it never does for DOUBLE/FLOAT). For backward-compatibility concerns: the numeric values on the wire do not change (any strict double parser reads both forms identically); only the textual form changes, so existing numeric clients are unaffected, while string-exact consumers gain MySQL parity.

Related prior art in-repo: #28660 (GROUP_CONCAT formatting was accepted as kind/bug and fixed) shows the maintainers treat MySQL formatting parity for float rendering as a bug class worth fixing; this report is the same class, different (and broader) path.

Full reproduction, exactly as Loom ran it
-- Minimal repro, run the identical SQL on MatrixOne standalone and on MySQL 8.0.46,
-- client: mysql --protocol=TCP -B --raw (no special mo config needed; defaults used).
drop database if exists sci_repro;
create database sci_repro;
use sci_repro;

create table td(k int, a double);
insert into td values (1, 1e22), (2, 1.7976931348623157e308), (3, 1e-20);

-- T1 plain SELECT: MO renders fixed-point, MySQL scientific
select * from td order by k;

-- T2 window functions over the DOUBLE column
select k, a, last_value(a) over () as lv, max(a) over () as mx,
       lag(a, 1, 1e15) over (order by k) as lg
from td order by k;

-- T3 CAST to string (MO: 1E+22 style; MySQL: 1e22 style)
select k, cast(a as char(40)) as c from td order by k;

-- T4 magnitude boundaries
select cast(1e14 as double) as a14, cast(1e15 as double) as a15,
       cast(1e-15 as double) as am15, cast(1e-16 as double) as am16;

-- T5 FLOAT column + window aggregate
create table tf(k int, a float);
insert into tf values (1, 1e20), (2, 1e15);
select k, a, sum(a) over () as s, row_number() over (order by k) as rn from tf order by k;

drop database if exists sci_repro;

Found by Loom bug hunt (module: custom-691c28503e; tests: unit, black-box, end-to-end)

Activity

  1. added
    kind/bug
    on Oct 18, 2026
  2. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    Collaborator

    Adding measured thresholds to narrow the fix, and confirming the same behavior on the negative-exponent side.

    Positive exponents — MO switches to plain decimal from 1.5e20 onward:

    Literal MO output MySQL 8.0.45
    1.5e10 15000000000 15000000000 (same)
    1.5e20 150000000000000000000 (21 chars) 1.5e20
    1.5e100 101-digit integer 1.5e100
    1.5e300 301-digit integer 1.5e300
    1e308 309-digit integer 1e308

    So the cutoff is between 1e10 (MO still plain, MySQL also plain) and 1.5e20 (MO plain, MySQL exponent). MySQL's threshold for switching to exponent form is around 1e16/1e17-ish for DOUBLE; MO never switches.

    Negative exponents behave the same way:

    Literal MO output MySQL 8.0.45
    1.5e-10 0.00000000015 0.00000000015 (same)
    1.5e-100 0.000…00015 (100 zeros) 1.5e-100
    2.5e-300 0.000…25 (300 zeros) 2.5e-300

    So both tails of the range expand. For 1e308 the wire value is ~309 bytes per row versus 5 bytes on MySQL.

    Practical amplification: a result set with 100k such rows sends ~30 MB on MO where MySQL sends ~0.5 MB, and any client that parses the text into a fixed-width numeric type (or a JSON number) has to handle a 300-digit integer — many JSON parsers and BigQuery/Numeric backends reject or lose precision on that. Bulk SELECT ... INTO OUTFILE and EXPORT produce correspondingly bloated files.

    Also worth noting: LENGTH(CAST(1.5e300 AS CHAR)) returns 8 on both engines, i.e. casting to CHAR does produce '1.5e300' — it is specifically the FLOAT/DOUBLE text wire format that expands, not all string conversion. That further localizes the bug to the result-serialization layer rather than the CAST implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions