[MDEV-8924] mysqldump restores a negative zero as a positive zero Created: 2015-10-09 Updated: 2017-01-09 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Scripts & Clients |
| Affects Version/s: | 5.1.67, 5.2.14, 5.3.12, 5.5, 10.0, 10.1 |
| Fix Version/s: | 10.1 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Peter (Stig) Edwards | Assignee: | Alexander Barkov |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | upstream | ||
| Description |
|
Hello and thank you for MariaDB, While importing a database using mysqldump, I noticed table checksums were not the same, a diff on the mysqldump showed that negative zero values in a double field were represented as -0 in the mysqldump which was being imported as positive zero when the mysqldump was run using the mysql client. If I add the following to mysql-test/t/mysqldump_restore.test , notice to obtain a negative zero I enclose it in quotes:
and then run:
I suspect in the case of the data being worked on that the negative zero was written as a string in error, and had it been numeric then it would have been stored as positive zero and we would have not seen a difference between the original and restored data. I am not sure if test_if_special_chars in client/mysqldump.c could return 1 if passed "-0", or if INSERT -0 should be expected to store a negative zero. Thank you. |
| Comments |
| Comment by Elena Stepanova [ 2015-10-21 ] | |||||||||||||||
|
Found here another way to get the same problem, which does not involve representing numbers as strings:
The rest is the same: mysqldump converts it into INSERT INTO `t1` VALUES (0),(-0) and after restore we get positive zeros. | |||||||||||||||
| Comment by Elena Stepanova [ 2015-10-21 ] | |||||||||||||||
|
It is reproducible with upstream versions, including MySQL 5.7. I found a somewhat related bug report Bug #67529 GROUP BY treats +0 and -0 as different values, but nothing closer than that. | |||||||||||||||
| Comment by Elena Stepanova [ 2015-10-21 ] | |||||||||||||||
|
bar, could you please take a look at it, decide what's the best course of actions here, and re-report it to MySQL if needed (unless thatsafunnyname has already done it or is planning to do)? | |||||||||||||||
| Comment by Peter (Stig) Edwards [ 2015-10-21 ] | |||||||||||||||
|
I have not reported the bug to MySQL. I was wondering if because of https://dev.mysql.com/doc/refman/5.5/en/problems-with-float.html : "A floating-point value as written in an SQL statement may not be the same as the value represented internally. Attempts to treat floating-point values as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. The FLOAT and DOUBLE data types are subject to these issues." it would be deemed "not a bug", similar to https://bugs.mysql.com/bug.php?id=43262 - "Float values lose precision when dumped out and reloaded" and https://bugs.launchpad.net/maria/+bug/714419 - "Replication failures with slave provisioning via mysqldump and tables with no PK" One could argue the documentation for mysqldump could mention such potential problems. From a pragmatic point of view, the behaviour alerted us to -0 DOUBLE values, which were changed to 0. If the -0 values had been preserved between dump and load, it would have saved me some time from looking into why the table checksums differed. I am guessing the universe of usage of DOUBLE -0 and mysqldump and load and table checksums is very small, and within that universe the deliberate usage of DOUBLE -0 is even smaller. I am thinking it would be desirable for any fix for this UPDATE. Also see: .) The --lossless-fp option added by Justin Tolmer (at the time of Google) to mysqldump at https://code.google.com/p/google-mysql , along with the IEEE754_TO_STRING function, this contains tests for -0e0 and +0e0 being inserted into a DOUBLE. I do not see a DOUBLE -0 test in server/mysql-test/t/type_float.test http://www.exploringbinary.com/gays-strtod-returns-zero-for-inputs-just-above-2-1075/ 20131122 | |||||||||||||||
| Comment by Hartmut Holzgraefe [ 2017-01-09 ] | |||||||||||||||
|
So we have two different questions here:
The implementation of "let mysqldump quote negative zeros" would be simple:
| |||||||||||||||
| Comment by Hartmut Holzgraefe [ 2017-01-09 ] | |||||||||||||||
|
Side note: "What would PostgreSQL do?" PostgreSQL also interprets -0 as 0, but the string form '-0' as -0 Also pg_dump restores correctly in default mode that uses COPY, but fails the same way as mysqldump when being forced to use INSERT statements by the --column-inserts option. |