From eb36371ac3830b651b75d5ab05423f45002e6bf4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Nov 2006 15:02:33 +0100 Subject: [PATCH] #18487 UPDATE IGNORE not supported for unique constraint violation of non-primary key: call peek_index_rows --- mysql-test/r/ndb_update.result | 1 + mysql-test/t/ndb_update.test | 1 + sql/ha_ndbcluster.cc | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/mysql-test/r/ndb_update.result b/mysql-test/r/ndb_update.result index 52236bb0c3d..d75f82172ae 100644 --- a/mysql-test/r/ndb_update.result +++ b/mysql-test/r/ndb_update.result @@ -27,6 +27,7 @@ pk1 b c 4 1 1 UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4; ERROR 23000: Duplicate entry '' for key 0 +UPDATE IGNORE t1 set pk1 = 1, c = 2 where pk1 = 4; select * from t1 order by pk1; pk1 b c 0 0 0 diff --git a/mysql-test/t/ndb_update.test b/mysql-test/t/ndb_update.test index 5472dd95e9f..ebcc6995d74 100644 --- a/mysql-test/t/ndb_update.test +++ b/mysql-test/t/ndb_update.test @@ -29,6 +29,7 @@ UPDATE IGNORE t1 set pk1 = 4 where pk1 = 2; select * from t1 order by pk1; -- error 1062 UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4; +UPDATE IGNORE t1 set pk1 = 1, c = 2 where pk1 = 4; select * from t1 order by pk1; UPDATE t1 set pk1 = pk1 + 10; select * from t1 order by pk1; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 533f288fbce..b819a1bf5a4 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2387,6 +2387,21 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data) uint i; DBUG_ENTER("update_row"); + /* + * If IGNORE the ignore constraint violations on primary and unique keys + */ + if (m_ignore_dup_key) + { + int peek_res= peek_indexed_rows(new_data); + + if (!peek_res) + { + DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY); + } + if (peek_res != HA_ERR_KEY_NOT_FOUND) + DBUG_RETURN(peek_res); + } + statistic_increment(thd->status_var.ha_update_count, &LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) {