mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
comments
This commit is contained in:
12
sql/field.cc
12
sql/field.cc
@ -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;
|
ASSERT_COLUMN_MARKED_FOR_READ;
|
||||||
*sec_part= 0;
|
*sec_part= 0;
|
||||||
@ -4592,7 +4592,7 @@ longlong Field_timestamp::val_int(void)
|
|||||||
|
|
||||||
thd->time_zone_used= 1;
|
thd->time_zone_used= 1;
|
||||||
ulong sec_part;
|
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.
|
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;
|
thd->time_zone_used= 1;
|
||||||
ulong sec_part;
|
ulong sec_part;
|
||||||
uint32 temp= get_timestamp(&sec_part);
|
my_time_t temp= get_timestamp(&sec_part);
|
||||||
|
|
||||||
if (temp == 0 && sec_part == 0)
|
if (temp == 0 && sec_part == 0)
|
||||||
{ /* Zero time is "000000" */
|
{ /* Zero time is "000000" */
|
||||||
@ -4682,7 +4682,7 @@ bool Field_timestamp::get_date(MYSQL_TIME *ltime, uint fuzzydate)
|
|||||||
THD *thd= table->in_use;
|
THD *thd= table->in_use;
|
||||||
thd->time_zone_used= 1;
|
thd->time_zone_used= 1;
|
||||||
ulong sec_part;
|
ulong sec_part;
|
||||||
uint32 temp= get_timestamp(&sec_part);
|
my_time_t temp= get_timestamp(&sec_part);
|
||||||
if (temp == 0 && sec_part == 0)
|
if (temp == 0 && sec_part == 0)
|
||||||
{ /* Zero time is "000000" */
|
{ /* Zero time is "000000" */
|
||||||
if (fuzzydate & TIME_NO_ZERO_DATE)
|
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]);
|
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;
|
ASSERT_COLUMN_MARKED_FOR_READ;
|
||||||
*sec_part= (long)sec_part_unshift(read_bigendian(ptr+4, sec_part_bytes[dec]), dec);
|
*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;
|
thd->time_zone_used= 1;
|
||||||
ulong sec_part;
|
ulong sec_part;
|
||||||
uint32 temp= get_timestamp(&sec_part);
|
my_time_t temp= get_timestamp(&sec_part);
|
||||||
|
|
||||||
if (temp == 0 && sec_part == 0)
|
if (temp == 0 && sec_part == 0)
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -1137,7 +1137,7 @@ public:
|
|||||||
Field::set_default();
|
Field::set_default();
|
||||||
}
|
}
|
||||||
/* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
|
/* 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)
|
virtual void store_TIME(my_time_t timestamp, ulong sec_part)
|
||||||
{
|
{
|
||||||
int4store(ptr,timestamp);
|
int4store(ptr,timestamp);
|
||||||
@ -1172,7 +1172,7 @@ public:
|
|||||||
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
|
DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS);
|
||||||
}
|
}
|
||||||
void sql_type(String &str) const;
|
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);
|
void store_TIME(my_time_t timestamp, ulong sec_part);
|
||||||
int store_decimal(const my_decimal *d);
|
int store_decimal(const my_decimal *d);
|
||||||
double val_real(void);
|
double val_real(void);
|
||||||
|
@ -7106,6 +7106,7 @@ Item_cache* Item_cache::get_cache(const Item *item, const Item_result type)
|
|||||||
case ROW_RESULT:
|
case ROW_RESULT:
|
||||||
return new Item_cache_row();
|
return new Item_cache_row();
|
||||||
case TIME_RESULT:
|
case TIME_RESULT:
|
||||||
|
/* this item will store a packed datetime value as an integer */
|
||||||
return new Item_cache_int(MYSQL_TYPE_DATETIME);
|
return new Item_cache_int(MYSQL_TYPE_DATETIME);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3041,6 +3041,11 @@ public:
|
|||||||
bool cache_value();
|
bool cache_value();
|
||||||
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
|
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
|
||||||
int save_in_field(Field *field, bool no_conversions);
|
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 *clone_item()
|
||||||
{
|
{
|
||||||
Item_cache_int *item= new Item_cache_int(cached_field_type);
|
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);
|
longlong UNINIT_VAR(min_max);
|
||||||
DBUG_ASSERT(fixed == 1);
|
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)
|
if (!compare_as_dates)
|
||||||
return Item_func::get_date(ltime, fuzzy_date);
|
return Item_func::get_date(ltime, fuzzy_date);
|
||||||
|
|
||||||
|
@ -1015,6 +1015,7 @@ public:
|
|||||||
when_sec_part= thd->start_time_sec_part;
|
when_sec_part= thd->start_time_sec_part;
|
||||||
return when;
|
return when;
|
||||||
}
|
}
|
||||||
|
/* thd will only be 0 here at time of log creation */
|
||||||
if ((tmp_thd= current_thd))
|
if ((tmp_thd= current_thd))
|
||||||
{
|
{
|
||||||
when= tmp_thd->start_time;
|
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
|
return cond; // Point at next and level
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Check if equality can be used in removing components of GROUP BY/DISTINCT
|
Check if equality can be used in removing components of GROUP BY/DISTINCT
|
||||||
|
|
||||||
SYNOPSIS
|
@param l the left comparison argument (a field if any)
|
||||||
test_if_equality_guarantees_uniqueness()
|
@param r the right comparison argument (a const of any)
|
||||||
l the left comparison argument (a field if any)
|
|
||||||
r the right comparison argument (a const of any)
|
|
||||||
|
|
||||||
DESCRIPTION
|
@details
|
||||||
Checks if an equality predicate can be used to take away
|
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/GROUP BY because it is known to be true for exactly one
|
||||||
distinct value (e.g. <expr> == <const>).
|
distinct value (e.g. <expr> == <const>).
|
||||||
Arguments must be of the same type because e.g.
|
Arguments must be of the same type because e.g.
|
||||||
<string_field> = <int_const> may match more than 1 distinct value from
|
<string_field> = <int_const> may match more than 1 distinct value from
|
||||||
the column.
|
the column.
|
||||||
We must take into consideration and the optimization done for various
|
Additionally, strings must have the same collation.
|
||||||
string constants when compared to dates etc (see Item_int_with_ref) as
|
Or the *field* must be a datetime - if the constant is a datetime
|
||||||
well as the collation of the arguments.
|
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
|
@retval true can be used
|
||||||
TRUE can be used
|
@retval false cannot be used
|
||||||
FALSE cannot be used
|
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
test_if_equality_guarantees_uniqueness(Item *l, Item *r)
|
test_if_equality_guarantees_uniqueness(Item *l, Item *r)
|
||||||
{
|
{
|
||||||
return r->const_item() &&
|
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 ||
|
(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() &&
|
(r->result_type() == l->result_type() &&
|
||||||
/* and must have the same collation if compared as strings */
|
/* and must have the same collation if compared as strings */
|
||||||
(l->result_type() != STRING_RESULT ||
|
(l->result_type() != STRING_RESULT ||
|
||||||
|
Reference in New Issue
Block a user