From 69b9ed063b78d2bf28ec0a4823e0b0317fce2c4d Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 25 Jun 2018 18:16:29 +0530 Subject: [PATCH] MDEV-16365 Setting a column NOT NULL fails to return error for NULL values when there is no DEFAULT - Post push fix for adding n_rows in row_log_t. --- .../innodb/r/alter_non_null_debug,STRICT.rdiff | 4 ---- .../suite/innodb/r/alter_non_null_debug.result | 2 +- storage/innobase/row/row0log.cc | 17 +++++++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mysql-test/suite/innodb/r/alter_non_null_debug,STRICT.rdiff b/mysql-test/suite/innodb/r/alter_non_null_debug,STRICT.rdiff index 2865c5d7f71..09c717c44b0 100644 --- a/mysql-test/suite/innodb/r/alter_non_null_debug,STRICT.rdiff +++ b/mysql-test/suite/innodb/r/alter_non_null_debug,STRICT.rdiff @@ -9,7 +9,3 @@ < 2 0 --- > 2 NULL -71c68 -< Warning 1265 Data truncated for column 'c2' at row 7 ---- -> Warning 1265 Data truncated for column 'c2' at row 6 diff --git a/mysql-test/suite/innodb/r/alter_non_null_debug.result b/mysql-test/suite/innodb/r/alter_non_null_debug.result index e4c42241f5d..c12f1fbca3d 100644 --- a/mysql-test/suite/innodb/r/alter_non_null_debug.result +++ b/mysql-test/suite/innodb/r/alter_non_null_debug.result @@ -68,7 +68,7 @@ connection default; affected rows: 0 info: Records: 0 Duplicates: 0 Warnings: 1 Warnings: -Warning 1265 Data truncated for column 'c2' at row 7 +Warning 1265 Data truncated for column 'c2' at row 3 SELECT * FROM t1; c1 c2 c3 1 2 3 diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index ebd15ab5020..2dc5c0a5705 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -233,6 +233,7 @@ struct row_log_t { defaults */ const TABLE* old_table; /*< Use old table in case of error. */ + uint64_t n_rows; /*< Number of rows read from the table */ /** Determine whether the log should be in the 'instant ADD' format @param[in] index the clustered index of the source table @return whether to use the 'instant ADD COLUMN' format */ @@ -1483,16 +1484,15 @@ row_log_table_apply_convert_mrec( const mrec_t* mrec, /*!< in: merge record */ dict_index_t* index, /*!< in: index of mrec */ const ulint* offsets, /*!< in: offsets of mrec */ - const row_log_t* log, /*!< in: rebuild context */ + row_log_t* log, /*!< in: rebuild context */ mem_heap_t* heap, /*!< in/out: memory heap */ dberr_t* error) /*!< out: DB_SUCCESS or DB_MISSING_HISTORY or reason of failure */ { dtuple_t* row; - static ulong n_rows = index->table->stat_n_rows; - n_rows++; + log->n_rows++; *error = DB_SUCCESS; /* This is based on row_build(). */ @@ -1624,7 +1624,7 @@ blob_done: Field* field = log->old_table->field[col_no]; field->set_warning(Sql_condition::WARN_LEVEL_WARN, - WARN_DATA_TRUNCATED, 1, n_rows); + WARN_DATA_TRUNCATED, 1, log->n_rows); if (!log->allow_not_null) { /* We got a NULL value for a NOT NULL column. */ @@ -1736,7 +1736,7 @@ row_log_table_apply_insert( row_merge_dup_t* dup) /*!< in/out: for reporting duplicate key errors */ { - const row_log_t*log = dup->index->online_log; + row_log_t*log = dup->index->online_log; dberr_t error; const dtuple_t* row = row_log_table_apply_convert_mrec( mrec, dup->index, offsets, log, heap, &error); @@ -2007,7 +2007,7 @@ row_log_table_apply_update( of the old value, or PRIMARY KEY if same_pk */ { - const row_log_t*log = dup->index->online_log; + row_log_t* log = dup->index->online_log; const dtuple_t* row; dict_index_t* index = dict_table_get_first_index(log->table); mtr_t mtr; @@ -3072,6 +3072,10 @@ row_log_table_apply( ut_ad(!rw_lock_own(dict_operation_lock, RW_LOCK_S)); clust_index = dict_table_get_first_index(old_table); + if (clust_index->online_log->n_rows == 0) { + clust_index->online_log->n_rows = old_table->stat_n_rows; + } + rw_lock_x_lock(dict_index_get_lock(clust_index)); if (!clust_index->online_log) { @@ -3166,6 +3170,7 @@ row_log_allocate( ut_ad(!table || log->is_instant(index) == index->is_instant()); log->allow_not_null = allow_not_null; log->old_table = old_table; + log->n_rows = 0; dict_index_set_online_status(index, ONLINE_INDEX_CREATION); index->online_log = log;