Commit 5a3a79ce authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-9637 select nullif(count(col1),0) gives wrong result if in a view

don't do special SUM_FUNC_ITEM treatment in NULLIF for views
(as before), but do it for derived tables (when
context_analysis_only == CONTEXT_ANALYSIS_ONLY_DERIVED)
parent c689e935
......@@ -1531,6 +1531,17 @@ View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select nullif(count(distinct `t1`.`col1`),0) AS `nullif(count(distinct col1),0)` from `t1` latin1 latin1_swedish_ci
drop view v1;
drop table t1;
create table t1 (col1 varchar(50) default null);
insert into t1 (col1) values ('hello'), ('hello'), ('hello');
create view v1 as select nullif(count(col1),0) from t1;
select * from v1;
nullif(count(col1),0)
3
select nullif(count(col1),0) from t1;
nullif(count(col1),0)
3
drop view v1;
drop table t1;
#
# End of 10.1 tests
#
......@@ -958,6 +958,17 @@ show create view v1;
drop view v1;
drop table t1;
#
# MDEV-9637 select nullif(count(col1),0) gives wrong result if in a view
#
create table t1 (col1 varchar(50) default null);
insert into t1 (col1) values ('hello'), ('hello'), ('hello');
create view v1 as select nullif(count(col1),0) from t1;
select * from v1;
select nullif(count(col1),0) from t1;
drop view v1;
drop table t1;
--echo #
--echo # End of 10.1 tests
--echo #
......@@ -2584,7 +2584,8 @@ Item_func_nullif::fix_length_and_dec()
args[0] and args[2] should still point to the same original l_expr.
*/
DBUG_ASSERT(args[0] == args[2] || thd->stmt_arena->is_stmt_execute());
if (args[0]->type() == SUM_FUNC_ITEM && !thd->lex->context_analysis_only)
if (args[0]->type() == SUM_FUNC_ITEM &&
!thd->lex->is_ps_or_view_context_analysis())
{
/*
NULLIF(l_expr, r_expr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment