Skip to content

Commit

Permalink
bug: Failed to insert a null value to the composite primary key. #1374
Browse files Browse the repository at this point in the history
  • Loading branch information
wisehead committed Mar 10, 2023
1 parent c040c50 commit d97f39f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mysql-test/suite/tianmu/r/composite_primary_key.result
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 25 additions & 0 deletions mysql-test/suite/tianmu/t/composite_primary_key.test
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions storage/tianmu/index/rdb_meta_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(IndexInfoType::INDEX_INFO_VERSION_INITIAL)) {
key.write((const uchar *)field.data(), field.length());
Expand Down

0 comments on commit d97f39f

Please sign in to comment.