python-mysql-replication icon indicating copy to clipboard operation
python-mysql-replication copied to clipboard

get wrong fsp value for time,datetime,timestamp(new date format)

Open dumingyou opened this issue 7 years ago • 4 comments

mysql server version: mysql5.6 schema:

CREATE TABLE `mytest` (
  `a` int(11) NOT NULL,
  `b` smallint(6) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  `d` mediumint(9) DEFAULT NULL,
  `y` float DEFAULT NULL,
  `x` double DEFAULT NULL,
  `e` varchar(100) DEFAULT NULL,
  `f` char(20) DEFAULT NULL,
  `g` text,
  `h` decimal(10,5) DEFAULT NULL,
  `i` time(2) DEFAULT NULL,
  `j` date DEFAULT NULL,
  `k` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `l` bigint(20) DEFAULT NULL,
  `m` year(4) DEFAULT NULL,
  `n` enum('a','b','c') DEFAULT NULL,
  `o` set('a','b','c') DEFAULT NULL,
  PRIMARY KEY (`a`),
  UNIQUE KEY `uk_bc` (`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

sql:

mysql> select * from mytest where a = 9;
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
| a | b    | c    | d    | y     | x    | e      | f     | g       | h        | i           | j          | k                       | l    | m    | n    | o    |
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
| 9 |   10 |   10 |   10 | 10.01 | 10.3 | aasfsd | 435ty | d3yzsaf | 10.22200 | 10:10:10.11 | 1999-01-01 | 2017-09-25 22:09:59.889 |  555 | 1990 | a    | a,b  |
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
1 row in set (0.00 sec)

mysql> update mytest set c=101 where a=9;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from mytest where a = 9;
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
| a | b    | c    | d    | y     | x    | e      | f     | g       | h        | i           | j          | k                       | l    | m    | n    | o    |
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
| 9 |   10 |  101 |   10 | 10.01 | 10.3 | aasfsd | 435ty | d3yzsaf | 10.22200 | 10:10:10.11 | 1999-01-01 | 2017-09-25 22:19:43.102 |  555 | 1990 | a    | a,b  |
+---+------+------+------+-------+------+--------+-------+---------+----------+-------------+------------+-------------------------+------+------+------+------+
1 row in set (0.00 sec)

result:

=== UpdateRowsEvent ===
Date: 2017-09-25T22:19:43
Log position: 1793388
Event size: 179
Read bytes: 17
Table: dmy2.mytest
Affected columns: 17
Changed rows: 1
Affected columns: 17
Values:
--
*a:9=>9
*c:10=>101
*b:10=>10
*e:aasfsd=>aasfsd
*d:10=>10
*g:d3yzsaf=>d3yzsaf
*f:435ty=>435ty
*i:10:10:10.000011=>10:10:10.000011
*h:10.22200=>10.22200
*k:2017-09-25 22:09:59.000889=>2017-09-25 22:19:43.000102
*j:1999-01-01=>1999-01-01
*m:1990=>1990
*l:555=>555
*o:set([u'a', u'b'])=>set([u'a', u'b'])
*n:a=>a
*y:10.0100002289=>10.0100002289
*x:10.3=>10.3

see column i k , it's a wrong value

dumingyou avatar Sep 25 '17 14:09 dumingyou

(reformated issue for readability)

baloo avatar Sep 25 '17 17:09 baloo

The problem is float precision. Feel free to provide a PR for that.

baloo avatar Sep 25 '17 17:09 baloo

@dumingyou @baloo @alex @dreid @chaoslawful row_event.py about 200 line modify code to:

201     def __read_fsp(self, column):       
202         read = 0           
203         if column.fsp == 1 or column.fsp == 2:
204             read = 1       
205         elif column.fsp == 3 or column.fsp == 4: 
206             read = 2       
207         elif column.fsp == 5 or column.fsp == 6: 
208             read = 3       
209         if read > 0:       
210             microsecond = self.packet.read_int_be_by_size(read)
211   
212             if column.fsp == 1: microsecond *= 100000
213             elif column.fsp == 2: microsecond *= 10000
214             elif column.fsp == 3: microsecond *= 1000
215             elif column.fsp == 4: microsecond *= 100
216             elif column.fsp == 5: microsecond *= 10
217 
218             if column.fsp % 2:
219                 return int(microsecond / 10)
220             else:
221                 return microsecond      
222 
223         return 0

daiguadaidai avatar Dec 11 '17 15:12 daiguadaidai

meet same problem, have provided a pr #269

danfengcao avatar May 29 '18 09:05 danfengcao