1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-15159 NULL is treated as 0 in CTE

Forced columns of recursive CTEs to be nullable. SQL standard
requires this only from recursive columns, but in our code
so far we do not differentiate between recursive and non-recursive
columns when aggregating types of the union that specifies a
recursive CTE.
This commit is contained in:
Igor Babaev
2018-05-14 14:38:17 -07:00
parent 4a5e23e257
commit e74181e3c2
3 changed files with 48 additions and 1 deletions

View File

@ -788,18 +788,28 @@ bool st_select_lex_unit::join_union_item_types(THD *thd_arg,
join_union_type_attributes(thd_arg, holders, count))
DBUG_RETURN(true);
bool is_recursive= with_element && with_element->is_recursive;
types.empty();
List_iterator_fast<Item> it(first_sl->item_list);
Item *item_tmp;
for (uint pos= 0; (item_tmp= it++); pos++)
{
/*
SQL standard requires forced nullability only for
recursive columns. However type aggregation in our
implementation so far does not differentiate between
recursive and non-recursive columns of a recursive CTE.
TODO: this should be fixed.
*/
bool pos_maybe_null= is_recursive ? true : holders[pos].get_maybe_null();
/* Error's in 'new' will be detected after loop */
types.push_back(new (thd_arg->mem_root)
Item_type_holder(thd_arg,
item_tmp,
holders[pos].type_handler(),
&holders[pos]/*Type_all_attributes*/,
holders[pos].get_maybe_null()));
pos_maybe_null));
}
if (unlikely(thd_arg->is_fatal_error))
DBUG_RETURN(true); // out of memory