Commit dda9577d authored by Sergei Golubchik's avatar Sergei Golubchik

comments

parent 7c459960
......@@ -4473,7 +4473,7 @@ timestamp_auto_set_type Field_timestamp::get_auto_set_type() const
}
}
long Field_timestamp::get_timestamp(ulong *sec_part) const
my_time_t Field_timestamp::get_timestamp(ulong *sec_part) const
{
ASSERT_COLUMN_MARKED_FOR_READ;
*sec_part= 0;
......@@ -4592,7 +4592,7 @@ longlong Field_timestamp::val_int(void)
thd->time_zone_used= 1;
ulong sec_part;
uint32 temp= get_timestamp(&sec_part);
my_time_t temp= get_timestamp(&sec_part);
/*
Field_timestamp() and Field_timestamp_hres() shares this code.
......@@ -4622,7 +4622,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
thd->time_zone_used= 1;
ulong sec_part;
uint32 temp= get_timestamp(&sec_part);
my_time_t temp= get_timestamp(&sec_part);
if (temp == 0 && sec_part == 0)
{ /* Zero time is "000000" */
......@@ -4682,7 +4682,7 @@ bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
THD *thd= table->in_use;
thd->time_zone_used= 1;
ulong sec_part;
uint32 temp= get_timestamp(&sec_part);
my_time_t temp= get_timestamp(&sec_part);
if (temp == 0 && sec_part == 0)
{ /* Zero time is "000000" */
if (fuzzydate & TIME_NO_ZERO_DATE)
......@@ -4830,7 +4830,7 @@ void Field_timestamp_hires::store_TIME(my_time_t timestamp, ulong sec_part)
store_bigendian(sec_part_shift(sec_part, dec), ptr+4, sec_part_bytes[dec]);
}
long Field_timestamp_hires::get_timestamp(ulong *sec_part) const
my_time_t Field_timestamp_hires::get_timestamp(ulong *sec_part) const
{
ASSERT_COLUMN_MARKED_FOR_READ;
*sec_part= (long)sec_part_unshift(read_bigendian(ptr+4, sec_part_bytes[dec]), dec);
......@@ -4844,7 +4844,7 @@ double Field_timestamp_hires::val_real(void)
thd->time_zone_used= 1;
ulong sec_part;
uint32 temp= get_timestamp(&sec_part);
my_time_t temp= get_timestamp(&sec_part);
if (temp == 0 && sec_part == 0)
return(0);
......
......@@ -1137,7 +1137,7 @@ class Field_timestamp :public Field_str {
Field::set_default();
}
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
virtual long get_timestamp(ulong *sec_part) const;
virtual my_time_t get_timestamp(ulong *sec_part) const;
virtual void store_TIME(my_time_t timestamp, ulong sec_part)
{
int4store(ptr,timestamp);
......@@ -1172,7 +1172,7 @@ class Field_timestamp_hires :public Field_timestamp {
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
}
void sql_type(String &str) const;
long get_timestamp(ulong *sec_part) const;
my_time_t get_timestamp(ulong *sec_part) const;
void store_TIME(my_time_t timestamp, ulong sec_part);
int store_decimal(const my_decimal *d);
double val_real(void);
......
......@@ -7106,6 +7106,7 @@ Item_cache* Item_cache::get_cache(const Item *item, const Item_result type)
case ROW_RESULT:
return new Item_cache_row();
case TIME_RESULT:
/* this item will store a packed datetime value as an integer */
return new Item_cache_int(MYSQL_TYPE_DATETIME);
}
return 0;
......
......@@ -3041,6 +3041,11 @@ class Item_cache_int: public Item_cache
bool cache_value();
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
int save_in_field(Field *field, bool no_conversions);
/*
Having a clone_item method tells optimizer that this object
is a constant and need not be optimized further.
Important when storing packed datetime values.
*/
Item *clone_item()
{
Item_cache_int *item= new Item_cache_int(cached_field_type);
......
......@@ -2282,6 +2282,14 @@ bool Item_func_min_max::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{
longlong UNINIT_VAR(min_max);
DBUG_ASSERT(fixed == 1);
/*
just like ::val_int() method of an string item can be called,
for example, SELECT CONCAT("10", "12") + 1,
::get_date() can be called for non-temporal values,
for example, SELECT MONTH(GREATEST("2011-11-21", "2010-10-09"))
*/
if (!compare_as_dates)
return Item_func::get_date(ltime, fuzzy_date);
......
......@@ -1015,6 +1015,7 @@ class Log_event
when_sec_part= thd->start_time_sec_part;
return when;
}
/* thd will only be 0 here at time of log creation */
if ((tmp_thd= current_thd))
{
when= tmp_thd->start_time;
......
......@@ -9417,36 +9417,36 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
return cond; // Point at next and level
}
/*
/**
Check if equality can be used in removing components of GROUP BY/DISTINCT
SYNOPSIS
test_if_equality_guarantees_uniqueness()
l the left comparison argument (a field if any)
r the right comparison argument (a const of any)
@param l the left comparison argument (a field if any)
@param r the right comparison argument (a const of any)
DESCRIPTION
Checks if an equality predicate can be used to take away
DISTINCT/GROUP BY because it is known to be true for exactly one
distinct value (e.g. <expr> == <const>).
Arguments must be of the same type because e.g.
<string_field> = <int_const> may match more than 1 distinct value from
the column.
We must take into consideration and the optimization done for various
string constants when compared to dates etc (see Item_int_with_ref) as
well as the collation of the arguments.
@details
Checks if an equality predicate can be used to take away
DISTINCT/GROUP BY because it is known to be true for exactly one
distinct value (e.g. <expr> == <const>).
Arguments must be of the same type because e.g.
<string_field> = <int_const> may match more than 1 distinct value from
the column.
Additionally, strings must have the same collation.
Or the *field* must be a datetime - if the constant is a datetime
and a field is not - this is not enough, consider:
create table t1 (a varchar(100));
insert t1 values ('2010-01-02'), ('2010-1-2'), ('20100102');
select distinct t1 from t1 where a=date('2010-01-02');
RETURN VALUE
TRUE can be used
FALSE cannot be used
@retval true can be used
@retval false cannot be used
*/
static bool
test_if_equality_guarantees_uniqueness(Item *l, Item *r)
{
return r->const_item() &&
/* elements must be compared as dates */
/* the field is a date (the const will be converted to a date) */
(l->cmp_type() == TIME_RESULT ||
/* or of the same result type */
/* or arguments are of the same result type */
(r->result_type() == l->result_type() &&
/* and must have the same collation if compared as strings */
(l->result_type() != STRING_RESULT ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment