Skip to content

Commit

Permalink
MDEV-9637 select nullif(count(col1),0) gives wrong result if in a view
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vuvova committed Mar 5, 2016
1 parent c689e93 commit 5a3a79c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mysql-test/r/null.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
11 changes: 11 additions & 0 deletions mysql-test/t/null.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
3 changes: 2 additions & 1 deletion sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5a3a79c

Please sign in to comment.