Description:
Under sql_mode='strict_all_tables', LOAD DATA with more columns in data file will lead to error under 5.6.26, but just warning under 5.7.10.
How to repeat:
use test
drop table if exists t1;
create table t1(c1 varchar(10), c2 varchar(10), c3 varchar(10));
insert into t1 values('aaaaa', 'bbbbb', 'cccccc');
select * from t1 into outfile '/tmp/datafile' FIELDS TERMINATED BY ',';
drop table if exists t2;
create table t2(c1 varchar(10));
set sql_mode='strict_all_tables';
load data infile '/tmp/datafile' into table t2 fields terminated by ',';
Suggested fix:
I see the Strict_error_handler::handle_condition in 5.7:
switch (sql_errno)
{
case ER_TRUNCATED_WRONG_VALUE:
case ER_WRONG_VALUE_FOR_TYPE:
case ER_WARN_DATA_OUT_OF_RANGE:
case ER_DIVISION_BY_ZERO:
case ER_TRUNCATED_WRONG_VALUE_FOR_FIELD:
case WARN_DATA_TRUNCATED:
case ER_DATA_TOO_LONG:
case ER_BAD_NULL_ERROR:
case ER_NO_DEFAULT_FOR_FIELD:
case ER_TOO_LONG_KEY:
case ER_NO_DEFAULT_FOR_VIEW_FIELD:
case ER_WARN_NULL_TO_NOTNULL:
case ER_CUT_VALUE_GROUP_CONCAT:
case ER_DATETIME_FUNCTION_OVERFLOW:
case ER_WARN_TOO_FEW_RECORDS:
case ER_INVALID_ARGUMENT_FOR_LOGARITHM:
case ER_NUMERIC_JSON_VALUE_OUT_OF_RANGE:
case ER_INVALID_JSON_VALUE_FOR_CAST:
case ER_WARN_ALLOWED_PACKET_OVERFLOWED:
if ((*level == Sql_condition::SL_WARNING) &&
(!thd->get_transaction()->cannot_safely_rollback(Transaction_ctx::STMT)
|| (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES)))
{
(*level)= Sql_condition::SL_ERROR;
thd->killed= THD::KILL_BAD_DATA;
}
break;
The code above just can handle ER_WARN_TOO_FEW_RECORDS, which means too few columns in the data file, but not handle ER_WARN_TOO_MANY_RECORDS.
Description: Under sql_mode='strict_all_tables', LOAD DATA with more columns in data file will lead to error under 5.6.26, but just warning under 5.7.10. How to repeat: use test drop table if exists t1; create table t1(c1 varchar(10), c2 varchar(10), c3 varchar(10)); insert into t1 values('aaaaa', 'bbbbb', 'cccccc'); select * from t1 into outfile '/tmp/datafile' FIELDS TERMINATED BY ','; drop table if exists t2; create table t2(c1 varchar(10)); set sql_mode='strict_all_tables'; load data infile '/tmp/datafile' into table t2 fields terminated by ','; Suggested fix: I see the Strict_error_handler::handle_condition in 5.7: switch (sql_errno) { case ER_TRUNCATED_WRONG_VALUE: case ER_WRONG_VALUE_FOR_TYPE: case ER_WARN_DATA_OUT_OF_RANGE: case ER_DIVISION_BY_ZERO: case ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: case WARN_DATA_TRUNCATED: case ER_DATA_TOO_LONG: case ER_BAD_NULL_ERROR: case ER_NO_DEFAULT_FOR_FIELD: case ER_TOO_LONG_KEY: case ER_NO_DEFAULT_FOR_VIEW_FIELD: case ER_WARN_NULL_TO_NOTNULL: case ER_CUT_VALUE_GROUP_CONCAT: case ER_DATETIME_FUNCTION_OVERFLOW: case ER_WARN_TOO_FEW_RECORDS: case ER_INVALID_ARGUMENT_FOR_LOGARITHM: case ER_NUMERIC_JSON_VALUE_OUT_OF_RANGE: case ER_INVALID_JSON_VALUE_FOR_CAST: case ER_WARN_ALLOWED_PACKET_OVERFLOWED: if ((*level == Sql_condition::SL_WARNING) && (!thd->get_transaction()->cannot_safely_rollback(Transaction_ctx::STMT) || (thd->variables.sql_mode & MODE_STRICT_ALL_TABLES))) { (*level)= Sql_condition::SL_ERROR; thd->killed= THD::KILL_BAD_DATA; } break; The code above just can handle ER_WARN_TOO_FEW_RECORDS, which means too few columns in the data file, but not handle ER_WARN_TOO_MANY_RECORDS.