UDF crashes on View

You are viewing an old version of this question. View the current version here.

When using a UDF in the WHERE clause of a view, mariadb segfaults with

mysqld[17525]: segfault at 7f533c00b180 ip 00007f533f794dff sp 00007f5328e6b720 error 4 in libgcc_s.so.1[7f533f788000+11000]

Here is a test UDF (it just returns the length of the string)

#include <string.h>
#include <mariadb/mysql.h>

//  Check arguments
my_bool testudf_init(UDF_INIT* initid,UDF_ARGS* args,char* message)
{
   if (args->arg_count!=1 || args->arg_type[0]!=STRING_RESULT)
   {
      strcpy(message,"testudf takes one string arguments");
      return 1;
   }
   initid->maybe_null=0;
   initid->const_item=0;
   return 0;
}

//  Destructor
void testudf_deinit(UDF_INIT* initid)
{
}

//  Check if IP address is with Subnet
long long testudf(UDF_INIT* initid,UDF_ARGS* args,char* is_null,char* error)
{
   //  Never returns an error or null
   *is_null = 0;
   *error = 0;
   return args->lengths[0];
}

Here is how I build and install it:

mysql devdb -e "DROP FUNCTION IF EXISTS testudf"
cp -a testudf.so /usr/lib/x86_64-linux-gnu/mariadb19/plugin
chown root:root /usr/lib/x86_64-linux-gnu/mariadb19/plugin/testudf.so
mysql devdb -e "CREATE FUNCTION testudf RETURNS integer SONAME 'testudf.so'"

Here are the tests:

CREATE TABLE x(a CHAR(8));
CREATE TABLE y(a CHAR(8));
CREATE VIEW z AS SELECT a FROM x UNION SELECT a FROM y;
INSERT INTO x VALUES('cat');
INSERT INTO y VALUES('dog');
SELECT a,testudf(a) from x;
+------+------------+
| a    | testudf(a) |
+------+------------+
| cat  |          3 |
+------+------------+
1 row in set (0.001 sec)

SELECT a,testudf(a) from y;
+------+------------+
| a    | testudf(a) |
+------+------------+
| dog  |          3 |
+------+------------+
1 row in set (0.001 sec)

SELECT a,testudf(a) from z;
+------+------------+
| a    | testudf(a) |
+------+------------+
| cat  |          3 |
| dog  |          3 |
+------+------------+
2 rows in set (0.001 sec)

SELECT a FROM x WHERE testudf(a)>2;
+------+
| a    |
+------+
| cat  |
+------+
1 row in set (0.001 sec)

SELECT a FROM y WHERE testudf(a)>2;
+------+
| a    |
+------+
| dog  |
+------+
1 row in set (0.001 sec)

SELECT a FROM z WHERE testudf(a)>2;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Note that using the UDF in the WHERE clause of the view causes the segfault, but works fine everywhere else. I can't find anything in the docs that prohibits this. Is this a bug?

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.