Bug #130 Replace reports wrong stats if done by SELECT from table.
Submitted: 7 Mar 2003 0:32 Modified: 28 Apr 2003 1:25
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.11 OS:
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[7 Mar 2003 0:32] Peter Zaitsev
Description:
The affected rows in a REPLACE statement is different when you do a 
'REPLACE INTO ... SELECT' statement compared to a 'REPLACE INTO tbl 
VALUES' statement.

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 4.0.11-gamma-max-nt-log |
+-------------------------+
1 row in set (0.00 sec)

mysql> replace into repl (id) values (1), (2);
Query OK, 4 rows affected (0.00 sec)
Records: 2  Duplicates: 2  Warnings: 0

mysql> replace into repl (id) select id from test;
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 2  Warnings: 0

mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

How to repeat:
CREATE TABLE test (
  id int(11) default NULL
) TYPE=MyISAM;

INSERT INTO test VALUES (1);
INSERT INTO test VALUES (2);

CREATE TABLE repl (
  id int(11) NOT NULL default '0',
  name char(10) default NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

INSERT INTO repl VALUES (1,NULL);
INSERT INTO repl VALUES (2,NULL);
INSERT INTO repl VALUES (3,'3');
INSERT INTO repl VALUES (4,'4');

replace into repl (id) values (1), (2);
replace into repl (id) select id from test;
[28 Apr 2003 1:25] Oleksandr Byelkin
--- 1.95/sql/sql_insert.cc      Sun Mar 16 16:28:28 2003 
+++ 1.96/sql/sql_insert.cc      Sat Apr 26 15:53:08 2003 
@@ -1392,7 +1392,7 @@ 
              thd->cuted_fields); 
     if (last_insert_id) 
       thd->insert_id(last_insert_id);          // For update log 
-    ::send_ok(&thd->net,info.copied,last_insert_id,buff); 
+    ::send_ok(&thd->net,info.copied+info.deleted,last_insert_id,buff); 
     mysql_update_log.write(thd,thd->query,thd->query_length); 
     return 0; 
   }