Unary plus on $ZYSQLNULL value set from $ORDER() has a value of $ZYSQLNULL
Final Release Note
The unary plus (+) operator on a local variable node whose $ZYSQLNULL value was set from a $ORDER() return has a value of $ZYSQLNULL. Previously a unary plus on a node value of $ZYSQLNULL set from a $ORDER() return had a value of zero (0). This was encountered in the development environment and was never reported by a user. [#629 (closed)]
Description
Below is a simple example illustrating how the +
operator on $ZYSQLNULL
results in a $ZYSQLNULL
value.
YDB>set x=$ZYSQLNULL
YDB>set y=+x
YDB>zwrite x,y
x=$ZYSQLNULL
y=$ZYSQLNULL
But this stops working if $ZYSQLNULL
got returned by a $ORDER
on an lvn. Below is an example. The variable y
holds the value $ZYSQLNULL
initially after the $ORDER
operation. But once the set z=+y
is done, the variable y
holds the value ""
instead and the result of the +
in the variable z
ends up being 0
. We expect z
to hold the value $ZYSQLNULL
.
YDB>set x($ZYSQLNULL)=""
YDB>set y=$ORDER(x(""))
YDB>zwrite x,y
x($ZYSQLNULL)=""
y=$ZYSQLNULL
YDB>set z=+y
YDB>zwrite y,z
y=""
z=0
This issue was found while trying to fix YottaDB/DBMS/YDBOcto#574 (closed) (as part of YottaDB/DBMS/YDBOcto!743 (merged)) to use the +
operator on all numeric operands to force numeric coercion. The incorrect value of the +
computation caused a query to execute incorrectly. Because of this issue, YottaDB/DBMS/YDBOcto!743 (merged) was fixed to handle $ZYSQLNULL
first before attempting the +
operator (in the $$ForceNumeric^%ydboctoplanhelpers
function).
In Debug builds of YottaDB, the above test case results in the following assert failure.
%YDB-F-ASSERT, Assert failed in sr_port/s2n.c line 40 for expression (!MV_IS_SQLNULL(u))
Draft Release Note
Unary +
operator on an lvn that contains the value $ZYSQLNULL
correctly returns $ZYSQLNULL
even if the lvn value was set as a result of a $ORDER
operation. Previously (i.e. in YottaDB r1.30) this used to incorrectly return a 0
.