Bug #82696 Warning count sometimes 2-bytes and sometimes 4-byte
Submitted: 23 Aug 2016 14:27 Modified: 29 Nov 2016 7:34
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: warnings

[23 Aug 2016 14:27] Daniël van Eeden
Description:
Example resultset:
Query OK, 110380165 rows affected, 65535 warnings (1 hour 41 min 38.07 sec)
Records: 110380165  Duplicates: 0  Warnings: 9155440

This is from a mysql client (mysql monitor) session.

Note that 65535<>9155440

Looks like warning count is stored as:
8 bytes (ulong) in client/mysql.cc
4 bytes (uint) in st_mysql/MYSQL from include/mysql.h
2 bytes (short int unsigned) in 'OK Packet' on the wire. 

https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html

How to repeat:
Read code and run queries with > 65535 warnings.

Suggested fix:
1. Make a note on https://dev.mysql.com/doc/refman/5.7/en/mysql-warning-count.html
That it might not return values >65535.

2. Make it return a 4-byte value.
[23 Aug 2016 15:27] Umesh Shastry
Hello Daniël,

Thank you for the report.

Thanks,
Umesh
[23 Aug 2016 21:16] Daniël van Eeden
Proposed fix:
- Create CLIENT_PROTOCOL_80 Flag
- If that flag is set warnings == 4 bytes. If the 4.1 flag is set warnings == 2 bytes, else (3.23 etc) no warnings.
[25 Aug 2016 16:21] Simon Mudd
Please also document this protocol change as clearly as possible.
[3 Oct 2016 21:46] Daniël van Eeden
Related:
Bug #23164	Query summary Warnings count capped at 65535
[4 Oct 2016 8:10] Daniël van Eeden
Related:
Bug #23164 	Query summary Warnings count capped at 65535
[28 Nov 2016 14:01] Georgi Kodinov
Daniël,

Just curious: what good is having more than 64k warnings in the protocol ?
Will you read all of them ?
Note that this is different from the server count, which is stored in an (per-message type array of) uint.
IMHO if you hit 64k warnings something is drastically wrong with the SQL you're executing. 
And yes, I am aware that it will generate 1 warning for every conversion that went somewhat wrong.
[29 Nov 2016 7:34] Daniël van Eeden
It can be useful to know if there are 70000 errors or 70015.
This happens if importing 70000 rows which all have one missing field or some other common error. The other way to solve this is to group by error number.

Note that changing it to this would at least make it tell the truth:
Query OK, 110380165 rows affected, >=65535 warnings (1 hour 41 min 38.07 sec)
Records: 110380165  Duplicates: 0  Warnings: 9155440

Having one action return multiple warning counts is odd, especially if they're not the same.

Or try to hide the wrong warning count in the client like this:
Query OK, (1 hour 41 min 38.07 sec) Records: 110380165  Duplicates: 0  Warnings: 9155440

Not sure if this would work correctly with multiple result sets etc.