Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-8644

Using a UDF in a virtual column causes a crash when stopping the server

    XMLWordPrintable

    Details

      Description

      Because MariaDB does not accept a constant virtual column (other DBMS's do) I was obliged to write the noconst UDF as:

      /***********************************************************************/
      /*  Returns its argument saying it is not a constant.                  */
      /***********************************************************************/
      my_bool noconst_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
      {
      	if (args->arg_count != 1 || args->arg_type[0] != STRING_RESULT) {
      		strcpy(message, "noconst unique argument must be a string");
      		return true;
      	} // endif arg
       
      	initid->const_item = false;    // The trick!
      	return false;
      } // end of noconst_init
       
      char *noconst(UDF_INIT *initid, UDF_ARGS *args, char *result,
      	unsigned long *res_length, char *, char *)
      {
      	return args->args[0];
      } // end of noconst

      Now, creating the table t1, inserting one line to it and displaying it does work:

      MariaDB [test]> create table t1 (
          -> n int key not null auto_increment,
          -> msg char(20) as (noconst('Hello World')) virtual);
      Query OK, 0 rows affected (0.06 sec)
       
      MariaDB [test]> insert into t1() values();
      Query OK, 1 row affected (0.01 sec)
       
      MariaDB [test]> select * from t1;
      +---+-------------+
      | n | msg         |
      +---+-------------+
      | 1 | Hello World |
      +---+-------------+
      1 row in set (0.00 sec)

      However, later on when stopping the server a crash occurs in the function:

      void udf_handler::cleanup()
      {
        if (!not_original)
        {
          if (initialized)
          {
            if (u_d->func_deinit != NULL)
            {
              Udf_func_deinit deinit= u_d->func_deinit;
              (*deinit)(&initid);
            }
            free_udf(u_d);
            initialized= FALSE;
          }
          if (buffers)				// Because of bug in ecc
            delete [] buffers;
          buffers= 0;
        }
      }

      See the attach udf_crash.log.
      The same kind of crash occurs with different other UDF's.

        Attachments

          Activity

            People

            Assignee:
            serg Sergei Golubchik
            Reporter:
            bertrandop Olivier Bertrand
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: