UDF функции в MySQL - PullRequest
       25

UDF функции в MySQL

0 голосов
/ 12 марта 2019

пытаюсь добавить функцию UDF в mysql 5.7.25, и функция успешно скомпилирована, и создается файл .SO.когда я запускаю запрос, я получаю следующую ошибку:

ОШИБКА 2013 (HY000): потеря соединения с сервером MySQL во время запроса

я просмотрел множество ссылок на эту темуошибка и внесла следующие изменения в системные переменные

    mysql> show variables like '%timeout%';
    +-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+

| connect_timeout             | 10   

   |
| delayed_insert_timeout      | 300  |

| have_statement_timeout      | YES  |

| innodb_flush_log_at_timeout | 1     |

| innodb_lock_wait_timeout    | 50   |


| innodb_rollback_on_timeout  | OFF  |


| interactive_timeout         | 28800  |

| lock_wait_timeout           | 31536000 |

| net_read_timeout            | 31536000 |

| net_write_timeout           | 31536000 |

| rpl_stop_slave_timeout      | 31536000 |

| slave_net_timeout           | 60       |

| wait_timeout                | 28800    |

+-----------------------------+----------+
13 rows in set (0.00 sec)

мой файл кода UDF

    #include <stdlib.h>

    #include <string.h>

    #include </usr/include/mysql/mysql.h>

    #include<math.h>

     struct store

        {

                double sum_x;

                double sum_y;

                double sum_xy;

                double sum_x_square;

                double count;

                double a,b,y;

        };

    my_bool linreg_init(UDF_INIT *initid, UDF_ARGS *args,char *message)

    {

     struct store  *data = malloc(sizeof(struct store));

      data->sum_x=0;

     data->sum_y=0;

    data->sum_xy=0;

     data->sum_x_square=0;

    data->count=0;

    data->a=0;

     data->b=0;

     data->y=0;


     initid->ptr = (char*) data;

     if (args->arg_count != 3)

     {

     strcpy(message, "linreg() can only accept 3 argument");

     return 1;

     }
        if (args->arg_type[0] != REAL_RESULT && args->arg_type[1]                    !=REAL_RESULT )              
&& args->arg_type[2] != REAL_RESULT)

     {

     strcpy(message, "linreg() argument has to be  a floating point number");

     return 1;

     }

     initid->decimals = 3;

     return 0;

    }




     void linreg_add(UDF_INIT *initid, UDF_ARGS *args,

       char *is_null, char *error)

      {
       struct store *data=(struct store *)initid->ptr;

         if (args->args[0] && args->args[1])
       {
       data->sum_x = data->sum_x +  *(double *)args->args[0];

       data->sum_y += *(double *)args->args[1];

       data->sum_xy +=( *(double *)args->args[0] * * (double *)args->args[1]);
        double temp= *(double *)args->args[0];
       data->sum_x_square +=pow(temp,2);

      data->count++;

       }

      }


    void linreg_clear(UDF_INIT *initid, char *is_null,char *error)

   {

     struct store *data=(struct store *)initid->ptr;

     data->sum_x = 0;

      data->sum_y = 0;

       data->sum_xy = 0;

       data->sum_x_square = 0;

       data->count = 0;

       data->a=0;

      data->b=0;

      data->y=0;



    }


    double linreg(UDF_INIT *initid, UDF_ARGS *args,char *is_null, char *error)

      {

      struct store *data=(struct store *)initid->ptr;

      double denom=  (data->count *  data->sum_x_square) - (data->sum_x * data     ->sum_x);
    double a= (data->count *  data->sum_xy  - (data->sum_x *  data->sum_y)  )/   denom;
  double b= ( (data->sum_y *  data->sum_x_square) - (data->sum_x *  data->sum_xy)) /denom;

    double  x=      *((double*)args->args[3]);

    return ( (a*x) +  b);
   }

После проверки файла журнала я получил

14:02:02 UTC - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 76388 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.



