-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
Executing a SELECT query with an ORDER BY clause on a result set containing large TEXT columns causes a MySQLProtocolException:
MySQLProtocolException: Wrong first byte, while decoding getVariableEncInt
Removing the ORDER BY clause from the same query resolves the error. The issue is reproducible on both mysql_client 0.0.27 and mysql_client_plus 0.0.31.
Environment
- mysql_client_plus: 0.0.31
- Dart SDK: 3.10.4
- Platform: macOS (Flutter desktop app)
- MySQL: 8.x (Docker)
- Auth:
caching_sha2_password(default SSL /secure: true)
Reproduction
Failing query
SELECT
id,
name,
ST_AsText(geometry, 'axis-order=long-lat') AS wkt,
category,
source
FROM polygons
WHERE is_active = 1
ORDER BY category, source- ~1,500 rows returned
wktcolumn contains WKT strings ranging from ~800 bytes to ~18 KB
Working query (identical but without ORDER BY)
SELECT
id,
name,
ST_AsText(geometry, 'axis-order=long-lat') AS wkt,
category,
source
FROM polygons
WHERE is_active = 1Connection code
final conn = await MySQLConnection.createConnection(
host: '127.0.0.1',
port: 3306,
userName: 'user',
password: 'password',
databaseName: 'mydb',
);
await conn.connect();
// This throws MySQLProtocolException with ORDER BY,
// works fine without it.
final result = await conn.execute(sql);Observations
- The error occurs on the very first query after a fresh connection — not a stale/reused connection issue.
- Adding
LIMIT 5to theORDER BYquery does not fix it (still fails). - The same query without
ORDER BYworks with the full ~1,500 row result set. - Queries without large TEXT columns work fine with
ORDER BY.
Root cause hypothesis
When MySQL sorts a result set containing large TEXT columns, it buffers the rows differently before sending them (likely using temporary tables or filesort with different packet framing). The library's packet parser misreads the packet boundaries in the sorted response, causing it to interpret a data byte as a length-encoded integer prefix, which then fails validation.
Workaround
Remove ORDER BY from the SQL query and sort the results client-side in Dart.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels