fix: use i64 for COUNT(*) result on MySQL and SQLite#2944
Merged
tyt2y3 merged 3 commits intoSeaQL:masterfrom Feb 6, 2026
Merged
fix: use i64 for COUNT(*) result on MySQL and SQLite#2944tyt2y3 merged 3 commits intoSeaQL:masterfrom
tyt2y3 merged 3 commits intoSeaQL:masterfrom
Conversation
MySQL's COUNT(*) returns BIGINT (64-bit), but SeaORM was reading it as i32 which could overflow for large datasets. Now all backends use i64 consistently.
Member
|
hi, thank you for your contribution. I realize we don't actually have test coverage for it in our test suite. can you add some test cases in a new file |
tyt2y3
approved these changes
Feb 6, 2026
Member
tyt2y3
left a comment
There was a problem hiding this comment.
thank you! looks good, can merge if all tests passed
🎉 Released In 2.0.0-rc.32 🎉Huge thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
i64consistently forCOUNT(*)results across all database backends (MySQL, PostgreSQL, SQLite)db_backendvariable that was only used for type selectionProblem
MySQL's
COUNT(*)returnsBIGINT(64-bit), but SeaORM was reading it asi32, which could cause overflow for datasets with more than ~2 billion rows.Historical Context
The original code (before commit 9c865cb) used
i32for all databases:In August 2021, commit 9c865cbb ("Try to fix count()") added PostgreSQL-specific handling because PostgreSQL's
COUNT(*)returnsBIGINTwhich cannot be decoded asi32:However, MySQL also returns
BIGINTforCOUNT(*). The fix only addressed PostgreSQL because:Solution
Use
i64for all backends since:COUNT(*)→BIGINT(i64)COUNT(*)→BIGINT(i64)Changes
src/executor/paginator.rs(async version)sea-orm-sync/src/executor/paginator.rs(sync version)