Skip to content
Permalink
Browse files
MDEV-29225 make explicit_defaults_for_timestamps SESSION variable
make @@explicit_defaults_for_timestamp session variable
  • Loading branch information
vuvova committed Aug 2, 2022
1 parent 086eb8e commit 4e3728f
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 82 deletions.
@@ -1322,3 +1322,27 @@ SET timestamp=DEFAULT;
#
# End of 10.4 tests
#
#
# MDEV-29225 make explicit_defaults_for_timestamps SESSION variable
#
set explicit_defaults_for_timestamp=OFF;
create table t1 (f1 timestamp, f2 timestamp);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`f2` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
set explicit_defaults_for_timestamp=ON;
create table t1 (f1 timestamp, f2 timestamp);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` timestamp NULL DEFAULT NULL,
`f2` timestamp NULL DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
#
# End of 10.10 tests
#
@@ -874,7 +874,23 @@ SELECT CASE WHEN a THEN DEFAULT(a) END FROM t1;
DROP TABLE t1;
SET timestamp=DEFAULT;


--echo #
--echo # End of 10.4 tests
--echo #

--echo #
--echo # MDEV-29225 make explicit_defaults_for_timestamps SESSION variable
--echo #

set explicit_defaults_for_timestamp=OFF;
create table t1 (f1 timestamp, f2 timestamp);
show create table t1;
drop table t1;
set explicit_defaults_for_timestamp=ON;
create table t1 (f1 timestamp, f2 timestamp);
show create table t1;
drop table t1;

--echo #
--echo # End of 10.10 tests
--echo #

This file was deleted.

@@ -1,3 +1,4 @@
set @@explicit_defaults_for_timestamp=0;
CREATE TABLE t1 (a TIMESTAMP);
SHOW CREATE TABLE t1;
Table Create Table
@@ -1,3 +1,4 @@
set @@explicit_defaults_for_timestamp=1;
CREATE TABLE t1 (a TIMESTAMP);
SHOW CREATE TABLE t1;
Table Create Table
@@ -913,14 +913,14 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP
VARIABLE_SCOPE GLOBAL
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BOOLEAN
VARIABLE_COMMENT This option causes CREATE TABLE to create all TIMESTAMP columns as NULL with DEFAULT NULL attribute, Without this option, TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses.
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST OFF,ON
READ_ONLY YES
READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME EXTERNAL_USER
VARIABLE_SCOPE SESSION ONLY
@@ -933,14 +933,14 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP
VARIABLE_SCOPE GLOBAL
VARIABLE_SCOPE SESSION
VARIABLE_TYPE BOOLEAN
VARIABLE_COMMENT This option causes CREATE TABLE to create all TIMESTAMP columns as NULL with DEFAULT NULL attribute, Without this option, TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses.
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST OFF,ON
READ_ONLY YES
READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME EXTERNAL_USER
VARIABLE_SCOPE SESSION ONLY

This file was deleted.

@@ -1,8 +1,3 @@
--disable_query_log
if (`SELECT @@explicit_defaults_for_timestamp`)
{
Skip Need explicit-defaults-for-timestamp=off;
}
--enable_query_log
set @@explicit_defaults_for_timestamp=0;

--source inc/explicit_defaults_for_timestamp.inc

This file was deleted.

@@ -1,8 +1,3 @@
--disable_query_log
if (!`SELECT @@explicit_defaults_for_timestamp`)
{
Skip Need explicit-defaults-for-timestamp=on;
}
--enable_query_log
set @@explicit_defaults_for_timestamp=1;

--source inc/explicit_defaults_for_timestamp.inc
@@ -10666,7 +10666,7 @@ bool Column_definition::check(THD *thd)
TIMESTAMP columns get implicit DEFAULT value when
explicit_defaults_for_timestamp is not set.
*/
if ((opt_explicit_defaults_for_timestamp ||
if (((thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP) ||
!is_timestamp_type()) && !vers_sys_field())
{
flags|= NO_DEFAULT_VALUE_FLAG;
@@ -391,7 +391,6 @@ my_bool opt_show_slave_auth_info;
my_bool opt_log_slave_updates= 0;
my_bool opt_replicate_annotate_row_events= 0;
my_bool opt_mysql56_temporal_format=0, strict_password_validation= 1;
my_bool opt_explicit_defaults_for_timestamp= 0;
char *opt_slave_skip_errors;
char *opt_slave_transaction_retry_errors;

@@ -948,7 +948,6 @@ extern my_bool opt_stack_trace, disable_log_notes;
extern my_bool opt_expect_abort;
extern my_bool opt_slave_sql_verify_checksum;
extern my_bool opt_mysql56_temporal_format, strict_password_validation;
extern my_bool opt_explicit_defaults_for_timestamp;
extern ulong binlog_checksum_options;
extern bool max_user_connections_checking;
extern ulong opt_binlog_dbug_fsync_sleep;
@@ -4432,7 +4432,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
tmp_table.maybe_null= 0;
tmp_table.in_use= thd;

if (!opt_explicit_defaults_for_timestamp)
if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
promote_first_timestamp_column(&alter_info->create_list);

if (create_info->fix_create_fields(thd, alter_info, *create_table))
@@ -136,8 +136,7 @@
#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
#define OPTION_KEEP_LOG (1ULL << 23) // THD, user

/* The following is used to detect a conflict with DISTINCT */
#define SELECT_ALL (1ULL << 24) // SELECT, user, parser
#define OPTION_EXPLICIT_DEF_TIMESTAMP (1ULL << 24) // THD, user
#define OPTION_GTID_BEGIN (1ULL << 25) // GTID BEGIN found in log

/** The following can be set when importing tables in a 'wrong order'
@@ -180,10 +179,11 @@
#define OPTION_NO_QUERY_CACHE (1ULL << 39) // SELECT, user
#define OPTION_PROCEDURE_CLAUSE (1ULL << 40) // Internal usage
#define SELECT_NO_UNLOCK (1ULL << 41) // SELECT, intern
#define SELECT_NO_UNLOCK (1ULL << 41) // SELECT, intern
#define OPTION_BIN_TMP_LOG_OFF (1ULL << 42) // disable binlog, intern
/* Disable commit of binlog. Used to combine many DDL's and DML's as one */
#define OPTION_BIN_COMMIT_OFF (1ULL << 43)
/* The following is used to detect a conflict with DISTINCT */
#define SELECT_ALL (1ULL << 44) // SELECT, user, parser

#define OPTION_LEX_FOUND_COMMENT (1ULL << 0) // intern, parser

@@ -4478,7 +4478,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
!sql_field->has_default_function() &&
(sql_field->flags & NOT_NULL_FLAG) &&
(!sql_field->is_timestamp_type() ||
opt_explicit_defaults_for_timestamp)&&
(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))&&
!sql_field->vers_sys_field())
{
sql_field->flags|= NO_DEFAULT_VALUE_FLAG;
@@ -4489,7 +4489,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
!sql_field->default_value && !sql_field->vcol_info &&
!sql_field->vers_sys_field() &&
sql_field->is_timestamp_type() &&
!opt_explicit_defaults_for_timestamp &&
!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP) &&
(sql_field->flags & NOT_NULL_FLAG) &&
(type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
{
@@ -5592,7 +5592,7 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
else
create_table_mode= C_ASSISTED_DISCOVERY;

if (!opt_explicit_defaults_for_timestamp)
if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
promote_first_timestamp_column(&alter_info->create_list);

/* We can abort create table for any table type */
@@ -10511,7 +10511,7 @@ do_continue:;
create_info->fix_period_fields(thd, alter_info))
DBUG_RETURN(true);

if (!opt_explicit_defaults_for_timestamp)
if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
promote_first_timestamp_column(&alter_info->create_list);

#ifdef WITH_PARTITION_STORAGE_ENGINE
@@ -4271,7 +4271,7 @@ Column_definition_set_attributes(THD *thd,
column_definition_type_t type) const
{
Type_handler::Column_definition_set_attributes(thd, def, attr, cs, type);
if (!opt_explicit_defaults_for_timestamp)
if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
def->flags|= NOT_NULL_FLAG;
return false;
}
@@ -719,15 +719,13 @@ Sys_binlog_direct(
CMD_LINE(OPT_ARG), DEFAULT(FALSE),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check));


static Sys_var_mybool Sys_explicit_defaults_for_timestamp(
static Sys_var_bit Sys_explicit_defaults_for_timestamp(
"explicit_defaults_for_timestamp",
"This option causes CREATE TABLE to create all TIMESTAMP columns "
"as NULL with DEFAULT NULL attribute, Without this option, "
"TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses.",
READ_ONLY GLOBAL_VAR(opt_explicit_defaults_for_timestamp),
CMD_LINE(OPT_ARG), DEFAULT(FALSE));

SESSION_VAR(option_bits), CMD_LINE(OPT_ARG),
OPTION_EXPLICIT_DEF_TIMESTAMP, DEFAULT(FALSE));

static Sys_var_ulonglong Sys_bulk_insert_buff_size(
"bulk_insert_buffer_size", "Size of tree cache used in bulk "

0 comments on commit 4e3728f

Please sign in to comment.