go-mysql-server icon indicating copy to clipboard operation
go-mysql-server copied to clipboard

Number length

Open Wuvist opened this issue 3 years ago • 4 comments

Currently consider TINYINT as a synonym to Boolean, and doesn't store length info for all number types.

IHMO, a tinyint column is only consider as boolean when specified as tinyint(1), and better treat as int8 when specified like tinyint(4).

And, it's better to length info for number types, as it's also required for be consistent with mysql's show create table and information_schema usage as well.

Nonetheless, my PR only contains handling for length info for tinyint.

Wuvist avatar Aug 14 '22 14:08 Wuvist

Thanks for the contribution, but I don't think we want to concern the library with display widths, as they are deprecated in the current version of MySQL:

https://dev.mysql.com/doc/refman/8.0/en/numeric-type-attributes.html

Can you describe your use case that would make these necessary?

zachmu avatar Aug 16 '22 18:08 zachmu

Thanks for the contribution, but I don't think we want to concern the library with display widths, as they are deprecated in the current version of MySQL:

https://dev.mysql.com/doc/refman/8.0/en/numeric-type-attributes.html

Can you describe your use case that would make these necessary?

As https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html stats:

BOOL, BOOLEAN

These types are synonyms for [TINYINT(1)](https://dev.mysql.com/doc/refman/8.0/en/integer-types.html).

Length information is needed to determine if a tinyint column is used as bool or int8.

Wuvist avatar Aug 17 '22 06:08 Wuvist

I agree this is how MySQL works right now, but it's officially unsupported and will not work in the future. For that reason we are not going to add it to the engine -- we would just need to remove it when MySQL does to retain compatibility.

As of MySQL 8.0.17, the ZEROFILL attribute is deprecated for numeric data types, as is the display width attribute for integer data types. You should expect support for ZEROFILL and display widths for integer data types to be removed in a future version of MySQL. Consider using an alternative means of producing the effect of these attributes. For example, applications can use the LPAD() function to zero-pad numbers up to the desired width, or they can store the formatted numbers in CHAR columns.

zachmu avatar Aug 17 '22 16:08 zachmu

Understand, or it's possible to make it a feature flag when future mysql release?

Legacy & compatibility issue is always a headache.


I'm actually working on a go ORM lib and use go-mysql-server for unit testing. The ORM will read schema from db(In the case of my unit testing, it reads schema from go-mysql-server) and generate go code. It will need display width for tinyint info to decide whether generate bool or int8 field.

I will really wish that my team to either use tinyint only for bool or only for int8, but there are just too many legacy codes use both way.

Wuvist avatar Aug 17 '22 17:08 Wuvist

Closing this older PR to tidy up our queue since we decided not to take this change.

@Wuvist – thank you for being a customer of go-mysql-server and for engaging us in this discussion! 🙏 Please don't hesitate to ping us again here or on Discord if you have feedback/suggestions/questions for go-mysql-server or dolt.

fulghum avatar Dec 08 '22 18:12 fulghum