1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-29225 make explicit_defaults_for_timestamps SESSION variable

make @@explicit_defaults_for_timestamp session variable
This commit is contained in:
Sergei Golubchik
2022-07-02 12:22:10 +02:00
parent 086eb8e23c
commit 4e3728f038
19 changed files with 62 additions and 82 deletions

View File

@@ -1322,3 +1322,27 @@ SET timestamp=DEFAULT;
# #
# End of 10.4 tests # 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
#

View File

@@ -874,7 +874,23 @@ SELECT CASE WHEN a THEN DEFAULT(a) END FROM t1;
DROP TABLE t1; DROP TABLE t1;
SET timestamp=DEFAULT; SET timestamp=DEFAULT;
--echo # --echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo # --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 #

View File

@@ -1,21 +0,0 @@
select @@global.explicit_defaults_for_timestamp;
@@global.explicit_defaults_for_timestamp
0
select @@session.explicit_defaults_for_timestamp;
ERROR HY000: Variable 'explicit_defaults_for_timestamp' is a GLOBAL variable
show global variables like 'explicit_defaults_for_timestamp';
Variable_name Value
explicit_defaults_for_timestamp OFF
show session variables like 'explicit_defaults_for_timestamp';
Variable_name Value
explicit_defaults_for_timestamp OFF
select * from information_schema.global_variables where variable_name='explicit_defaults_for_timestamp';
VARIABLE_NAME VARIABLE_VALUE
EXPLICIT_DEFAULTS_FOR_TIMESTAMP OFF
select * from information_schema.session_variables where variable_name='explicit_defaults_for_timestamp';
VARIABLE_NAME VARIABLE_VALUE
EXPLICIT_DEFAULTS_FOR_TIMESTAMP OFF
set global explicit_defaults_for_timestamp=true;
ERROR HY000: Variable 'explicit_defaults_for_timestamp' is a read only variable
set session explicit_defaults_for_timestamp=true;
ERROR HY000: Variable 'explicit_defaults_for_timestamp' is a read only variable

View File

@@ -1,3 +1,4 @@
set @@explicit_defaults_for_timestamp=0;
CREATE TABLE t1 (a TIMESTAMP); CREATE TABLE t1 (a TIMESTAMP);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table

View File

@@ -1,3 +1,4 @@
set @@explicit_defaults_for_timestamp=1;
CREATE TABLE t1 (a TIMESTAMP); CREATE TABLE t1 (a TIMESTAMP);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table

View File

@@ -913,14 +913,14 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP
VARIABLE_SCOPE GLOBAL VARIABLE_SCOPE SESSION
VARIABLE_TYPE BOOLEAN 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. 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_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST OFF,ON ENUM_VALUE_LIST OFF,ON
READ_ONLY YES READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME EXTERNAL_USER VARIABLE_NAME EXTERNAL_USER
VARIABLE_SCOPE SESSION ONLY VARIABLE_SCOPE SESSION ONLY

View File

@@ -933,14 +933,14 @@ ENUM_VALUE_LIST NULL
READ_ONLY NO READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP VARIABLE_NAME EXPLICIT_DEFAULTS_FOR_TIMESTAMP
VARIABLE_SCOPE GLOBAL VARIABLE_SCOPE SESSION
VARIABLE_TYPE BOOLEAN 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. 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_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST OFF,ON ENUM_VALUE_LIST OFF,ON
READ_ONLY YES READ_ONLY NO
COMMAND_LINE_ARGUMENT OPTIONAL COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME EXTERNAL_USER VARIABLE_NAME EXTERNAL_USER
VARIABLE_SCOPE SESSION ONLY VARIABLE_SCOPE SESSION ONLY

View File

@@ -1,26 +0,0 @@
#
# show the global and session values;
#
select @@global.explicit_defaults_for_timestamp;
#
# Test that it's a global-only variable
#
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.explicit_defaults_for_timestamp;
show global variables like 'explicit_defaults_for_timestamp';
show session variables like 'explicit_defaults_for_timestamp';
--disable_warnings
select * from information_schema.global_variables where variable_name='explicit_defaults_for_timestamp';
select * from information_schema.session_variables where variable_name='explicit_defaults_for_timestamp';
--enable_warnings
#
# show that it's read-only
#
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set global explicit_defaults_for_timestamp=true;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
set session explicit_defaults_for_timestamp=true;

View File

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

View File

@@ -1 +0,0 @@
--explicit-defaults-for-timestamp=on

View File

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

View File

