From: Alexander Barkov Date: November 7 2011 2:56pm Subject: bzr push into mysql-trunk branch (alexander.barkov:3552 to 3553) WL#946 List-Archive: http://lists.mysql.com/commits/141856 Message-Id: <201111071456.pA7EutYt018520@bar.myoffice.izhnet.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3553 Alexander Barkov 2011-11-07 WL#946 clean-ups modified: include/mysql_time.h sql/field.cc sql/field.h sql/item.h sql/item_timefunc.h 3552 Alexander Barkov 2011-11-07 WL#946: more clean-ups in MYSQL_TIME_cache: now set_XXX() functions automatically reset string representation. This is needed because in case of prepared statements fix_length_and_dec() is called twice: at prepare time and at execute time. We need to clean string representation when set_XXX() is called from the execute time fix_length_and_dec(). modified: sql/item_timefunc.cc sql/item_timefunc.h unittest/gunit/item-t.cc === modified file 'include/mysql_time.h' --- a/include/mysql_time.h 2006-12-31 00:02:27 +0000 +++ b/include/mysql_time.h 2011-11-07 14:35:16 +0000 @@ -47,7 +47,7 @@ enum enum_mysql_timestamp_type typedef struct st_mysql_time { unsigned int year, month, day, hour, minute, second; - unsigned long second_part; + unsigned long second_part; /**< microseconds */ my_bool neg; enum enum_mysql_timestamp_type time_type; } MYSQL_TIME; === modified file 'sql/field.cc' --- a/sql/field.cc 2011-11-03 09:33:45 +0000 +++ b/sql/field.cc 2011-11-07 14:35:16 +0000 @@ -4863,7 +4863,7 @@ Field_temporal::convert_number_to_dateti Note, number_to_datetime can return a result different from nr: e.g. 111111 -> 20111111000000 */ - longlong tmp= number_to_datetime(nr, ltime, check_flags(), warnings); + longlong tmp= number_to_datetime(nr, ltime, date_flags(), warnings); if (tmp == LL(-1)) reset(); return tmp; @@ -5054,7 +5054,7 @@ Field_temporal_with_date::store_time(MYS { case MYSQL_TIMESTAMP_DATETIME: case MYSQL_TIMESTAMP_DATE: - if (check_date(ltime, non_zero_date(ltime), check_flags(), &warnings)) + if (check_date(ltime, non_zero_date(ltime), date_flags(), &warnings)) { reset(); error= 1; @@ -5091,7 +5091,7 @@ Field_temporal_with_date::convert_str_to MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status) { - return str_to_datetime(cs, str, len, ltime, check_flags(), status); + return str_to_datetime(cs, str, len, ltime, date_flags(), status); } @@ -5296,8 +5296,7 @@ Field_timestamp::Field_timestamp(uchar * const char *field_name_arg, TABLE_SHARE *share) :Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - MAX_DATETIME_WIDTH, 0) + unireg_check_arg, field_name_arg, 0) { init_timestamp_flags_and_share(share); } @@ -5307,8 +5306,7 @@ Field_timestamp::Field_timestamp(bool ma const char *field_name_arg) :Field_temporal_with_date_and_time((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, 0, - NONE, field_name_arg, - MAX_DATETIME_WIDTH, 0) + NONE, field_name_arg, 0) { /* For 4.0 MYD and 4.0 InnoDB compatibility */ flags|= ZEROFILL_FLAG | UNSIGNED_FLAG | BINARY_FLAG; @@ -5317,7 +5315,7 @@ Field_timestamp::Field_timestamp(bool ma } -ulonglong Field_timestamp::check_flags(const THD *thd) +ulonglong Field_timestamp::date_flags(const THD *thd) { /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE; @@ -5478,7 +5476,7 @@ Field_timestampf::Field_timestampf(uchar uint8 dec_arg) :Field_temporal_with_date_and_timef(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, - MAX_DATETIME_WIDTH, dec_arg) + dec_arg) { init_timestamp_flags_and_share(share); } @@ -5489,8 +5487,7 @@ Field_timestampf::Field_timestampf(bool uint8 dec_arg) :Field_temporal_with_date_and_timef((uchar*) 0, maybe_null_arg ? (uchar*) "": 0, 0, - NONE, field_name_arg, - MAX_DATETIME_WIDTH, dec_arg) + NONE, field_name_arg, dec_arg) { /* For 4.0 MYD and 4.0 InnoDB compatibility */ flags|= ZEROFILL_FLAG | UNSIGNED_FLAG | BINARY_FLAG; @@ -5499,7 +5496,7 @@ Field_timestampf::Field_timestampf(bool } -ulonglong Field_timestampf::check_flags(const THD *thd) +ulonglong Field_timestampf::date_flags(const THD *thd) { /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE; @@ -6049,7 +6046,7 @@ void Field_year::sql_type(String &res) c ** In number context: YYYYMMDD ****************************************************************************/ -ulonglong Field_newdate::check_flags(const THD *thd) +ulonglong Field_newdate::date_flags(const THD *thd) { return TIME_FUZZY_DATE | thd->datetime_flags(); } @@ -6189,7 +6186,7 @@ void Field_newdate::sql_type(String &res ****************************************************************************/ -ulonglong Field_datetime::check_flags(const THD *thd) +ulonglong Field_datetime::date_flags(const THD *thd) { return TIME_FUZZY_DATE | thd->datetime_flags(); } @@ -6381,7 +6378,7 @@ void Field_datetime::sql_type(String &re ****************************************************************************/ -ulonglong Field_datetimef::check_flags(const THD *thd) +ulonglong Field_datetimef::date_flags(const THD *thd) { return TIME_FUZZY_DATE | thd->datetime_flags(); } === modified file 'sql/field.h' --- a/sql/field.h 2011-11-01 11:52:24 +0000 +++ b/sql/field.h 2011-11-07 14:35:16 +0000 @@ -1863,7 +1863,7 @@ protected: @param thd THD @retval sql_mode flags mixed with the field type flags. */ - virtual ulonglong check_flags(const THD *thd) + virtual ulonglong date_flags(const THD *thd) { return 0; } @@ -1872,9 +1872,9 @@ protected: check_date(), number_to_datetime(), str_to_datetime(). Similar to the above when we don't have a THD value. */ - inline ulonglong check_flags() + inline ulonglong date_flags() { - return check_flags(table ? table->in_use : current_thd); + return date_flags(table ? table->in_use : current_thd); } /** @@ -1890,6 +1890,16 @@ protected: ErrConvString str, timestamp_type ts_type, int cuted_increment); public: + /** + Constructor for Field_temporal + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param len_arg Number of characters in the integer part. + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, @@ -1899,6 +1909,13 @@ public: null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg) { flags|= BINARY_FLAG; } + /** + Constructor for Field_temporal + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param len_arg Number of characters in the integer part. + @param dec_arg Number of second fraction digits, 0..6 + */ Field_temporal(bool maybe_null_arg, const char *field_name_arg, uint32 len_arg, uint8 dec_arg) :Field((uchar *) 0, @@ -1958,6 +1975,16 @@ protected: MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status); int store_internal_with_round(MYSQL_TIME *ltime, int *warnings); public: + /** + Constructor for Field_temporal + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param len_arg Number of characters in the integer part. + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal_with_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, @@ -1967,6 +1994,13 @@ public: unireg_check_arg, field_name_arg, int_length_arg, dec_arg) { } + /** + Constructor for Field_temporal + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param len_arg Number of characters in the integer part. + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal_with_date(bool maybe_null_arg, const char *field_name_arg, uint int_length_arg, uint8 dec_arg) :Field_temporal((uchar*) 0, maybe_null_arg ? (uchar*) "": 0, 0, @@ -2001,20 +2035,37 @@ private: return 0; } protected: + /** + Initialize flags and share for timestamp column. + */ void init_timestamp_flags_and_share(TABLE_SHARE *share); + /** + Store "struct timeval" value into field. + The value must be properly rounded or truncated according + to the number of fractional second digits. + */ virtual void store_timestamp_internal(const struct timeval *tm)= 0; bool convert_TIME_to_timestamp(THD *thd, const MYSQL_TIME *ltime, struct timeval *tm, int *error); public: + /** + Constructor for Field_temporal_with_date_and_time + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal_with_date_and_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, - uint8 int_length_arg, uint8 dec_arg) + uint8 dec_arg) :Field_temporal_with_date(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, - int_length_arg, dec_arg) + MAX_DATETIME_WIDTH, dec_arg) { } void set_time(); void store_timestamp(const struct timeval *tm); @@ -2034,22 +2085,36 @@ private: return 1; } public: + /** + Constructor for Field_temporal_with_date_and_timef + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal_with_date_and_timef(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, - uint8 int_length_arg, uint8 dec_arg) + uint8 dec_arg) :Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, - int_length_arg, dec_arg) + dec_arg) { } + /** + Constructor for Field_temporal_with_date_and_timef + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_temporal_with_date_and_timef(bool maybe_null_arg, const char *field_name_arg, - uint int_length_arg, uint8 dec_arg) + uint8 dec_arg) :Field_temporal_with_date_and_time((uchar *) 0, maybe_null_arg ? (uchar*) "" : 0, 0, - NONE, field_name_arg, int_length_arg, - dec_arg) + NONE, field_name_arg, dec_arg) { } uint decimals() const { return dec; } @@ -2070,9 +2135,13 @@ public: }; +/* + Field implementing TIMESTAMP data type without fractional seconds. + We will be removed eventually. +*/ class Field_timestamp :public Field_temporal_with_date_and_time { protected: - ulonglong check_flags(const THD *thd); + ulonglong date_flags(const THD *thd); int store_internal(const MYSQL_TIME *ltime, int *error); bool get_date_internal(MYSQL_TIME *ltime); void store_timestamp_internal(const struct timeval *tm); @@ -2125,16 +2194,35 @@ public: }; +/* + Field implementing TIMESTAMP(N) data type, where N=0..6. +*/ class Field_timestampf :public Field_temporal_with_date_and_timef { protected: bool get_date_internal(MYSQL_TIME *ltime); int store_internal(const MYSQL_TIME *ltime, int *error); - ulonglong check_flags(const THD *thd); + ulonglong date_flags(const THD *thd); void store_timestamp_internal(const struct timeval *tm); public: + /** + Field_timestampf constructor + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param share Table share. + @param dec_arg Number of fractional second digits, 0..6. + */ Field_timestampf(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, TABLE_SHARE *share, uint8 dec_arg); + /** + Field_timestampf constructor + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of fractional second digits, 0..6. + */ Field_timestampf(bool maybe_null_arg, const char *field_name_arg, uint8 dec_arg); Field_timestampf *clone(MEM_ROOT *mem_root) const @@ -2181,16 +2269,6 @@ public: }; -inline Field *new_Field_timestamp(bool maybe_null_arg, - const char *name_arg, - uint8 dec_arg) -{ - return dec_arg > 0 ? - (Field *) new Field_timestampf(maybe_null_arg, name_arg, dec_arg) : - (Field *) new Field_timestamp(maybe_null_arg, name_arg); -} - - class Field_year :public Field_tiny { public: Field_year(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, @@ -2223,7 +2301,7 @@ public: class Field_newdate :public Field_temporal_with_date { protected: - ulonglong check_flags(const THD *thd); + ulonglong date_flags(const THD *thd); bool get_date_internal(MYSQL_TIME *ltime); int store_internal(const MYSQL_TIME *ltime, int *error); @@ -2278,21 +2356,48 @@ protected: MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status); int convert_number_to_TIME(longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime, int *warning); + /** + Low-level function to store MYSQL_TIME value. + The value must be rounded or truncated according to decimals(). + */ virtual int store_internal(const MYSQL_TIME *ltime, int *error)= 0; + /** + Low-level function to store time value in lldiv_t format. + The value must be rounded or truncated according to decimals(). + */ virtual int store_internal(const lldiv_t *lld)= 0; + /** + Function to store time value. + The value is rounded according to decimals(). + */ virtual int store_internal_with_round(MYSQL_TIME *ltime, int *warnings); public: + /** + Constructor for Field_time_common + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_time_common(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, - enum utype unireg_check_arg, const char *field_name_arg, - uint32 int_len_arg, uint8 dec_arg) + enum utype unireg_check_arg, const char *field_name_arg, + uint8 dec_arg) :Field_temporal(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, - int_len_arg, dec_arg) + MAX_TIME_WIDTH, dec_arg) { } + /** + Constructor for Field_time_common + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_time_common(bool maybe_null_arg, const char *field_name_arg, - uint32 int_len_arg, uint8 dec_arg) + uint8 dec_arg) :Field_temporal((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, 0, - NONE, field_name_arg, int_len_arg, dec_arg) + NONE, field_name_arg, MAX_TIME_WIDTH, dec_arg) { } int store_time(MYSQL_TIME *ltime, uint8 dec); String *val_str(String*, String *); @@ -2302,6 +2407,10 @@ public: }; +/* + Field implementing TIME data type without fractional seconds. + We will be removed eventually. +*/ class Field_time :public Field_time_common { protected: int store_internal(const MYSQL_TIME *ltime, int *error); @@ -2310,11 +2419,11 @@ public: Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg) :Field_time_common(ptr_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, MAX_TIME_WIDTH, 0) + unireg_check_arg, field_name_arg, 0) { } Field_time(bool maybe_null_arg, const char *field_name_arg) :Field_time_common((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, 0, - NONE, field_name_arg, MAX_TIME_WIDTH, 0) + NONE, field_name_arg, 0) { } enum_field_types type() const { return MYSQL_TYPE_TIME;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_INT24; } @@ -2339,6 +2448,9 @@ public: }; +/* + Field implementing TIME(N) data type, where N=0..6. +*/ class Field_timef :public Field_time_common { private: int do_save_field_metadata(uchar *metadata_ptr) @@ -2350,17 +2462,30 @@ protected: int store_internal(const MYSQL_TIME *ltime, int *error); int store_internal(const lldiv_t *lld); public: + /** + Constructor for Field_timef + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_timef(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, uint8 dec_arg) :Field_time_common(ptr_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - MAX_TIME_WIDTH, dec_arg) + unireg_check_arg, field_name_arg, dec_arg) { } + /** + Constructor for Field_timef + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_timef(bool maybe_null_arg, const char *field_name_arg, uint8 dec_arg) :Field_time_common((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, 0, - NONE, field_name_arg, - MAX_TIME_WIDTH, dec_arg) + NONE, field_name_arg, dec_arg) { } Field_timef *clone(MEM_ROOT *mem_root) const { @@ -2409,22 +2534,15 @@ public: }; -inline Field *new_Field_time(bool maybe_null_arg, - const char *name_arg, - uint8 dec_arg) -{ - DBUG_ASSERT(dec_arg <= DATETIME_MAX_DECIMALS); - return dec_arg ? - (Field *) new Field_timef(maybe_null_arg, name_arg, dec_arg) : - (Field *) new Field_time(maybe_null_arg, name_arg); -} - - +/* + Field implementing DATETIME data type without fractional seconds. + We will be removed eventually. +*/ class Field_datetime :public Field_temporal_with_date_and_time { protected: int store_internal(const MYSQL_TIME *ltime, int *error); bool get_date_internal(MYSQL_TIME *ltime); - ulonglong check_flags(const THD *thd); + ulonglong date_flags(const THD *thd); void store_timestamp_internal(const struct timeval *tm) { DBUG_ASSERT(0); @@ -2433,14 +2551,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) :Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg, - unireg_check_arg, field_name_arg, - MAX_DATETIME_WIDTH, 0) + unireg_check_arg, field_name_arg, 0) { } Field_datetime(bool maybe_null_arg, const char *field_name_arg) :Field_temporal_with_date_and_time((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, - 0, NONE, field_name_arg, - MAX_DATETIME_WIDTH, 0) + 0, NONE, field_name_arg, 0) { } enum_field_types type() const { return MYSQL_TYPE_DATETIME;} #ifdef HAVE_LONG_LONG @@ -2486,29 +2602,47 @@ public: }; +/* + Field implementing DATETIME(N) data type, where N=0..6. +*/ class Field_datetimef :public Field_temporal_with_date_and_timef { protected: bool get_date_internal(MYSQL_TIME *ltime); int store_internal(const MYSQL_TIME *ltime, int *error); - ulonglong check_flags(const THD *thd); + ulonglong date_flags(const THD *thd); void store_timestamp_internal(const struct timeval *tm) { DBUG_ASSERT(0); } public: + /** + Constructor for Field_datetimef + @param ptr_arg See Field definition + @param null_ptr_arg See Field definition + @param null_bit_arg See Field definition + @param unireg_check_arg See Field definition + @param field_name_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_datetimef(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, uint8 dec_arg) :Field_temporal_with_date_and_timef(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, - MAX_DATETIME_WIDTH, dec_arg) + dec_arg) { } + /** + Constructor for Field_datetimef + @param maybe_null_arg See Field definition + @param field_name_arg See Field definition + @param len_arg See Field definition + @param dec_arg Number of second fraction digits, 0..6. + */ Field_datetimef(bool maybe_null_arg, const char *field_name_arg, uint8 dec_arg) :Field_temporal_with_date_and_timef((uchar *) 0, maybe_null_arg ? (uchar *) "" : 0, 0, - NONE, field_name_arg, - MAX_DATETIME_WIDTH, dec_arg) + NONE, field_name_arg, dec_arg) { } Field_datetimef *clone(MEM_ROOT *mem_root) const { @@ -2544,16 +2678,6 @@ public: }; -inline Field *new_Field_datetime(bool maybe_null_arg, - const char *name_arg, - uint8 dec_arg) -{ - return dec_arg > 0 ? - (Field *) new Field_datetimef(maybe_null_arg, name_arg, dec_arg) : - (Field *) new Field_datetime(maybe_null_arg, name_arg); -} - - class Field_string :public Field_longstr { public: bool can_alter_field_type; === modified file 'sql/item.h' --- a/sql/item.h 2011-11-01 11:52:24 +0000 +++ b/sql/item.h 2011-11-07 14:35:16 +0000 @@ -639,7 +639,7 @@ public: virtual bool eq(const Item *, bool binary_cmp) const; virtual Item_result result_type() const { return REAL_RESULT; } /** - Result type when an item aprear in a numeric context. + Result type when an item appear in a numeric context. See Field::numeric_context_result_type() for more comments. */ virtual enum Item_result numeric_context_result_type() const @@ -739,8 +739,9 @@ public: return val_date_temporal(); } /** - Get date or time value in packed longlong format, - rounded to "dec" fractional digits. + Get date or time value in packed longlong format. + Before conversion from MYSQL_TIME to packed format, + the MYSQL_TIME value is rounded to "dec" fractional digits. */ longlong val_temporal_with_round(enum_field_types type, uint8 dec); @@ -3062,11 +3063,24 @@ public: }; +/* + Item_datetime_with_ref is used to optimize queries like: + SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010; + The numeric constant is replaced to Item_datetime_with_ref + by convert_constant_item(). +*/ class Item_datetime_with_ref :public Item_temporal_with_ref { private: enum_field_types cached_field_type; public: + /** + Constructor for Item_datetime_with_ref. + @param field_type_arg Data type: MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME + @param decimals_arg Number of fractional digits. + @param i Temporal value in packed format. + @param ref_arg Pointer to the original numeric Item. + */ Item_datetime_with_ref(enum_field_types field_type_arg, uint8 decimals_arg, longlong i, Item *ref_arg): Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true), @@ -3083,9 +3097,21 @@ public: }; +/* + Item_time_with_ref is used to optimize queries like: + SELECT ... FROM t1 WHERE time_column = 20110101101010; + The numeric constant is replaced to Item_time_with_ref + by convert_constant_item(). +*/ class Item_time_with_ref :public Item_temporal_with_ref { public: + /** + Constructor for Item_time_with_ref. + @param decimals_arg Number of fractional digits. + @param i Temporal value in packed format. + @param ref_arg Pointer to the original numeric Item. + */ Item_time_with_ref(uint8 decimals_arg, longlong i, Item *ref_arg): Item_temporal_with_ref(MYSQL_TYPE_TIME, decimals_arg, i, ref_arg, 0) { === modified file 'sql/item_timefunc.h' --- a/sql/item_timefunc.h 2011-11-07 12:02:15 +0000 +++ b/sql/item_timefunc.h 2011-11-07 14:35:16 +0000 @@ -787,6 +787,10 @@ class Item_date_literal :public Item_dat { MYSQL_TIME_cache cached_time; public: + /** + Constructor for Item_date_literal. + @param ltime DATE value. + */ Item_date_literal(MYSQL_TIME *ltime) :Item_date_func() { cached_time.set_date(ltime); @@ -839,6 +843,11 @@ class Item_time_literal :public Item_tim { MYSQL_TIME_cache cached_time; public: + /** + Constructor for Item_time_literal. + @param ltime TIME value. + @param dec_arg number of fractional digits in ltime. + */ Item_time_literal(MYSQL_TIME *ltime, uint dec_arg) :Item_time_func() { decimals= min(dec_arg, DATETIME_MAX_DECIMALS); @@ -892,6 +901,11 @@ class Item_datetime_literal :public Item { MYSQL_TIME_cache cached_time; public: + /** + Constructor for Item_datetime_literal. + @param ltime DATETIME value. + @param dec_arg number of fractional digits in ltime. + */ Item_datetime_literal(MYSQL_TIME *ltime, uint dec_arg) :Item_datetime_func() { decimals= min(dec_arg, DATETIME_MAX_DECIMALS); @@ -947,6 +961,10 @@ protected: // Abstract method that defines which time zone is used for conversion. virtual Time_zone *time_zone()= 0; public: + /** + Constructor for Item_func_curtime. + @param dec_arg Number of fractional digits. + */ Item_func_curtime(uint8 dec_arg) :Item_time_func() { decimals= dec_arg; } void fix_length_and_dec(); longlong val_time_temporal() @@ -1045,6 +1063,10 @@ class Item_func_now :public Item_datetim protected: virtual Time_zone *time_zone()= 0; public: + /** + Constructor for Item_func_now. + @param dec_arg Number of fractional digits. + */ Item_func_now(uint8 dec_arg) :Item_datetime_func() { decimals= dec_arg; } void fix_length_and_dec(); int save_in_field(Field *to, bool no_conversions); No bundle (reason: useless for push emails).