Repository navigation
Description
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
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 frometc/launchwith 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:
select cast(1e22 as double)returns10000000000000000000000(23 chars). MySQL 8.0.46 returns1e22.select cast(1e15 as double)returns1000000000000000; MySQL returns1e15.- A DOUBLE column holding DBL_MAX (
1.7976931348623157e308) is returned as a 309-character expansion17976931348623157followed by 2920s; MySQL returns1.7976931348623157e308. - Small magnitudes:
select cast(1e-16 as double)returns0.0000000000000001; MySQL returns1e-16.select cast(1e-30 as double)returns a 33-digit fraction; MySQL returns1e-30. - 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 queryselect k, a, last_value(a) over () lv, max(a) over () mx, lag(a, 1, 1e15) over (order by k) lg from td order by kreturns, for every one ofa,lv,mx,lg, the full fixed-point expansion (e.g.lgof row 3 is the 309-digit expansion) where MySQL returns1e-20/1.7976931348623157e308/1e22/1e15style tokens. - Over a FLOAT column
tf(k int, a float)with(1,1e20),(2,1e15),sum(a) over ()returns100001002004074730000; MySQL returns1.0000100200407473e20. - 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))returns1E+22andcast(1.7976931348623157e308 as char(40))returns1.7976931348623157E+308(Go capital-Eexponent style), while the result-set path for the same values returns the fixed-point expansions. MySQL's CAST output is1e22/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
- Build and start a standalone instance; no special configuration or session variables are needed (I used
etc/launchcopied to.loom-test/launchwith every port offset by +20000 and the data dir under.loom-test/, defaults elsewhere). - Connect with any MySQL-protocol client (here
mysql -P 26001 -u dump -p111 -B --raw) and run the SQL fromreprobelow, or just:select cast(1e22 as double); - Run the identical SQL against MySQL 8.0.46 (here
mysql -P 33306 -u root -B --raw). - 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) andcase float64: return strconv.FormatFloat(v, 'f', -1, 64)(line 475). Go's'f'format never emits an exponent;-1precision 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.goline 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.goline 10852 (CAST double->string) uses the same 'f' format... which produces yet another style for CAST (1E+22observed - 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.golines 550-559 (SELECT INTO OUTFILE),pkg/sql/colexec/externalwrite/encode.golines 236-244 (external write),pkg/sql/datastream/filter.golines 134-136,pkg/container/types/array.golines 77-83 (VECTOR/ARRAY toString),pkg/sql/colexec/aggexec/agg_payload.goline 143, whilepkg/container/types/tuple.golines 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
Ariznawlll commentedon Oct 26, 2026
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:
1.5e101500000000015000000000(same)1.5e20150000000000000000000(21 chars)1.5e201.5e1001.5e1001.5e3001.5e3001e3081e308So the cutoff is between
1e10(MO still plain, MySQL also plain) and1.5e20(MO plain, MySQL exponent). MySQL's threshold for switching to exponent form is around1e16/1e17-ish for DOUBLE; MO never switches.Negative exponents behave the same way:
1.5e-100.000000000150.00000000015(same)1.5e-1000.000…00015(100 zeros)1.5e-1002.5e-3000.000…25(300 zeros)2.5e-300So both tails of the range expand. For
1e308the 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 OUTFILEandEXPORTproduce 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.