Skip to content

Commit

Permalink
fix(tianmu): default value of the field take unaffect in load #1865
Browse files Browse the repository at this point in the history
Cause:
  in the function ParsingStrategy::ParseResult ParsingStrategy::GetOneRow
field->val_str(str) cannot distinguish 0 and NULL value.
Solution:
  Check whether field's default value is NULL.
  • Loading branch information
Double0101 committed Jun 19, 2023
1 parent c990b5f commit d096d0f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
28 changes: 28 additions & 0 deletions mysql-test/suite/tianmu/r/issue1865.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DROP DATABASE IF EXISTS issue1865_test_db;
CREATE DATABASE issue1865_test_db;
create table t1 (a int default 100, b int, c varchar(60))engine=tianmu;
load data infile 'MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;
a b c
NULL NULL 10
NULL NULL 15
alter table t1 alter column b drop default;
alter table t1 alter column b set default 10;
load data infile 'MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;
a b c
NULL NULL 10
NULL NULL 15
NULL 10 10
NULL 10 15
alter table t1 modify c text;
load data infile 'MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;
a b c
NULL NULL 10
NULL NULL 15
NULL 10 10
NULL 10 15
NULL 10 10
NULL 10 15
DROP DATABASE issue1865_test_db;
2 changes: 2 additions & 0 deletions mysql-test/suite/tianmu/std_data/issue1865.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\N 10
\N 15
27 changes: 27 additions & 0 deletions mysql-test/suite/tianmu/t/issue1865.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS issue1865_test_db;
--enable_warnings

CREATE DATABASE issue1865_test_db;

create table t1 (a int default 100, b int, c varchar(60))engine=tianmu;

--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval load data infile '$MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;

alter table t1 alter column b drop default;
alter table t1 alter column b set default 10;

--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval load data infile '$MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;

alter table t1 modify c text;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval load data infile '$MYSQL_TEST_DIR/suite/tianmu/std_data/issue1865.dat' into table t1 (a, c);
select * from t1;

DROP DATABASE issue1865_test_db;
9 changes: 6 additions & 3 deletions storage/tianmu/loader/parsing_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,12 @@ ParsingStrategy::ParseResult ParsingStrategy::GetOneRow(const char *const buf, s
if (!first_row_prepared_) {
std::string field_name(field->field_name);

str = new (thd_->mem_root) String(MAX_FIELD_WIDTH);
String *res = field->val_str(str);
DEBUG_ASSERT(res);
str = new (thd_->mem_root) String();
if (!field->is_null()) {
str->real_alloc(MAX_FIELD_WIDTH);
String *res = field->val_str(str);
DEBUG_ASSERT(res);
}
vec_field_Str_list_.push_back(str);
vec_field_num_to_index_.push_back(0);
map_field_name_to_index_[field_name] = i;
Expand Down

0 comments on commit d096d0f

Please sign in to comment.