From 9ee5406e2f3ab338e15d23997039b2c95cc5762a Mon Sep 17 00:00:00 2001 From: Sachin Setiya Date: Thu, 26 Apr 2018 16:49:27 +0530 Subject: [PATCH] MDEV-15965 Invisible columns and LOAD DATA don't work well together:... ER_WARN_TOO_FEW_RECORDS Fix mysql_load iterator to skip invisible fields. --- mysql-test/main/invisible_field.result | 61 ++++++++++++++++++++++++++ mysql-test/main/invisible_field.test | 25 +++++++++++ sql/sql_load.cc | 3 ++ 3 files changed, 89 insertions(+) diff --git a/mysql-test/main/invisible_field.result b/mysql-test/main/invisible_field.result index 5cea77f5b0c..876a80814e5 100644 --- a/mysql-test/main/invisible_field.result +++ b/mysql-test/main/invisible_field.result @@ -556,3 +556,64 @@ INSERT INTO t1 (c,t) VALUES ('foo','2000-01-01 00:00:00'); CREATE TRIGGER tr BEFORE INSERT ON t1 FOR EACH ROW SET @a= 1; INSERT INTO t1 SELECT * FROM t1; DROP TABLE t1; +create or replace table t1 (a int, b int invisible); +insert into t1 values (1),(2); +select * from t1 into outfile 'f'; +load data infile 'f' into table t1; +select a,b from t1; +a b +1 NULL +2 NULL +1 NULL +2 NULL +load data infile 'f' into table t1 (a,@v) SET b=@v; +select a,b from t1; +a b +1 NULL +2 NULL +1 NULL +2 NULL +1 NULL +2 NULL +load data infile 'f' into table t1 (a,@v) SET b=a; +select a,b from t1; +a b +1 NULL +2 NULL +1 NULL +2 NULL +1 NULL +2 NULL +1 1 +2 2 +truncate table t1; +insert into t1(a,b) values (1,1),(2,2); +select a,b from t1 into outfile 'a'; +load data infile 'a' into table t1(a,b); +select a,b from t1; +a b +1 1 +2 2 +1 1 +2 2 +load data infile 'a' into table t1 (a,@v) SET b=@v; +select a,b from t1; +a b +1 1 +2 2 +1 1 +2 2 +1 1 +2 2 +load data infile 'a' into table t1 (a,@v) SET b=@v+2; +select a,b from t1; +a b +1 1 +2 2 +1 1 +2 2 +1 1 +2 2 +1 3 +2 4 +drop table t1; diff --git a/mysql-test/main/invisible_field.test b/mysql-test/main/invisible_field.test index cfe89d77230..0e3994a78ce 100644 --- a/mysql-test/main/invisible_field.test +++ b/mysql-test/main/invisible_field.test @@ -246,3 +246,28 @@ CREATE TRIGGER tr BEFORE INSERT ON t1 FOR EACH ROW SET @a= 1; INSERT INTO t1 SELECT * FROM t1; # Cleanup DROP TABLE t1; +##LOAD DATA MDEV-15965 Invisible columns and LOAD DATA don't work well +## together: ER_WARN_TOO_FEW_RECORDS +create or replace table t1 (a int, b int invisible); +insert into t1 values (1),(2); + +select * from t1 into outfile 'f'; +load data infile 'f' into table t1; +select a,b from t1; +load data infile 'f' into table t1 (a,@v) SET b=@v; +select a,b from t1; +load data infile 'f' into table t1 (a,@v) SET b=a; +select a,b from t1; +truncate table t1; + +insert into t1(a,b) values (1,1),(2,2); +select a,b from t1 into outfile 'a'; +load data infile 'a' into table t1(a,b); +select a,b from t1; +load data infile 'a' into table t1 (a,@v) SET b=@v; +select a,b from t1; +load data infile 'a' into table t1 (a,@v) SET b=@v+2; +select a,b from t1; + +#cleanup +drop table t1; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 3194ca5bcd9..cc5a5c7c794 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -444,6 +444,9 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list, field_iterator.set(table_list); for (; !field_iterator.end_of_fields(); field_iterator.next()) { + if (field_iterator.field() && + field_iterator.field()->invisible > VISIBLE) + continue; Item *item; if (!(item= field_iterator.create_item(thd))) DBUG_RETURN(TRUE);