Bug #19904 UDF: not initialized *is_null per row
Submitted: 18 May 2006 9:33 Modified: 13 Jul 2006 20:32
Reporter: Masaaki HIROSE Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.21 OS:Linux (Linux)
Assigned to: Chad MILLER CPU Architecture:Any

[18 May 2006 9:33] Masaaki HIROSE
Description:
It seems that *is_null in function "xxx()" on UDF source code is not initialized per row.

In some row, I set *is_null = 1 and return, all following rows *is_null is 1. In MySQL 5.0 We need *is_null=0 in top of "xxx()"?

MySQL 4.0.24 is initialized per row. (compare to below "How to repeat")
mysql> SELECT myfunc_double(n) from t;
+------------------+
| myfunc_double(n) |
+------------------+
|            49.00 |
|            50.00 |
|             NULL |
|            51.00 |
|            52.00 |
+------------------+

How to repeat:
CREATE TEMPORARY TABLE t (n INT);
TRUNCATE TABLE t;
INSERT INTO t VALUES (1),(2),(NULL),(3),(4);
SELECT myfunc_double(n) from t;

+------------------+
| myfunc_double(n) |
+------------------+
|            49.00 |
|            50.00 |
|             NULL |
|             NULL |
|             NULL |
+------------------+
[18 May 2006 21:34] Hartmut Holzgraefe
Verified using the following addition to the existing UDF test case

===== mysql-test/r/udf.result 1.4 vs edited =====
--- 1.4/mysql-test/r/udf.result 2006-04-27 16:32:35 +02:00
+++ edited/mysql-test/r/udf.result      2006-05-18 23:23:58 +02:00
@@ -76,6 +76,16 @@
 metaphon(testval)
 HL
 drop procedure xxx2;
+CREATE TABLE t1(n INT);
+INSERT INTO t1 VALUES (1),(2),(NULL),(3),(4);
+SELECT myfunc_double(n) AS f FROM t1;
+f
+49.00
+50.00
+NULL
+51.00
+52.00
+DROP TABLE t1;
 DROP FUNCTION metaphon;
 DROP FUNCTION myfunc_double;
 DROP FUNCTION myfunc_nonexist;
===== mysql-test/t/udf.test 1.4 vs edited =====
--- 1.4/mysql-test/t/udf.test   2006-04-27 16:32:35 +02:00
+++ edited/mysql-test/t/udf.test        2006-05-18 23:22:28 +02:00
@@ -99,6 +99,14 @@
 call XXX2();
 drop procedure xxx2;
 
+#-----------------------------------------------
+# Bug#19904 UDF: not initialized *is_null per row
+#-----------------------------------------------
+CREATE TABLE t1(n INT);
+INSERT INTO t1 VALUES (1),(2),(NULL),(3),(4);
+SELECT myfunc_double(n) AS f FROM t1;
+DROP TABLE t1;
+
 
 #
 # Drop the example functions from udf_example
[23 May 2006 23:44] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/6803
[8 Jun 2006 17:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7409
[26 Jun 2006 18:04] Chad MILLER
Available in 5.0.23.

A user-defined function, which is called on each row of a returned table, could receive a in_null state that is set, if it was set previously.  Now, the is_null is reset to False before each invocation of a UDF.
[13 Jul 2006 20:32] Paul DuBois
The fix went to 5.0.25.  Noted in 5.0.25 changelog.