Bug #105667 TINYINT display length is dropped when set to UNSIGNED
Submitted: 22 Nov 2021 20:54 Modified: 23 Nov 2021 4:49
Reporter: Gary Cartagena Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:8.0.27 OS:Ubuntu (20 LTS)
Assigned to: CPU Architecture:x86
Tags: DISPLAY LENGTH, INTEGER, regression, UNSIGNED

[22 Nov 2021 20:54] Gary Cartagena
Description:
Setting the Unsigned attribute overrides the field display length.
For example:  I can do the following: 

    ALTER TABLE `users` 
    CHANGE COLUMN `is_active` `is_active` TINYINT(1) NOT NULL DEFAULT '1' ;

and the table correctly sets the field display length. But if I do this:

    ALTER TABLE `users` 
    CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ;

The field length is no longer set. 

when I set TINYINT(1) UNSIGNED, the display length is dropped. 

How to repeat:
STR:
1. Create a table with a field intended to be used as a BOOLEAN;
CREATE TABLE `users` (
  `id` int unsigned NOT NULL AUTO_INCREMENT ,
  `user_name` varchar(50) NOT NULL,
  `password` varchar(255) NOT NULL,
  `is_active` tinyint(1)  NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

2. Observe that the display length on TINYINT(1) is in fact set.
3. Alter the table to make is_active an UNSIGNED value:
ALTER TABLE `users` 
 CHANGE COLUMN `is_active` `is_active` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ;

4. Observe that TINYINT no longer has a display length.

Suggested fix:
I argue that the correct field attribute for a "BOOLEAN" would be unsigned since your options would be 0 or 1. Not negatives. Therefore I would expect that the UNSIGNED behavior for TINYINT(1) be identical to the signed behavior, and field display length would be set / retained.
[23 Nov 2021 4:49] MySQL Verification Team
Hello Gary Cartagena,

Thank you for the report and test case.

regards,
Umesh