dbsrgits / sql-translator

SQL::Translator (SQLFairy)
http://sqlfairy.sourceforge.net/
82 stars 90 forks source link

Remove size on floating point data types during MySQL field normalization #110

Open jpiautinity opened 6 years ago

jpiautinity commented 6 years ago

Summary: This merge request removes the forced 2 precision and 8 digits size limit for floating point number data types in the MySQL field normalization and instead force removes size for these data types.

Some unit tests are updated to reflect this change.

Reason for this change: While sane size limits are useful for fixed point data types like decimal such limits make little sense for floating point data types. Setting the size for floating point data types does not result in less storage being used but will just try to badly truncate the input and mask the output (or raise an error in strict mode on bad input).

For use cases where size restricted data is required or desired it is highly recommended to use fixed point data types as they don't have impression errors in their given number space as opposed to IEEE 754 floating point numbers (As an example: 0.1 and 0.2 are not directly representable as IEEE 754 number no matter how good the precision is). IEEE 754 floating point numbers are simply not designed for such use cases but to closer approximate natural numbers.

Being able to set size limits to floating point numbers can also encourage the use of bad practices like the classic case of money represented as floating point numbers.

Lastly, the MySQL documentation recommends not using precision and number of digits for maximum portability. https://dev.mysql.com/doc/refman/en/floating-point-types.html

codecov[bot] commented 6 years ago

Codecov Report

Merging #110 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #110      +/-   ##
==========================================
+ Coverage    21.5%   21.51%   +0.01%     
==========================================
  Files          71       71              
  Lines       19914    19917       +3     
  Branches     5728     5729       +1     
==========================================
+ Hits         4283     4286       +3     
- Misses      14922    14924       +2     
+ Partials      709      707       -2
Impacted Files Coverage Δ
lib/SQL/Translator/Parser/MySQL.pm 71.72% <100%> (-0.82%) :arrow_down:
lib/SQL/Translator/Producer/MySQL.pm 91.08% <0%> (+0.55%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 86c68a0...d19e2c6. Read the comment docs.