Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
27d94b7e
Commit
27d94b7e
authored
Mar 13, 2018
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup: remove get_datetime_value()
parent
42529c43
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
74 deletions
+20
-74
sql/item_cmpfunc.cc
sql/item_cmpfunc.cc
+20
-68
sql/item_cmpfunc.h
sql/item_cmpfunc.h
+0
-6
No files found.
sql/item_cmpfunc.cc
View file @
27d94b7e
...
@@ -745,46 +745,6 @@ static Item** cache_converted_constant(THD *thd, Item **value,
...
@@ -745,46 +745,6 @@ static Item** cache_converted_constant(THD *thd, Item **value,
}
}
/**
Retrieves correct DATETIME value from given item.
@param[in] thd thread handle
@param[in,out] item_arg item to retrieve DATETIME value from
@param[in,out] cache_arg pointer to place to store the caching item to
@param[in] warn_item item for issuing the conversion warning
@param[out] is_null TRUE <=> the item_arg is null
@details
Retrieves the correct DATETIME value from given item for comparison by the
compare_datetime() function.
If the value should be compared as time (TIME_RESULT), it's retrieved as
MYSQL_TIME. Otherwise it's read as a number/string and converted to time.
Constant items are cached, so the convertion is only done once for them.
Note the f_type behavior: if the item can be compared as time, then
f_type is this item's field_type(). Otherwise it's field_type() of
warn_item (which is the other operand of the comparison operator).
This logic provides correct string/number to date/time conversion
depending on the other operand (when comparing a string with a date, it's
parsed as a date, when comparing a string with a time it's parsed as a time)
If the item is a constant it is replaced by the Item_cache_int, that
holds the packed datetime value.
@return
MYSQL_TIME value, packed in a longlong, suitable for comparison.
*/
longlong
get_datetime_value
(
Item
*
item
,
enum_field_types
f_type
,
bool
*
is_null
)
{
longlong
value
=
item
->
val_temporal_packed
(
f_type
);
if
((
*
is_null
=
item
->
null_value
))
return
~
(
ulonglong
)
0
;
return
value
;
}
/*
/*
Compare items values as dates.
Compare items values as dates.
...
@@ -793,8 +753,7 @@ longlong get_datetime_value(Item *item, enum_field_types f_type, bool *is_null)
...
@@ -793,8 +753,7 @@ longlong get_datetime_value(Item *item, enum_field_types f_type, bool *is_null)
DESCRIPTION
DESCRIPTION
Compare items values as DATE/DATETIME for both EQUAL_FUNC and from other
Compare items values as DATE/DATETIME for both EQUAL_FUNC and from other
comparison functions. The correct DATETIME values are obtained
comparison functions.
with help of the get_datetime_value() function.
RETURN
RETURN
-1 a < b or at least one item is null
-1 a < b or at least one item is null
...
@@ -804,20 +763,19 @@ longlong get_datetime_value(Item *item, enum_field_types f_type, bool *is_null)
...
@@ -804,20 +763,19 @@ longlong get_datetime_value(Item *item, enum_field_types f_type, bool *is_null)
int
Arg_comparator
::
compare_temporal
(
enum_field_types
type
)
int
Arg_comparator
::
compare_temporal
(
enum_field_types
type
)
{
{
bool
a_is_null
,
b_is_null
;
longlong
a_value
,
b_value
;
longlong
a_value
,
b_value
;
if
(
set_null
)
if
(
set_null
)
owner
->
null_value
=
1
;
owner
->
null_value
=
1
;
/* Get DATE/DATETIME/TIME value of the 'a' item. */
/* Get DATE/DATETIME/TIME value of the 'a' item. */
a_value
=
get_datetime_value
(
*
a
,
type
,
&
a_is_null
);
a_value
=
(
*
a
)
->
val_temporal_packed
(
type
);
if
(
a_is_null
)
if
(
(
*
a
)
->
null_value
)
return
-
1
;
return
-
1
;
/* Get DATE/DATETIME/TIME value of the 'b' item. */
/* Get DATE/DATETIME/TIME value of the 'b' item. */
b_value
=
get_datetime_value
(
*
b
,
type
,
&
b_is_null
);
b_value
=
(
*
b
)
->
val_temporal_packed
(
type
);
if
(
b_is_null
)
if
(
(
*
b
)
->
null_value
)
return
-
1
;
return
-
1
;
/* Here we have two not-NULL values. */
/* Here we have two not-NULL values. */
...
@@ -830,16 +788,15 @@ int Arg_comparator::compare_temporal(enum_field_types type)
...
@@ -830,16 +788,15 @@ int Arg_comparator::compare_temporal(enum_field_types type)
int
Arg_comparator
::
compare_e_temporal
(
enum_field_types
type
)
int
Arg_comparator
::
compare_e_temporal
(
enum_field_types
type
)
{
{
bool
a_is_null
,
b_is_null
;
longlong
a_value
,
b_value
;
longlong
a_value
,
b_value
;
/* Get DATE/DATETIME/TIME value of the 'a' item. */
/* Get DATE/DATETIME/TIME value of the 'a' item. */
a_value
=
get_datetime_value
(
*
a
,
type
,
&
a_is_null
);
a_value
=
(
*
a
)
->
val_temporal_packed
(
type
);
/* Get DATE/DATETIME/TIME value of the 'b' item. */
/* Get DATE/DATETIME/TIME value of the 'b' item. */
b_value
=
get_datetime_value
(
*
b
,
type
,
&
b_is_null
);
b_value
=
(
*
b
)
->
val_temporal_packed
(
type
);
return
a_is_null
||
b_is_null
?
a_is_null
==
b_is_null
return
(
*
a
)
->
null_value
||
(
*
b
)
->
null_value
?
:
a_value
==
b_value
;
(
*
a
)
->
null_value
==
(
*
b
)
->
null_value
:
a_value
==
b_value
;
}
}
int
Arg_comparator
::
compare_string
()
int
Arg_comparator
::
compare_string
()
...
@@ -2163,9 +2120,7 @@ void Item_func_between::fix_length_and_dec()
...
@@ -2163,9 +2120,7 @@ void Item_func_between::fix_length_and_dec()
/*
/*
When comparing as date/time, we need to convert non-temporal values
When comparing as date/time, we need to convert non-temporal values
(e.g. strings) to MYSQL_TIME. get_datetime_value() does it
(e.g. strings) to MYSQL_TIME.
automatically when one of the operands is a date/time. But here we
may need to compare two strings as dates (str1 BETWEEN str2 AND date).
For this to work, we need to know what date/time type we compare
For this to work, we need to know what date/time type we compare
strings as.
strings as.
*/
*/
...
@@ -2197,23 +2152,22 @@ longlong Item_func_between::val_int()
...
@@ -2197,23 +2152,22 @@ longlong Item_func_between::val_int()
case
TIME_RESULT
:
case
TIME_RESULT
:
{
{
longlong
value
,
a
,
b
;
longlong
value
,
a
,
b
;
bool
value_is_null
,
a_is_null
,
b_is_null
;
enum_field_types
f_type
=
field_type_for_temporal_comparison
(
compare_as_dates
);
enum_field_types
f_type
=
field_type_for_temporal_comparison
(
compare_as_dates
);
value
=
get_datetime_value
(
args
[
0
],
f_type
,
&
value_is_null
);
value
=
args
[
0
]
->
val_temporal_packed
(
f_type
);
if
((
null_value
=
value_is_null
))
if
((
null_value
=
args
[
0
]
->
null_value
))
return
0
;
return
0
;
a
=
get_datetime_value
(
args
[
1
],
f_type
,
&
a_is_null
);
a
=
args
[
1
]
->
val_temporal_packed
(
f_type
);
b
=
get_datetime_value
(
args
[
2
],
f_type
,
&
b_is_null
);
b
=
args
[
2
]
->
val_temporal_packed
(
f_type
);
if
(
!
a
_is_null
&&
!
b_is_null
)
if
(
!
a
rgs
[
1
]
->
null_value
&&
!
args
[
2
]
->
null_value
)
return
(
longlong
)
((
value
>=
a
&&
value
<=
b
)
!=
negated
);
return
(
longlong
)
((
value
>=
a
&&
value
<=
b
)
!=
negated
);
if
(
a
_is_null
&&
b_is_null
)
if
(
a
rgs
[
1
]
->
null_value
&&
args
[
2
]
->
null_value
)
null_value
=
1
;
null_value
=
1
;
else
if
(
a
_is_null
)
else
if
(
a
rgs
[
1
]
->
null_value
)
null_value
=
value
<=
b
;
// not null if false range.
null_value
=
value
<=
b
;
// not null if false range.
else
else
null_value
=
value
>=
a
;
null_value
=
value
>=
a
;
break
;
break
;
...
@@ -3777,9 +3731,8 @@ void in_datetime::set(uint pos,Item *item)
...
@@ -3777,9 +3731,8 @@ void in_datetime::set(uint pos,Item *item)
uchar
*
in_datetime
::
get_value
(
Item
*
item
)
uchar
*
in_datetime
::
get_value
(
Item
*
item
)
{
{
bool
is_null
;
enum_field_types
f_type
=
item
->
field_type_for_temporal_comparison
(
warn_item
);
enum_field_types
f_type
=
item
->
field_type_for_temporal_comparison
(
warn_item
);
tmp
.
val
=
get_datetime_value
(
item
,
f_type
,
&
is_null
);
tmp
.
val
=
item
->
val_temporal_packed
(
f_type
);
if
(
item
->
null_value
)
if
(
item
->
null_value
)
return
0
;
return
0
;
tmp
.
unsigned_flag
=
1L
;
tmp
.
unsigned_flag
=
1L
;
...
@@ -4040,9 +3993,8 @@ cmp_item* cmp_item_decimal::make_same()
...
@@ -4040,9 +3993,8 @@ cmp_item* cmp_item_decimal::make_same()
void
cmp_item_datetime
::
store_value
(
Item
*
item
)
void
cmp_item_datetime
::
store_value
(
Item
*
item
)
{
{
bool
is_null
;
enum_field_types
f_type
=
item
->
field_type_for_temporal_comparison
(
warn_item
);
enum_field_types
f_type
=
item
->
field_type_for_temporal_comparison
(
warn_item
);
value
=
get_datetime_value
(
item
,
f_type
,
&
is_null
);
value
=
item
->
val_temporal_packed
(
f_type
);
m_null_value
=
item
->
null_value
;
m_null_value
=
item
->
null_value
;
}
}
...
...
sql/item_cmpfunc.h
View file @
27d94b7e
...
@@ -1266,7 +1266,6 @@ class in_longlong :public in_vector
...
@@ -1266,7 +1266,6 @@ class in_longlong :public in_vector
/*
/*
Class to represent a vector of constant DATE/DATETIME values.
Class to represent a vector of constant DATE/DATETIME values.
Values are obtained with help of the get_datetime_value() function.
*/
*/
class
in_datetime
:
public
in_longlong
class
in_datetime
:
public
in_longlong
{
{
...
@@ -1436,7 +1435,6 @@ class cmp_item_int : public cmp_item_scalar
...
@@ -1436,7 +1435,6 @@ class cmp_item_int : public cmp_item_scalar
/*
/*
Compare items in the DATETIME context.
Compare items in the DATETIME context.
Values are obtained with help of the get_datetime_value() function.
*/
*/
class
cmp_item_datetime
:
public
cmp_item_scalar
class
cmp_item_datetime
:
public
cmp_item_scalar
{
{
...
@@ -2614,10 +2612,6 @@ inline bool is_cond_or(Item *item)
...
@@ -2614,10 +2612,6 @@ inline bool is_cond_or(Item *item)
Item
*
and_expressions
(
Item
*
a
,
Item
*
b
,
Item
**
org_item
);
Item
*
and_expressions
(
Item
*
a
,
Item
*
b
,
Item
**
org_item
);
longlong
get_datetime_value
(
Item
***
item_arg
,
Item
**
cache_arg
,
enum_field_types
f_type
,
bool
*
is_null
);
class
Comp_creator
class
Comp_creator
{
{
public:
public:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment