summaryrefslogtreecommitdiffstats
path: root/sql/sql_type.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-01 18:15:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-01 18:15:00 +0000
commita2a2e32c02643a0cec111511220227703fda1cd5 (patch)
tree69cc2b631234c2a8e026b9cd4d72676c61c594df /sql/sql_type.h
parentReleasing progress-linux version 1:10.11.8-1~progress7.99u1. (diff)
downloadmariadb-a2a2e32c02643a0cec111511220227703fda1cd5.tar.xz
mariadb-a2a2e32c02643a0cec111511220227703fda1cd5.zip
Merging upstream version 1:11.4.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sql/sql_type.h')
-rw-r--r--sql/sql_type.h65
1 files changed, 64 insertions, 1 deletions
diff --git a/sql/sql_type.h b/sql/sql_type.h
index b092433b..82db1bc7 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -24,6 +24,7 @@
#include "mysqld.h"
#include "lex_string.h"
+#include "sql_type_timeofday.h"
#include "sql_array.h"
#include "sql_const.h"
#include "sql_time.h"
@@ -2522,6 +2523,20 @@ public:
}
Datetime(my_time_t unix_time, ulong second_part,
const Time_zone* time_zone);
+ Datetime(uint year_arg, uint month_arg, uint day_arg, const TimeOfDay6 &td)
+ {
+ neg= 0;
+ year= year_arg;
+ month= month_arg;
+ day= day_arg;
+ hour= td.hour();
+ minute= td.minute();
+ second= td.second();
+ second_part= td.usecond();
+ time_type= MYSQL_TIMESTAMP_DATETIME;
+ if (!is_valid_datetime_slow())
+ time_type= MYSQL_TIMESTAMP_NONE;
+ }
bool is_valid_datetime() const
{
@@ -2667,6 +2682,12 @@ public:
return Temporal::fraction_remainder(dec);
}
+ Datetime time_of_day(const TimeOfDay6 &td) const
+ {
+ DBUG_ASSERT(is_valid_datetime()); // not SQL NULL
+ return Datetime(year, month, day, td);
+ }
+
Datetime &trunc(uint dec)
{
if (is_valid_datetime())
@@ -2840,6 +2861,11 @@ class Timestamp_or_zero_datetime: protected Timestamp
{
bool m_is_zero_datetime;
public:
+ static Timestamp_or_zero_datetime zero()
+ {
+ return Timestamp_or_zero_datetime(Timestamp(0, 0), true);
+ }
+public:
Timestamp_or_zero_datetime()
:Timestamp(0,0), m_is_zero_datetime(true)
{ }
@@ -2847,7 +2873,7 @@ public:
:Timestamp(native.length() ? Timestamp(native) : Timestamp(0,0)),
m_is_zero_datetime(native.length() == 0)
{ }
- Timestamp_or_zero_datetime(const Timestamp &tm, bool is_zero_datetime)
+ Timestamp_or_zero_datetime(const Timestamp &tm, bool is_zero_datetime= false)
:Timestamp(tm), m_is_zero_datetime(is_zero_datetime)
{ }
Timestamp_or_zero_datetime(THD *thd, const MYSQL_TIME *ltime, uint *err_code);
@@ -2871,6 +2897,11 @@ public:
return 1;
return Timestamp::cmp(other);
}
+ const Timestamp &to_timestamp() const
+ {
+ DBUG_ASSERT(!is_zero_datetime());
+ return *this;
+ }
bool to_TIME(THD *thd, MYSQL_TIME *to, date_mode_t fuzzydate) const;
/*
Convert to native format:
@@ -4231,6 +4262,33 @@ public:
virtual Item *make_const_item_for_comparison(THD *thd,
Item *src,
const Item *cmp) const= 0;
+ /**
+ When aggregating function arguments for comparison
+ (e.g. for =, <, >, <=, >=, NULLIF), in some cases we rewrite
+ arguments. For example, if the predicate
+ timestamp_expr0 = datetime_const_expr1
+ decides to compare arguments as DATETIME,
+ we can try to rewrite datetime_const_expr1 to a TIMESTAMP constant
+ and perform the comparison as TIMESTAMP, which is faster because
+ does not have to perform TIMESTAMP->DATETIME data type conversion per row.
+
+ "this" is the type handler that is used to compare
+ "subject" and "counterpart" (DATETIME in the above example).
+ @param thd the current thread
+ @param subject the comparison side that we want try to rewrite
+ @param counterpart the other comparison side
+ @retval subject, if the subject does not need to be rewritten
+ @retval NULL in case of error (e.g. EOM)
+ @retval Otherwise, a pointer to a new Item which can
+ be used as a replacement for the subject.
+ */
+ virtual Item *convert_item_for_comparison(THD *thd,
+ Item *subject,
+ const Item *counterpart) const
+ {
+ return subject;
+ }
+
virtual Item_cache *Item_get_cache(THD *thd, const Item *item) const= 0;
virtual Item *make_constructor_item(THD *thd, List<Item> *args) const
{
@@ -6583,6 +6641,9 @@ public:
}
String *print_item_value(THD *thd, Item *item, String *str) const override;
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
+ Item *convert_item_for_comparison(THD *thd,
+ Item *subject,
+ const Item *counterpart) const override;
String *Item_func_min_max_val_str(Item_func_min_max *, String *) const override;
double Item_func_min_max_val_real(Item_func_min_max *) const override;
longlong Item_func_min_max_val_int(Item_func_min_max *) const override;
@@ -6755,6 +6816,8 @@ public:
my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *,
my_decimal *) const override;
bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override;
+ bool Item_const_eq(const Item_const *a, const Item_const *b,
+ bool binary_cmp) const override;
bool Item_hybrid_func_fix_attributes(THD *thd,
const LEX_CSTRING &name,
Type_handler_hybrid_field_type *,