Thread pointer: 0x7f1d28014360
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7f1d50167e70 thread_stack 0x30000
/usr/sbin/mysqld(my_print_stacktrace+0x3b)[0xe94a9b]
/usr/sbin/mysqld(handle_fatal_signal+0x489)[0x78a9c9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f1d6aff8390]
/usr/lib/mysql/plugin/linreg.so(linreg+0xd4)[0x7f1d36dfcc2a]
/usr/sbin/mysqld(_ZN18Item_sum_udf_float8val_realEv+0x5e)[0xb5d1fe]
/usr/sbin/mysqld(_ZN4Item4sendEP8ProtocolP6String+0x10c)[0x7e5f8c]
/usr/sbin/mysqld(_ZN3THD19send_result_set_rowEP4ListI4ItemE+0x89)[0xc0cdf9]
/usr/sbin/mysqld(_ZN17Query_result_send9send_dataER4ListI4ItemE+0x5c)[0xc0cf6c]
/usr/sbin/mysqld(_Z14end_send_groupP4JOINP7QEP_TABb+0x438)[0xc24208]
/usr/sbin/mysqld(_ZN4JOIN4execEv+0x3e0)[0xc1e130]
/usr/sbin/mysqld(_Z12handle_queryP3THDP3LEXP12Query_resultyy+0x233)[0xc902d3]
/usr/sbin/mysqld[0x753e3b]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THDb+0x482b)[0xc51f2b]
/usr/sbin/mysqld(_Z11mysql_parseP3THDP12Parser_state+0x3ad)[0xc5447d]
/usr/sbin/mysqld(_Z16dispatch_commandP3THDPK8COM_DATA19enum_server_command+0x102a)[0xc555ba]
/usr/sbin/mysqld(_Z10do_commandP3THD+0x1c7)[0xc56a77]
/usr/sbin/mysqld(handle_connection+0x290)[0xd18fc0]
/usr/sbin/mysqld(pfs_spawn_thread+0x1b4)[0x11fd844]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f1d6afee6ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f1d6a48341d]


Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7f1d289340e0): is an invalid pointer
Connection ID (thread ID): 4
Status: NOT_KILLED

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
2019-03-12T14:02:02.630017Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2019-03-12T14:02:02.630101Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2019-03-12T14:02:02.784726Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-03-12T14:02:02.786062Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25-0ubuntu0.16.04.2) starting as process 7687 ...
2019-03-12T14:02:02.804827Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-03-12T14:02:02.804845Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-03-12T14:02:02.804851Z 0 [Note] InnoDB: Uses event mutexes
2019-03-12T14:02:02.804857Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-03-12T14:02:02.804862Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2019-03-12T14:02:02.804868Z 0 [Note] InnoDB: Using Linux native AIO
2019-03-12T14:02:02.805128Z 0 [Note] InnoDB: Number of pools: 1
2019-03-12T14:02:02.805230Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-03-12T14:02:02.806493Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-03-12T14:02:02.830942Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-03-12T14:02:02.838527Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-03-12T14:02:02.844141Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-03-12T14:02:02.845133Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 2641479
2019-03-12T14:02:02.845142Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 2641488
2019-03-12T14:02:02.845147Z 0 [Note] InnoDB: Database was not shutdown normally!
2019-03-12T14:02:02.845152Z 0 [Note] InnoDB: Starting crash recovery.
2019-03-12T14:02:02.962895Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-03-12T14:02:02.962957Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-03-12T14:02:02.963065Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-03-12T14:02:03.247020Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-03-12T14:02:03.249809Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-03-12T14:02:03.249847Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-03-12T14:02:03.250473Z 0 [Note] InnoDB: Waiting for purge to start
2019-03-12T14:02:03.301411Z 0 [Note] InnoDB: 5.7.25 started; log sequence number 2641488
2019-03-12T14:02:03.302314Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-03-12T14:02:03.306703Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-03-12T14:02:03.314709Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190312 19:32:03
2019-03-12T14:02:03.319445Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-03-12T14:02:03.319487Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2019-03-12T14:02:03.319511Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2019-03-12T14:02:03.319565Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2019-03-12T14:02:03.338737Z 0 [Note] Event Scheduler: Loaded 0 events
2019-03-12T14:02:03.339117Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.25-0ubuntu0.16.04.2'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
2019-03-12T14:02:03.637190Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)

iузнал, что в коде есть ошибка. но как я могу это исправить?в какой части ошибка?если есть ошибка, то как функция была скомпилирована?

как я могу исправить эту ошибку?заранее спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...