diff options
author | Igor Babaev <igor@askmonty.org> | 2018-05-14 14:38:17 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2018-05-14 14:38:17 -0700 |
commit | e74181e3c2eae882a382d532eefdc71156974ae2 (patch) | |
tree | 8c2b8e2b411aa3753e1a9ed148e38cf48bfe9117 /sql/sql_union.cc | |
parent | 4a5e23e257e229b548599133dbed5162af9df6d9 (diff) | |
download | mariadb-git-e74181e3c2eae882a382d532eefdc71156974ae2.tar.gz |
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.
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r-- | sql/sql_union.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 9b9418f0d29..971bb64cf2e 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -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 |