summaryrefslogtreecommitdiff
path: root/sql/field.h
diff options
context:
space:
mode:
authorTatiana A. Nurnberg <azundris@mysql.com>2009-06-24 13:02:20 +0200
committerTatiana A. Nurnberg <azundris@mysql.com>2009-06-24 13:02:20 +0200
commit74deaae946f060318900b93249e1d48f4d43c9af (patch)
tree91ef103df7056ffa6cd178a11a2301c411b885f3 /sql/field.h
parente2ac8c07bdd2e58f5f7b4919a76a0d1881f3ed5e (diff)
downloadmariadb-git-74deaae946f060318900b93249e1d48f4d43c9af.tar.gz
Bug#43508: Renaming timestamp or date column triggers table copy
Altering a table to update a column with types DATE or TIMESTAMP would incorrectly be seen as a significant change that necessitates a slow copy+rename operation instead of a fast update. There were two problems: The character set is magically set for TIMESTAMP to be "binary", but that was done too deep in field use code for ALTER TABLE to know of it. Now, put that in the constructor for Field_timestamp. Also, when we set the character set for the new replacement/ comparison field, also raise the "binary" field flag that tells us we should compare it exactly. That is necessary to match the old stored definition. Next is the problem that the default length for TIMESTAMP and DATE fields is different than the length read from the .frm . The compressed size is written to the file, but the human-readable, part-delimited length is used as default length. IIRC, for timestamp it was 19!=14, and for date it was 8!=10. Length mismatch causes a table copy. Also, clean up a place where a comparison function alters one of its parameters and replace it with an assertion of the condition it mutates.
Diffstat (limited to 'sql/field.h')
-rw-r--r--sql/field.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/sql/field.h b/sql/field.h
index 5136f760fc1..421411e8593 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1,4 +1,4 @@
-/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
+/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -603,6 +603,12 @@ protected:
handle_int64(to, from, low_byte_first_from, table->s->db_low_byte_first);
return from + sizeof(int64);
}
+
+ bool field_flags_are_binary()
+ {
+ return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
+ }
+
};
@@ -658,7 +664,6 @@ public:
friend class Create_field;
my_decimal *val_decimal(my_decimal *);
virtual bool str_needs_quotes() { return TRUE; }
- bool compare_str_field_flags(Create_field *new_field, uint32 flags);
uint is_equal(Create_field *new_field);
};
@@ -1268,12 +1273,12 @@ public:
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
CHARSET_INFO *cs)
- :Field_str(ptr_arg, 10, null_ptr_arg, null_bit_arg,
+ :Field_str(ptr_arg, MAX_DATE_WIDTH, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, cs)
{}
Field_date(bool maybe_null_arg, const char *field_name_arg,
CHARSET_INFO *cs)
- :Field_str((uchar*) 0,10, maybe_null_arg ? (uchar*) "": 0,0,
+ :Field_str((uchar*) 0, MAX_DATE_WIDTH, maybe_null_arg ? (uchar*) "": 0,0,
NONE, field_name_arg, cs) {}
enum_field_types type() const { return MYSQL_TYPE_DATE;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
@@ -1383,12 +1388,12 @@ public:
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
enum utype unireg_check_arg, const char *field_name_arg,
CHARSET_INFO *cs)
- :Field_str(ptr_arg, 19, null_ptr_arg, null_bit_arg,
+ :Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, cs)
{}
Field_datetime(bool maybe_null_arg, const char *field_name_arg,
CHARSET_INFO *cs)
- :Field_str((uchar*) 0,19, maybe_null_arg ? (uchar*) "": 0,0,
+ :Field_str((uchar*) 0, MAX_DATETIME_WIDTH, maybe_null_arg ? (uchar*) "": 0,0,
NONE, field_name_arg, cs) {}
enum_field_types type() const { return MYSQL_TYPE_DATETIME;}
#ifdef HAVE_LONG_LONG
@@ -2061,6 +2066,11 @@ public:
Item *on_update_value, LEX_STRING *comment, char *change,
List<String> *interval_list, CHARSET_INFO *cs,
uint uint_geom_type);
+
+ bool field_flags_are_binary()
+ {
+ return (flags & (BINCMP_FLAG | BINARY_FLAG)) != 0;
+ }
};