Bug #66565 Insert into federated table
Submitted: 28 Aug 2012 6:46 Modified: 28 Aug 2012 9:01
Reporter: Alexey Nick Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Federated storage engine Severity:S2 (Serious)
Version:5.5.28 OS:Any
Assigned to: CPU Architecture:Any

[28 Aug 2012 6:46] Alexey Nick
Description:
if you insert into federated table "on duplicate key update" clause doesn't work and MySQL returns 
ERROR 1022 (23000): Can't write; duplicate key in table 'gt_places'

How to repeat:
CREATE TABLE `gt_places` (
  `dt` date NOT NULL,
  `place_id` int(10) unsigned NOT NULL,
  `cnt_exposure` int(10) NOT NULL,
  `cnt_load` int(10) NOT NULL,
  `cnt_click` int(10) NOT NULL,
  `amt_money` double NOT NULL,
  `event_type` enum('exp','click') NOT NULL DEFAULT 'click',
  PRIMARY KEY (`dt`,`place_id`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='test/gtd_places';

    drop temporary table if exists __places;
    create temporary table __places (
      `dt` date not null,
      `place_id` int(10) unsigned not null,
      `cnt_exposure` int(10) unsigned not null default '0',
      `cnt_load` int(10) unsigned not null default '0',
      `cnt_click` int(10) unsigned not null default '0',
      `amt_money` double(11,4) unsigned not null default '0.0000',
      `amt_money_conv` double(11,4) unsigned not null default '0.0000',
      `event_type` enum('exp','click') not null default 'click',
      primary key (`dt`, `place_id`)
    ) engine=innodb default charset=utf8;

insert into __places values
('2012-08-09', 4, 5, 5, 5, 333, 544, 'click');
    
    insert into gt_places (dt, place_id, cnt_exposure, cnt_load, cnt_click, amt_money, event_type) 
        select
            dt,
            place_id,
            cnt_exposure,
            cnt_load,
            cnt_click,
            amt_money,
            event_type
        from
            __places 
    on duplicate key update
        cnt_exposure = values(cnt_exposure),
        cnt_load = values(cnt_load),
        cnt_click = values(cnt_click),
        amt_money = values(amt_money)
    ;
[28 Aug 2012 9:01] Valeriy Kravchuk
This is a documented limitation, read http://dev.mysql.com/doc/refman/5.5/en/federated-usagenotes.html:

"FEDERATED accepts INSERT ... ON DUPLICATE KEY UPDATE statements, but if a duplicate-key violation occurs, the statement fails with an error."