diff --git a/core/sql/exp/exp_bool.cpp b/core/sql/exp/exp_bool.cpp index fa86efc6f6..037a8e1d36 100644 --- a/core/sql/exp/exp_bool.cpp +++ b/core/sql/exp/exp_bool.cpp @@ -96,7 +96,7 @@ ex_expr::exp_return_type ex_branch_clause::eval(char *op_data[], switch (getOperType()) { case ITM_AND: - if (*(Lng32 *)op_data[1] == 0) + if (*(Lng32 *)op_data[1] == 0 || *(Lng32 *)op_data[1] == -1) // null treated as false { *(Lng32 *)op_data[0] = 0; setNextClause(branch_clause); diff --git a/core/sql/exp/exp_eval.cpp b/core/sql/exp/exp_eval.cpp index 00fbcc4da6..6ffdb253bf 100644 --- a/core/sql/exp/exp_eval.cpp +++ b/core/sql/exp/exp_eval.cpp @@ -6600,7 +6600,7 @@ ex_expr::exp_return_type ex_expr::evalPCode(PCodeBinary* pCode32, PTR_DEF_ASSIGN(Int32, srcPtr, 2 + 2 * PCODEBINARIES_PER_PTR ); Int32 src = *srcPtr; - if (src == 0) + if (src == 0 || src == -1) // null(i.e. -1) means false { DEF_ASSIGN_PTR(Int64, branchOffset, 0 ); *tgtPtr = 0; diff --git a/core/sql/regress/core/EXPECTED001.SB b/core/sql/regress/core/EXPECTED001.SB index 8870be42c3..451a7f5c82 100644 --- a/core/sql/regress/core/EXPECTED001.SB +++ b/core/sql/regress/core/EXPECTED001.SB @@ -14,7 +14,7 @@ >>invoke t001t1; -- Definition of Trafodion table TRAFODION.SCH.T001T1 --- Definition current Mon Mar 7 19:30:10 2016 +-- Definition current Sat Nov 17 15:05:31 2018 ( SYSKEY LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE @@ -32,7 +32,7 @@ >>invoke $$TEST_SCHEMA$$.t001ut1; -- Definition of Trafodion table TRAFODION.SCH.T001UT1 --- Definition current Mon Mar 7 19:30:10 2016 +-- Definition current Sat Nov 17 15:05:32 2018 ( SYSKEY LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE @@ -433,6 +433,94 @@ A --- 2 row(s) selected. >> -- ok >> +>>-- clause way +>>cqd pcode_opt_level 'off'; + +--- SQL operation complete. +>>select case when cast(null as int) > 0 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>> +>>select case when cast(null as int) > 0 and 2>1 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>>select case when cast(null as int) > 0 or 2>1 then 1/0 else 0 end from dual; + +*** ERROR[8419] An arithmetic expression attempted a division by zero. + +--- 0 row(s) selected. +>> +>>select case when cast(null as int) > 0 and 2>3 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>>select case when cast(null as int) > 0 or 2>3 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>> +>>-- PCODE way +>>cqd pcode_opt_level 'on'; + +--- SQL operation complete. +>>select case when cast(null as int) > 0 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>> +>>select case when cast(null as int) > 0 and 2>1 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>>select case when cast(null as int) > 0 or 2>1 then 1/0 else 0 end from dual; + +*** ERROR[8419] An arithmetic expression attempted a division by zero. + +--- 0 row(s) selected. +>> +>>select case when cast(null as int) > 0 and 2>3 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>>select case when cast(null as int) > 0 or 2>3 then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>> >>select a from t001t1 where null is null; A @@ -447,6 +535,22 @@ A --- 0 row(s) selected. >> -- ok (0 rows) +>> +>>-- = NULL is not ANSI +>>select case when 3 is null then 1/0 else 0 end from dual; + +(EXPR) +------- + + .0 + +--- 1 row(s) selected. +>>select case when 3 = null then 1/0 else 0 end from dual; + +*** ERROR[4099] A NULL operand is not allowed in predicate (3 = NULL). + +*** ERROR[8822] The statement was not prepared. + >> >> >>-- PARAM queries diff --git a/core/sql/regress/core/TEST001 b/core/sql/regress/core/TEST001 index cd0ec0ad06..a67253e2c0 100755 --- a/core/sql/regress/core/TEST001 +++ b/core/sql/regress/core/TEST001 @@ -128,9 +128,33 @@ select (case a when null then 1 else 2 end) from t001t1; select (case a when 1 then 1 when null then 2 else 3 end) from t001t1; select (case a when 1 then 1 when 2 then 2 else null end) from t001t1; -- ok +-- clause way +cqd pcode_opt_level 'off'; +select case when cast(null as int) > 0 then 1/0 else 0 end from dual; + +select case when cast(null as int) > 0 and 2>1 then 1/0 else 0 end from dual; +select case when cast(null as int) > 0 or 2>1 then 1/0 else 0 end from dual; + +select case when cast(null as int) > 0 and 2>3 then 1/0 else 0 end from dual; +select case when cast(null as int) > 0 or 2>3 then 1/0 else 0 end from dual; + +-- PCODE way +cqd pcode_opt_level 'on'; +select case when cast(null as int) > 0 then 1/0 else 0 end from dual; + +select case when cast(null as int) > 0 and 2>1 then 1/0 else 0 end from dual; +select case when cast(null as int) > 0 or 2>1 then 1/0 else 0 end from dual; + +select case when cast(null as int) > 0 and 2>3 then 1/0 else 0 end from dual; +select case when cast(null as int) > 0 or 2>3 then 1/0 else 0 end from dual; + select a from t001t1 where null is null; -- ok select a from t001t1 where null is not null; -- ok (0 rows) +-- = NULL is not ANSI +select case when 3 is null then 1/0 else 0 end from dual; +select case when 3 = null then 1/0 else 0 end from dual; + -- PARAM queries set param ?p 10;