mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
--echo #
--echo # MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY --echo #
This commit is contained in:
@ -542,5 +542,18 @@ SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
|
||||
a b
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY
|
||||
#
|
||||
SET time_zone='+00:00';
|
||||
CREATE TABLE t1 (a INT, ts TIMESTAMP) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1, FROM_UNIXTIME(1288481126) /*winter time in Moscow*/);
|
||||
SET time_zone='Europe/Moscow';
|
||||
CREATE TABLE t2 AS SELECT ts, COALESCE(ts) AS cts FROM t1 GROUP BY cts;
|
||||
SELECT ts, cts, UNIX_TIMESTAMP(ts) AS uts, UNIX_TIMESTAMP(cts) AS ucts FROM t2;
|
||||
ts cts uts ucts
|
||||
2010-10-31 02:25:26 2010-10-31 02:25:26 1288481126 1288481126
|
||||
DROP TABLE t1,t2;
|
||||
SET time_zone=DEFAULT;
|
||||
#
|
||||
# End of 10.4 tests
|
||||
#
|
||||
|
@ -490,6 +490,18 @@ SELECT * FROM t1 WHERE a = (SELECT MIN(b) FROM t1);
|
||||
SELECT * FROM t1 WHERE a IN ((SELECT MAX(b) FROM t1), (SELECT MIN(b) FROM t1));
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY
|
||||
--echo #
|
||||
|
||||
SET time_zone='+00:00';
|
||||
CREATE TABLE t1 (a INT, ts TIMESTAMP) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1, FROM_UNIXTIME(1288481126) /*winter time in Moscow*/);
|
||||
SET time_zone='Europe/Moscow';
|
||||
CREATE TABLE t2 AS SELECT ts, COALESCE(ts) AS cts FROM t1 GROUP BY cts;
|
||||
SELECT ts, cts, UNIX_TIMESTAMP(ts) AS uts, UNIX_TIMESTAMP(cts) AS ucts FROM t2;
|
||||
DROP TABLE t1,t2;
|
||||
SET time_zone=DEFAULT;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
|
@ -1118,5 +1118,16 @@ ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column 'a' at r
|
||||
DROP TABLE t1;
|
||||
SET sql_mode=DEFAULT;
|
||||
#
|
||||
# MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY
|
||||
#
|
||||
CREATE TABLE t1 (a INT, b TIMESTAMP) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1,'2018-06-19 00:00:00');
|
||||
SELECT NULLIF(b, 'N/A') AS f, MAX(a) FROM t1 GROUP BY f;
|
||||
f MAX(a)
|
||||
2018-06-19 00:00:00 1
|
||||
Warnings:
|
||||
Warning 1292 Truncated incorrect datetime value: 'N/A'
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# End of 10.4 tests
|
||||
#
|
||||
|
@ -709,6 +709,14 @@ UPDATE t1 SET a=COALESCE(b);
|
||||
DROP TABLE t1;
|
||||
SET sql_mode=DEFAULT;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-17979 Assertion `0' failed in Item::val_native upon SELECT with timestamp, NULLIF, GROUP BY
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a INT, b TIMESTAMP) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1,'2018-06-19 00:00:00');
|
||||
SELECT NULLIF(b, 'N/A') AS f, MAX(a) FROM t1 GROUP BY f;
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.4 tests
|
||||
|
56
sql/item.h
56
sql/item.h
@ -6021,6 +6021,62 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
We need a separate class Item_copy_timestamp because
|
||||
TIMESTAMP->string->TIMESTAMP conversion is not round trip safe
|
||||
near the DST change, e.g. '2010-10-31 02:25:26' can mean:
|
||||
- my_time_t(1288477526) - summer time in Moscow
|
||||
- my_time_t(1288481126) - winter time in Moscow, one hour later
|
||||
*/
|
||||
class Item_copy_timestamp: public Item_copy
|
||||
{
|
||||
Timestamp_or_zero_datetime m_value;
|
||||
public:
|
||||
Item_copy_timestamp(THD *thd, Item *arg): Item_copy(thd, arg) { }
|
||||
const Type_handler *type_handler() const { return &type_handler_timestamp2; }
|
||||
void copy()
|
||||
{
|
||||
Timestamp_or_zero_datetime_native_null tmp(current_thd, item, false);
|
||||
null_value= tmp.is_null();
|
||||
m_value= tmp.is_null() ? Timestamp_or_zero_datetime() :
|
||||
Timestamp_or_zero_datetime(tmp);
|
||||
}
|
||||
int save_in_field(Field *field, bool no_conversions)
|
||||
{
|
||||
Timestamp_or_zero_datetime_native native(m_value, decimals);
|
||||
return native.save_in_field(field, decimals);
|
||||
}
|
||||
longlong val_int()
|
||||
{
|
||||
return m_value.to_datetime(current_thd).to_longlong();
|
||||
}
|
||||
double val_real()
|
||||
{
|
||||
return m_value.to_datetime(current_thd).to_double();
|
||||
}
|
||||
String *val_str(String *to)
|
||||
{
|
||||
return m_value.to_datetime(current_thd).to_string(to, decimals);
|
||||
}
|
||||
my_decimal *val_decimal(my_decimal *to)
|
||||
{
|
||||
return m_value.to_datetime(current_thd).to_decimal(to);
|
||||
}
|
||||
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
|
||||
{
|
||||
bool res= m_value.to_TIME(thd, ltime, fuzzydate);
|
||||
DBUG_ASSERT(!res);
|
||||
return res;
|
||||
}
|
||||
bool val_native(THD *thd, Native *to)
|
||||
{
|
||||
return m_value.to_native(to, decimals);
|
||||
}
|
||||
Item *get_copy(THD *thd)
|
||||
{ return get_item_copy<Item_copy_timestamp>(thd, this); }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Cached_item_XXX objects are not exactly caches. They do the following:
|
||||
|
||||
|
@ -23907,7 +23907,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
|
||||
on how the value is to be used: In some cases this may be an
|
||||
argument in a group function, like: IF(ISNULL(col),0,COUNT(*))
|
||||
*/
|
||||
if (!(pos=new (thd->mem_root) Item_copy_string(thd, pos)))
|
||||
if (!(pos= pos->type_handler()->create_item_copy(thd, pos)))
|
||||
goto err;
|
||||
if (i < border) // HAVING, ORDER and GROUP BY
|
||||
{
|
||||
|
@ -3764,6 +3764,22 @@ Type_handler_date_common::Item_get_cache(THD *thd, const Item *item) const
|
||||
return new (thd->mem_root) Item_cache_date(thd);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
Item_copy *
|
||||
Type_handler::create_item_copy(THD *thd, Item *item) const
|
||||
{
|
||||
return new (thd->mem_root) Item_copy_string(thd, item);
|
||||
}
|
||||
|
||||
|
||||
Item_copy *
|
||||
Type_handler_timestamp_common::create_item_copy(THD *thd, Item *item) const
|
||||
{
|
||||
return new (thd->mem_root) Item_copy_timestamp(thd, item);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
bool Type_handler_int_result::
|
||||
|
@ -35,6 +35,7 @@ class Item_const;
|
||||
class Item_literal;
|
||||
class Item_param;
|
||||
class Item_cache;
|
||||
class Item_copy;
|
||||
class Item_func_or_sum;
|
||||
class Item_sum_hybrid;
|
||||
class Item_sum_sum;
|
||||
@ -3470,6 +3471,7 @@ public:
|
||||
DBUG_ASSERT(0);
|
||||
return NULL;
|
||||
}
|
||||
virtual Item_copy *create_item_copy(THD *thd, Item *item) const;
|
||||
virtual int cmp_native(const Native &a, const Native &b) const
|
||||
{
|
||||
DBUG_ASSERT(0);
|
||||
@ -3771,6 +3773,11 @@ public:
|
||||
}
|
||||
Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const;
|
||||
Item_cache *Item_get_cache(THD *thd, const Item *item) const;
|
||||
Item_copy *create_item_copy(THD *thd, Item *item) const
|
||||
{
|
||||
DBUG_ASSERT(0);
|
||||
return NULL;
|
||||
}
|
||||
bool set_comparator_func(Arg_comparator *cmp) const;
|
||||
bool Item_hybrid_func_fix_attributes(THD *thd,
|
||||
const char *name,
|
||||
@ -5411,6 +5418,7 @@ public:
|
||||
int Item_save_in_field(Item *item, Field *field, bool no_conversions) const;
|
||||
String *print_item_value(THD *thd, Item *item, String *str) const;
|
||||
Item_cache *Item_get_cache(THD *thd, const Item *item) const;
|
||||
Item_copy *create_item_copy(THD *thd, Item *item) const;
|
||||
String *Item_func_min_max_val_str(Item_func_min_max *, String *) const;
|
||||
double Item_func_min_max_val_real(Item_func_min_max *) const;
|
||||
longlong Item_func_min_max_val_int(Item_func_min_max *) const;
|
||||
|
Reference in New Issue
Block a user