From 6b20342651bb5207b6c125d2d11b664a1bebcc41 Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 18 Aug 2015 00:42:08 +0300 Subject: Ensure that fields declared with NOT NULL doesn't have DEFAULT values if not specified and if not timestamp or auto_increment In original code, sometimes one got an automatic DEFAULT value in some cases, in other cases not. For example: create table t1 (a int primary key) - No default create table t2 (a int, primary key(a)) - DEFAULT 0 create table t1 SELECT .... - Default for all fields, even if they where defined as NOT NULL ALTER TABLE ... MODIFY could sometimes add an unexpected DEFAULT value. The patch is quite big because we had some many test cases that used CREATE ... SELECT or CREATE ... (...PRIMARY KEY(xxx)) which doesn't have an automatic DEFAULT anymore. Other things: - Removed warnings from InnoDB when waiting from semaphore (got this when testing things with --big) --- sql/field.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'sql/field.cc') diff --git a/sql/field.cc b/sql/field.cc index 6ca0d4a7d63..5d45a8d39d1 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -9463,14 +9463,6 @@ bool Create_field::check(THD *thd) sql_type= vcol_info->get_real_type(); } - /* - Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and - it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP. - */ - if (!def && unireg_check == Field::NONE && - (flags & NOT_NULL_FLAG) && !is_timestamp_type(sql_type)) - flags|= NO_DEFAULT_VALUE_FLAG; - sign_len= flags & UNSIGNED_FLAG ? 0 : 1; switch (sql_type) { @@ -9663,6 +9655,16 @@ bool Create_field::check(THD *thd) /* Remember the value of length */ char_length= length; + /* + Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and + it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP. + We need to do this check here and in mysql_create_prepare_table() as + sp_head::fill_field_definition() calls this function. + */ + if (!def && unireg_check == Field::NONE && + (flags & NOT_NULL_FLAG) && !is_timestamp_type(sql_type)) + flags|= NO_DEFAULT_VALUE_FLAG; + if (!(flags & BLOB_FLAG) && ((length > max_field_charlength && (sql_type != MYSQL_TYPE_VARCHAR || def)) || -- cgit v1.2.1