Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(index): Failed to insert a null value to the composite primary key. #1374 #1377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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