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 ++++++++++-------- sql/field.h | 8 ++++++++ sql/sql_table.cc | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'sql') 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)) || diff --git a/sql/field.h b/sql/field.h index 8c4219513a9..c059c5c78b9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -3084,6 +3084,14 @@ public: { return 255 - FRM_VCOL_HEADER_SIZE(interval != NULL); } + + bool has_default_function() const + { + return (unireg_check == Field::TIMESTAMP_DN_FIELD || + unireg_check == Field::TIMESTAMP_DNUN_FIELD || + unireg_check == Field::TIMESTAMP_UN_FIELD || + unireg_check == Field::NEXT_NUMBER); + } }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 512c5a355c5..a2cab82de4e 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4092,6 +4092,20 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, { Field::utype type= (Field::utype) MTYP_TYPENR(sql_field->unireg_check); + /* + Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and + it is NOT NULL, not an AUTO_INCREMENT field, not a TIMESTAMP and not + updated trough a NOW() function. + */ + if (!sql_field->def && + !sql_field->has_default_function() && + (sql_field->flags & NOT_NULL_FLAG) && + !is_timestamp_type(sql_field->sql_type)) + { + sql_field->flags|= NO_DEFAULT_VALUE_FLAG; + sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT; + } + if (thd->variables.sql_mode & MODE_NO_ZERO_DATE && !sql_field->def && is_timestamp_type(sql_field->sql_type) && -- cgit v1.2.1 From dfac82e44dd665ab218348765df2b519db4c10dc Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 18 Aug 2015 11:17:54 +0300 Subject: Fixed failing tests and compiler warnings - UNINIT_VAR() was required for 4.8.3 on openSUSE 13.2 --- sql/item_geofunc.cc | 5 ++++- sql/opt_range.cc | 4 +++- sql/sp_head.cc | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 55e69c68adb..f1c9e037aeb 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -1082,6 +1082,8 @@ static int setup_relate_func(Geometry *g1, Geometry *g2, uint shape_a, shape_b; uint n_operands= 0; int last_shape_pos; + UNINIT_VAR(shape_a); + UNINIT_VAR(shape_b); last_shape_pos= func->get_next_expression_pos(); if (func->reserve_op_buffer(1)) @@ -2325,7 +2327,8 @@ String *Item_func_pointonsurface::val_str(String *str) String *result= 0; const Gcalc_scan_iterator::point *pprev= NULL; uint32 srid; - + UNINIT_VAR(px); + UNINIT_VAR(py); null_value= 1; if ((args[0]->null_value || diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7361c8443c4..c2979f97e80 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -3545,9 +3545,11 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) break; bitmap_set_bit(&handled_columns, key_part->fieldnr-1); } - double selectivity_mult; if (i) { + double selectivity_mult; + UNINIT_VAR(selectivity_mult); + /* There is at least 1-column prefix of columns whose selectivity has not yet been accounted for. diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 777775e6e39..667cac41d43 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1133,6 +1133,8 @@ sp_head::execute(THD *thd, bool merge_da_on_success) Diagnostics_area *da= thd->get_stmt_da(); Warning_info sp_wi(da->warning_info_id(), false, true); + UNINIT_VAR(saved_creation_ctx); + /* this 7*STACK_MIN_SIZE is a complex matter with a long history (see it!) */ if (check_stack_overrun(thd, 7 * STACK_MIN_SIZE, (uchar*)&old_packet)) DBUG_RETURN(TRUE); -- cgit v1.2.1