You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: lead/lag default value incorrect for DECIMAL type #24402
When using lead() or lag() window functions with a DECIMAL type column and an integer default value, the default value is not correctly scaled to match the DECIMAL precision. Instead of displaying the raw integer as a decimal value, it appears to be stored directly into the DECIMAL's raw internal storage without proper scaling.
Minimal Reproduction
select lead(cast(100.1234asdecimal(10,4)), 1, -1) over (order by a)
from (select1as a union allselect2as a) t;
Expected Result
100.1234
-1.0000
Actual Result (MO)
100.1234
-0.0001
Analysis
DECIMAL(10,4) internally uses fixed-point integer storage (value * 10^4). The default value -1 should be stored as -10000 (displaying as -1.0000), but MO writes -1 directly into the raw storage, resulting in -1 / 10^4 = -0.0001.
Note: lag(col, 1, 0) with default 0 does not exhibit the issue since 0 is unaffected by scaling.
Environment
MO branch: 4.0-dev (nightly)
Discovered during big-data window function regression tests
Commit: 726bf23
Server check: select git_version(); => 726bf23
Test process:
Built mo-service from this commit with make build.
Started MO with ./mo-service -launch ./etc/launch/launch.toml.
Connected through MySQL on 127.0.0.1:6001.
Test SQL:
select lead(cast(100.1234asdecimal(10,4)), 1, -1) over (order by a) as lead_decimal
from (select1as a union allselect2as a) t;
select lag(cast(100.1234asdecimal(10,4)), 1, -1) over (order by a) as lag_decimal
from (select1as a union allselect2as a) t;
Verified on commit: 77e514a (origin/3.0-dev, git_version() = 77e514a)
MO start method: built mo-service with Go 1.25.10, then started a clean local cluster via ./mo-service -launch /private/tmp/mo-launch-3dev/launch.toml, using isolated data-dir /private/tmp/mo-data-3dev.
SQL case:
select lead(cast(100.1234 as decimal(10,4)), 1, -1) over (order by a) ...
select lag(cast(100.1234 as decimal(10,4)), 1, -1) over (order by a) ...
Result:
lead output: 100.1234, -1.0000
lag output: -1.0000, 100.1234
Conclusion: PASS on 3.0-dev. Decimal default value is preserved as -1.0000.
Verified on commit: 3b24795 (origin/4.0-dev, git_version() = 3b24795)
MO start method: built mo-service with Go 1.25.10, then started a clean local cluster via ./mo-service -launch /private/tmp/mo-launch-4dev/launch.toml, using isolated data-dir /private/tmp/mo-data-4dev-3b24795fa.
SQL case:
select lead(cast(100.1234 as decimal(10,4)), 1, -1) over (order by a) ...
select lag(cast(100.1234 as decimal(10,4)), 1, -1) over (order by a) ...
Result:
lead output: 100.1234, -1.0000
lag output: -1.0000, 100.1234
Conclusion: PASS on 4.0-dev. Decimal default value is preserved as -1.0000.
Activity
daviszhen commentedon May 18, 2026
修改已经merge
Ariznawlll commentedon May 21, 2026
Verified on latest main.
Commit: 726bf23
Server check: select git_version(); => 726bf23
Test process:
make build../mo-service -launch ./etc/launch/launch.toml.Test SQL:
Actual result:
Result: PASS. The decimal default value is correctly scaled to -1.0000, not -0.0001.
Ariznawlll commentedon May 21, 2026
3.0-dev verification update
Verified on commit: 77e514a (origin/3.0-dev, git_version() = 77e514a)
MO start method: built mo-service with Go 1.25.10, then started a clean local cluster via ./mo-service -launch /private/tmp/mo-launch-3dev/launch.toml, using isolated data-dir /private/tmp/mo-data-3dev.
SQL case:
Result:
Conclusion: PASS on 3.0-dev. Decimal default value is preserved as -1.0000.
Ariznawlll commentedon May 21, 2026
4.0-dev verification update
Verified on commit: 3b24795 (origin/4.0-dev, git_version() = 3b24795)
MO start method: built mo-service with Go 1.25.10, then started a clean local cluster via ./mo-service -launch /private/tmp/mo-launch-4dev/launch.toml, using isolated data-dir /private/tmp/mo-data-4dev-3b24795fa.
SQL case:
Result:
Conclusion: PASS on 4.0-dev. Decimal default value is preserved as -1.0000.
Ariznawlll commentedon May 21, 2026
Verified PASS on main, 3.0-dev, and 4.0-dev. Closing as fixed.