diff --git a/mysql-test/suite/tianmu/r/composite_primary_key.result b/mysql-test/suite/tianmu/r/composite_primary_key.result new file mode 100644 index 000000000..de7810415 --- /dev/null +++ b/mysql-test/suite/tianmu/r/composite_primary_key.result @@ -0,0 +1,9 @@ +DROP DATABASE IF EXISTS composite_primary_key_test; +CREATE DATABASE composite_primary_key_test; +USE composite_primary_key_test; +create table ttt(id int,c1 varchar(10),c2 varchar(10),primary key(id,c1)) ENGINE=TIANMU; +insert into ttt values(1,'xxx','xxx'); +insert into ttt values(1,'','xxx'); +insert into ttt values(1,'','xxx'); +ERROR 23000: Duplicate entry '1-' for key 'PRIMARY' +DROP DATABASE composite_primary_key_test; diff --git a/mysql-test/suite/tianmu/t/composite_primary_key.test b/mysql-test/suite/tianmu/t/composite_primary_key.test new file mode 100644 index 000000000..dc6c782ad --- /dev/null +++ b/mysql-test/suite/tianmu/t/composite_primary_key.test @@ -0,0 +1,25 @@ +--source include/have_tianmu.inc + +--disable_warnings +DROP DATABASE IF EXISTS composite_primary_key_test; +--enable_warnings + +CREATE DATABASE composite_primary_key_test; + +USE composite_primary_key_test; + +--disable_warnings + +## DDL +create table ttt(id int,c1 varchar(10),c2 varchar(10),primary key(id,c1)) ENGINE=TIANMU; + +## insert data +insert into ttt values(1,'xxx','xxx'); + +insert into ttt values(1,'','xxx'); +--error ER_DUP_ENTRY +insert into ttt values(1,'','xxx'); + + +## clean test table +DROP DATABASE composite_primary_key_test; diff --git a/storage/tianmu/index/rdb_meta_manager.cpp b/storage/tianmu/index/rdb_meta_manager.cpp index df1183800..54b78a38c 100644 --- a/storage/tianmu/index/rdb_meta_manager.cpp +++ b/storage/tianmu/index/rdb_meta_manager.cpp @@ -127,6 +127,10 @@ common::ErrorCode RdbKey::unpack_field_number(StringReader &key, std::string &fi } void RdbKey::pack_field_string(StringWriter &info, StringWriter &key, std::string &field) { + // issue1374: bug: Failed to insert a null value to the composite primary key. + // the empty field of primary key will be ignored. + if (field.length() == 0) + return; // version compatible if (index_ver_ == static_cast(IndexInfoType::INDEX_INFO_VERSION_INITIAL)) { key.write((const uchar *)field.data(), field.length());