mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Support for TIMESTAMP columns holding NULL values. Unlike all other
column types TIMESTAMP is NOT NULL by default, so in order to have TIMESTAMP column holding NULL valaues you have to specify NULL as one of its attributes (this needed for backward compatibility). Main changes: Replaced TABLE::timestamp_default_now/on_update_now members with TABLE::timestamp_auto_set_type flag which is used everywhere for determining if we should auto-set value of TIMESTAMP field during this operation or not. We are also use Field_timestamp::set_time() instead of handler::update_timestamp() in handlers. mysql-test/r/type_timestamp.result: Added test for TIMESTAMP columns which are able to store NULL values. mysql-test/t/type_timestamp.test: Added test for TIMESTAMP columns which are able to store NULL values. sql/field.cc: Added support for TIMESTAMP fields holding NULL values. We don't need Field_timestamp::set_timestamp_offsets() anymore. Instead we need Field_timestamp::get_auto_set_type() function which will convert TIMESTAMP auto-set type stored in Field in unireg_check to value from timestamp_auto_set_type_enum. (We can't replace this function with additional Field_timestamp member and some code in constructor because then we will have troubles with Field::new_field() method). We should also set field to not null in Field_timestamp::set_time() now. sql/field.h: Added support for TIMESTAMP fields holding NULL values. We don't need Field_timestamp::set_timestamp_offsets() anymore. Instead we need Field_timestamp::get_auto_set_type() function, which will convert TIMESTAMP auto-set type stored in Field in unireg_check to value from timestamp_auto_set_type_enum. We also have to support NULL values in Field_timestamp::get_timestamp() function. sql/field_conv.cc: Added comment clarifying behavior in case of TIMESTAMP fields which are able to store NULL values. sql/ha_berkeley.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_heap.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_innodb.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_isam.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_isammrg.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_myisam.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_myisammrg.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/ha_ndbcluster.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now for determining if we should auto-set value of TIMESTAMP field during this operation. We are also use Field_timestamp::set_time() instead of handler::update_timestamp(). sql/handler.cc: handler::update_timestamp() is no longer needed since now we use Field_timestamp::set_time() instead. (we can't use handler::update_timestamp() anyway since field position only is not enough for TIMESTAMP fields which are able to store NULLs) sql/handler.h: handler::update_timestamp() is no longer needed since now we use Field_timestamp::set_time() instead. sql/item_timefunc.cc: Since now TIMESTAMP fields can hold NULL values we should take this into account. sql/sql_base.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now. (Here we use Field_timestamp::get_auto_set_type() to setup its value before further statement execution). sql/sql_insert.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now. sql/sql_load.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now. sql/sql_parse.cc: Added support for TIMESTAMP fields holding NULL values. We should distinguish NULL default values and non-specified default values for such fields (because latter could mean DEFAULT NOW() ON UPDATE NOW() in some cases). sql/sql_show.cc: Added support for TIMESTAMP fields holding NULL values. Unlike all other fields these are NOT NULL by default so we have to specify NULL attribute explicitly for them. sql/sql_table.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now. sql/sql_update.cc: Now we use TABLE::timestamp_field_type instead of TABLE::timestamp_default_now/on_update_now. sql/sql_yacc.yy: Added support for TIMESTAMP fields holding NULL values. Unlike all other fields these are NOT NULL by default (so we have to set NOT_NULL_FLAG properly for them). sql/table.h: Added timestamp_auto_set_type enum which values are used for indicating during which operations we should automatically set TIMESTAPM field value to current timestamp. TABLE: Replaced timestamp_default_now/on_update_now members with timestamp_auto_set_type flag (Now when TIMESTAMP field are able to store NULL values, single position of field in record is not enough for updating this field anyway).
This commit is contained in:
@@ -45,8 +45,8 @@ static void unlink_blobs(register TABLE *table);
|
||||
|
||||
/*
|
||||
Check if insert fields are correct.
|
||||
Sets table->timestamp_default_now/on_update_now to 0 o leaves it to point
|
||||
to timestamp field, depending on if timestamp should be updated or not.
|
||||
Sets table->timestamp_field_type to TIMESTAMP_NO_AUTO_SET or leaves it
|
||||
as is, depending on if timestamp should be updated or not.
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -67,7 +67,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
|
||||
check_grant_all_columns(thd,INSERT_ACL,table))
|
||||
return -1;
|
||||
#endif
|
||||
table->timestamp_default_now= table->timestamp_on_update_now= 0;
|
||||
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
|
||||
}
|
||||
else
|
||||
{ // Part field list
|
||||
@@ -97,7 +97,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
|
||||
}
|
||||
if (table->timestamp_field && // Don't set timestamp if used
|
||||
table->timestamp_field->query_id == thd->query_id)
|
||||
table->timestamp_default_now= table->timestamp_on_update_now= 0;
|
||||
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
|
||||
}
|
||||
// For the values we need select_priv
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
@@ -569,7 +569,8 @@ int write_record(TABLE *table,COPY_INFO *info)
|
||||
*/
|
||||
if (last_uniq_key(table,key_nr) &&
|
||||
!table->file->referenced_by_foreign_key() &&
|
||||
table->timestamp_default_now == table->timestamp_on_update_now)
|
||||
(table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET ||
|
||||
table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH))
|
||||
{
|
||||
if ((error=table->file->update_row(table->record[1],
|
||||
table->record[0])))
|
||||
@@ -645,8 +646,7 @@ public:
|
||||
bool query_start_used,last_insert_id_used,insert_id_used;
|
||||
int log_query;
|
||||
ulonglong last_insert_id;
|
||||
ulong timestamp_default_now;
|
||||
ulong timestamp_on_update_now;
|
||||
timestamp_auto_set_type timestamp_field_type;
|
||||
uint query_length;
|
||||
|
||||
delayed_row(enum_duplicates dup_arg, int log_query_arg)
|
||||
@@ -940,7 +940,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
|
||||
copy->timestamp_field=
|
||||
(Field_timestamp*) copy->field[table->timestamp_field_offset];
|
||||
copy->timestamp_field->unireg_check= table->timestamp_field->unireg_check;
|
||||
copy->timestamp_field->set_timestamp_offsets();
|
||||
copy->timestamp_field_type= copy->timestamp_field->get_auto_set_type();
|
||||
}
|
||||
|
||||
/* _rowid is not used with delayed insert */
|
||||
@@ -995,8 +995,7 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic,
|
||||
row->last_insert_id_used= thd->last_insert_id_used;
|
||||
row->insert_id_used= thd->insert_id_used;
|
||||
row->last_insert_id= thd->last_insert_id;
|
||||
row->timestamp_default_now= table->timestamp_default_now;
|
||||
row->timestamp_on_update_now= table->timestamp_on_update_now;
|
||||
row->timestamp_field_type= table->timestamp_field_type;
|
||||
|
||||
di->rows.push_back(row);
|
||||
di->stacked_inserts++;
|
||||
@@ -1335,8 +1334,7 @@ bool delayed_insert::handle_inserts(void)
|
||||
thd.last_insert_id=row->last_insert_id;
|
||||
thd.last_insert_id_used=row->last_insert_id_used;
|
||||
thd.insert_id_used=row->insert_id_used;
|
||||
table->timestamp_default_now= row->timestamp_default_now;
|
||||
table->timestamp_on_update_now= row->timestamp_on_update_now;
|
||||
table->timestamp_field_type= row->timestamp_field_type;
|
||||
|
||||
info.handle_duplicates= row->dup;
|
||||
if (info.handle_duplicates == DUP_IGNORE ||
|
||||
@@ -1631,7 +1629,7 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
|
||||
field=table->field+table->fields - values.elements;
|
||||
|
||||
/* Don't set timestamp if used */
|
||||
table->timestamp_default_now= table->timestamp_on_update_now= 0;
|
||||
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
|
||||
|
||||
table->next_number_field=table->found_next_number_field;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user