Unenumerbrated Note

Unenumerbrated

A colleague encountered perplexing MySQL query results in Workbench where a count on a filtered set returned zero despite individual rows showing matching values. For example, 'select * from payments where client_id=1234' showed successful=1 for all 12 rows, but 'select count(*) from payments where client_id=1234 and successful=1' returned 0. This issue was reproducible locally but queries in application code functioned correctly. After extensive troubleshooting, the root cause was identified: the 'successful' field was defined as an enum('0', '1'). MySQL treats enum values as strings internally, but allows querying by either their string value or their integer index. In this specific case, the string "0" had an integer index of 1, and the string "1" had an integer index of 2. Therefore, 'successful='1'' (string comparison) was distinct from 'successful=1' (integer comparison). MySQL typically performs silent conversions between strings and integers, adding to the confusion. The author primarily blamed the original field definition for using '0' and '1' as enum values instead of descriptive names like 'successful' and 'unsuccessful'. This specific database design quirk, though still in use, remains an isolated incident within the system.