diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 1 | ||||
-rw-r--r-- | sql/field.h | 4 | ||||
-rw-r--r-- | sql/sql_table.cc | 8 | ||||
-rw-r--r-- | sql/sql_type.cc | 13 | ||||
-rw-r--r-- | sql/sql_type.h | 6 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 7 |
6 files changed, 14 insertions, 25 deletions
diff --git a/sql/field.cc b/sql/field.cc index f3a89a653e4..3d6eaba6f73 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10801,6 +10801,7 @@ Column_definition::Column_definition(THD *thd, Field *old_field, comment= old_field->comment; vcol_info= old_field->vcol_info; option_list= old_field->option_list; + explicitly_nullable= !(old_field->flags & NOT_NULL_FLAG); compression_method_ptr= 0; versioning= VERSIONING_NOT_SET; invisible= old_field->invisible; diff --git a/sql/field.h b/sql/field.h index 31a0256cc2f..8b7c6d6a554 100644 --- a/sql/field.h +++ b/sql/field.h @@ -5262,7 +5262,7 @@ public: uint flags, pack_length; List<String> interval_list; engine_option_value *option_list; - + bool explicitly_nullable; /* This is additinal data provided for any computed(virtual) field. @@ -5284,7 +5284,7 @@ public: comment(null_clex_str), on_update(NULL), invisible(VISIBLE), char_length(0), flags(0), pack_length(0), - option_list(NULL), + option_list(NULL), explicitly_nullable(false), vcol_info(0), default_value(0), check_constraint(0), versioning(VERSIONING_NOT_SET), period(NULL) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0ba755f49b9..f6aae1af8e9 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3133,13 +3133,17 @@ bool Column_definition::prepare_stage2(handler *file, void promote_first_timestamp_column(List<Create_field> *column_definitions) { + bool first= true; for (Create_field &column_definition : *column_definitions) { if (column_definition.is_timestamp_type() || // TIMESTAMP column_definition.unireg_check == Field::TIMESTAMP_OLD_FIELD) // Legacy { + if (!column_definition.explicitly_nullable) + column_definition.flags|= NOT_NULL_FLAG; DBUG_PRINT("info", ("field-ptr:%p", column_definition.field)); - if ((column_definition.flags & NOT_NULL_FLAG) != 0 && // NOT NULL, + if (first && + (column_definition.flags & NOT_NULL_FLAG) != 0 && // NOT NULL, column_definition.default_value == NULL && // no constant default, column_definition.unireg_check == Field::NONE && // no function default column_definition.vcol_info == NULL && @@ -3153,7 +3157,7 @@ void promote_first_timestamp_column(List<Create_field> *column_definitions) )); column_definition.unireg_check= Field::TIMESTAMP_DNUN_FIELD; } - return; + first= false; } } } diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 11a955627a6..d2939f5e6e9 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -4262,19 +4262,6 @@ void Type_handler_temporal_with_date::Item_update_null_value(Item *item) const (void) item->get_date(thd, <ime, Datetime::Options(thd)); } -bool -Type_handler_timestamp_common:: -Column_definition_set_attributes(THD *thd, - Column_definition *def, - const Lex_field_type_st &attr, - CHARSET_INFO *cs, - column_definition_type_t type) const -{ - Type_handler::Column_definition_set_attributes(thd, def, attr, cs, type); - if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP)) - def->flags|= NOT_NULL_FLAG; - return false; -} void Type_handler_string_result::Item_update_null_value(Item *item) const { diff --git a/sql/sql_type.h b/sql/sql_type.h index a2e21d81894..c4e7765d0cb 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -6660,12 +6660,6 @@ public: bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, MYSQL_TIME *, date_mode_t fuzzydate) const override; - bool Column_definition_set_attributes(THD *thd, - Column_definition *def, - const Lex_field_type_st &attr, - CHARSET_INFO *cs, - column_definition_type_t type) - const override; }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 54db077aa2f..1baa395bf07 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6091,7 +6091,6 @@ field_def: | opt_generated_always AS virtual_column_func { Lex->last_field->vcol_info= $3; - Lex->last_field->flags&= ~NOT_NULL_FLAG; // undo automatic NOT NULL for timestamps } vcol_opt_specifier vcol_opt_attribute | opt_generated_always AS ROW_SYM START_SYM opt_asrow_attribute @@ -6566,7 +6565,11 @@ attribute_list: ; attribute: - NULL_SYM { Lex->last_field->flags&= ~ NOT_NULL_FLAG; } + NULL_SYM + { + Lex->last_field->flags&= ~NOT_NULL_FLAG; + Lex->last_field->explicitly_nullable= true; + } | DEFAULT column_default_expr { Lex->last_field->default_value= $2; } | ON UPDATE_SYM NOW_SYM opt_default_time_precision { |