@@ -10666,7 +10666,7 @@ bool Column_definition::check(THD *thd)
TIMESTAMP columns get implicit DEFAULT value when TIMESTAMP columns get implicit DEFAULT value when
explicit_defaults_for_timestamp is not set. 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()) !is_timestamp_type()) && !vers_sys_field())
{ {
flags|= NO_DEFAULT_VALUE_FLAG; flags|= NO_DEFAULT_VALUE_FLAG;

View File

@@ -391,7 +391,6 @@ my_bool opt_show_slave_auth_info;
my_bool opt_log_slave_updates= 0; my_bool opt_log_slave_updates= 0;
my_bool opt_replicate_annotate_row_events= 0; my_bool opt_replicate_annotate_row_events= 0;
my_bool opt_mysql56_temporal_format=0, strict_password_validation= 1; 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_skip_errors;
char *opt_slave_transaction_retry_errors; char *opt_slave_transaction_retry_errors;

View File

@@ -948,7 +948,6 @@ extern my_bool opt_stack_trace, disable_log_notes;
extern my_bool opt_expect_abort; extern my_bool opt_expect_abort;
extern my_bool opt_slave_sql_verify_checksum; extern my_bool opt_slave_sql_verify_checksum;
extern my_bool opt_mysql56_temporal_format, strict_password_validation; extern my_bool opt_mysql56_temporal_format, strict_password_validation;
extern my_bool opt_explicit_defaults_for_timestamp;
extern ulong binlog_checksum_options; extern ulong binlog_checksum_options;
extern bool max_user_connections_checking; extern bool max_user_connections_checking;
extern ulong opt_binlog_dbug_fsync_sleep; extern ulong opt_binlog_dbug_fsync_sleep;

View File

@@ -4432,7 +4432,7 @@ TABLE *select_create::create_table_from_items(THD *thd, List<Item> *items,
tmp_table.maybe_null= 0; tmp_table.maybe_null= 0;
tmp_table.in_use= thd; 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); promote_first_timestamp_column(&alter_info->create_list);
if (create_info->fix_create_fields(thd, alter_info, *create_table)) if (create_info->fix_create_fields(thd, alter_info, *create_table))

View File

@@ -136,8 +136,7 @@
#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE) #define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
#define OPTION_KEEP_LOG (1ULL << 23) // THD, user #define OPTION_KEEP_LOG (1ULL << 23) // THD, user
/* The following is used to detect a conflict with DISTINCT */ #define OPTION_EXPLICIT_DEF_TIMESTAMP (1ULL << 24) // THD, user
#define SELECT_ALL (1ULL << 24) // SELECT, user, parser
#define OPTION_GTID_BEGIN (1ULL << 25) // GTID BEGIN found in log #define OPTION_GTID_BEGIN (1ULL << 25) // GTID BEGIN found in log
/** The following can be set when importing tables in a 'wrong order' /** 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_NO_QUERY_CACHE (1ULL << 39) // SELECT, user
#define OPTION_PROCEDURE_CLAUSE (1ULL << 40) // Internal usage #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 SELECT_NO_UNLOCK (1ULL << 41) // SELECT, intern
#define OPTION_BIN_TMP_LOG_OFF (1ULL << 42) // disable binlog, 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 */ /* Disable commit of binlog. Used to combine many DDL's and DML's as one */
#define OPTION_BIN_COMMIT_OFF (1ULL << 43) #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 #define OPTION_LEX_FOUND_COMMENT (1ULL << 0) // intern, parser

View File

@@ -4478,7 +4478,7 @@ without_overlaps_err:
!sql_field->has_default_function() && !sql_field->has_default_function() &&
(sql_field->flags & NOT_NULL_FLAG) && (sql_field->flags & NOT_NULL_FLAG) &&
(!sql_field->is_timestamp_type() || (!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->vers_sys_field())
{ {
sql_field->flags|= NO_DEFAULT_VALUE_FLAG; sql_field->flags|= NO_DEFAULT_VALUE_FLAG;
@@ -4489,7 +4489,7 @@ without_overlaps_err:
!sql_field->default_value && !sql_field->vcol_info && !sql_field->default_value && !sql_field->vcol_info &&
!sql_field->vers_sys_field() && !sql_field->vers_sys_field() &&
sql_field->is_timestamp_type() && sql_field->is_timestamp_type() &&
!opt_explicit_defaults_for_timestamp && !(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP) &&
(sql_field->flags & NOT_NULL_FLAG) && (sql_field->flags & NOT_NULL_FLAG) &&
(type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD)) (type == Field::NONE || type == Field::TIMESTAMP_UN_FIELD))
{ {
@@ -5592,7 +5592,7 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
else else
create_table_mode= C_ASSISTED_DISCOVERY; 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); promote_first_timestamp_column(&alter_info->create_list);
/* We can abort create table for any table type */ /* We can abort create table for any table type */
@@ -10511,7 +10511,7 @@ do_continue:;
create_info->fix_period_fields(thd, alter_info)) create_info->fix_period_fields(thd, alter_info))
DBUG_RETURN(true); 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); promote_first_timestamp_column(&alter_info->create_list);
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE

View File

@@ -4271,7 +4271,7 @@ Column_definition_set_attributes(THD *thd,
column_definition_type_t type) const column_definition_type_t type) const
{ {
Type_handler::Column_definition_set_attributes(thd, def, attr, cs, type); 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; def->flags|= NOT_NULL_FLAG;
return false; return false;
} }

View File

@@ -719,15 +719,13 @@ Sys_binlog_direct(
CMD_LINE(OPT_ARG), DEFAULT(FALSE), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check)); NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check));
static Sys_var_bit Sys_explicit_defaults_for_timestamp(
static Sys_var_mybool Sys_explicit_defaults_for_timestamp(
"explicit_defaults_for_timestamp", "explicit_defaults_for_timestamp",
"This option causes CREATE TABLE to create all TIMESTAMP columns " "This option causes CREATE TABLE to create all TIMESTAMP columns "
"as NULL with DEFAULT NULL attribute, Without this option, " "as NULL with DEFAULT NULL attribute, Without this option, "
"TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses.", "TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses.",
READ_ONLY GLOBAL_VAR(opt_explicit_defaults_for_timestamp), SESSION_VAR(option_bits), CMD_LINE(OPT_ARG),
CMD_LINE(OPT_ARG), DEFAULT(FALSE)); OPTION_EXPLICIT_DEF_TIMESTAMP, DEFAULT(FALSE));
static Sys_var_ulonglong Sys_bulk_insert_buff_size( static Sys_var_ulonglong Sys_bulk_insert_buff_size(
"bulk_insert_buffer_size", "Size of tree cache used in bulk " "bulk_insert_buffer_size", "Size of tree cache used in bulk "