Bug #88738 Missing vital error information in error message when failing to convert charset
Submitted: 3 Dec 2017 16:47 Modified: 3 Oct 2018 2:09
Reporter: teo teo Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Errors Severity:S4 (Feature request)
Version:5.7, 8.0 OS:Any
Assigned to: CPU Architecture:Any

[3 Dec 2017 16:47] teo teo
Description:
When executing a query like 
  ALTER TABLE `mytable` CONVERT TO CHARACTER SET whatever_charset

if the conversion causes an increase in the size of a column and there is an index on that column, if the new required size exceeds the maximum allowed for the index, you get this idiotic error message:

"Specified key was too long; max key length is 767 bytes"

This error message makes no sense in this context ("specified key", when there is no specified key) and lacks the most basic information:
- at the very least WHAT KEY is being affected
- also what column(s) have failed to be resized.

Obviously that error message was written with a specific use case in mind, without taking into account the whole range of cases where it is actually used.

This is just one of many error messages in MySQL that are very poorly phrased (or make sense only for a subset of the cases where they are used) and lack the most basic information you expect from a decent error message.

How to repeat:
CREATE TABLE `mytable` (
  `id` int(10) unsigned NOT NULL DEFAULT '0',
  `somefield` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`,`somefield`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE mytable CONVERT TO CHARACTER SET utf8mb4

Suggested fix:
The error message in this case should be something to the extent of:

"Cannot change column `somefield` to VARCHAR(333) because the resulting size of key `PRIMARY` would exceed the max key length of 767 bytes"
[14 Feb 2018 14:06] MySQL Verification Team
Hi,

Thank you for your bug report. I have got the same error message and I have had such messages many times.

I agree with you that this is not
[14 Feb 2018 14:08] MySQL Verification Team
Sorry, I have pressed a key too fast.

Thank you for your bug report. I have got the same error message and I have had such messages many times.

I agree with you that this is not a verbose and fully clear error message and hence, I am verifying this report as a feature request.
[14 Feb 2018 15:01] teo teo
Thank you for verifying.

However, this is a bug, not a feature request.
[3 Oct 2018 2:09] Paul DuBois
Posted by developer:
 
Fixed in 8.0.14.

The error message for ALTER TABLE statements that attempted character
set conversion but failed was improved to indicate which column
produced the error.