constructor in dynamicly loaded library containing user defined functions not run when loading from mysql?

This is a discussion on constructor in dynamicly loaded library containing user defined functions not run when loading from mysql? within the MySQL Database forums, part of the Database Forums category; Hi, I've been writing a user defined function with a very expensive initialisation which only needs to run once. ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-26-2006
Alejandro Dubrovsky
 
Posts: n/a
Default constructor in dynamicly loaded library containing user defined functions not run when loading from mysql?

Hi,

I've been writing a user defined function with a very expensive
initialisation which only needs to run once. I thought it might be possible
to put it in the constructor section of the shared library object
(__attribute__((constructor)) function) to be run at dlopen time, but this
does not seem to be run when loading from mysql.
Is this really the case? If so, what's the correct way to go about solving
the situation? Would creating a soliton be ok?

(eg. the following dummy library returns 0 when called from mysql, but
should return 3 if the constructor would be run.

//start
#ifdef STANDARD
#include <stdio.h>
#include <string.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
typedef long long longlong;
#endif /*__WIN__*/
#else
#include <my_global.h>
#include <my_sys.h>
#endif
#include <mysql.h>


#ifdef HAVE_DLOPEN

extern "C" {
my_bool dummy_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void dummy_deinit(UDF_INIT *initid);
long long dummy(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
*error);
void __attribute__((constructor)) dummy_real_init(void);
void __attribute__((destructor)) dummy_real_deinit(void);
}

static long long secret = 0;
void __attribute__((constructor)) dummy_real_init(void) {
secret = 3;
}

void __attribute__((destructor)) dummy_real_deinit(void) {
secret = 1;
}

my_bool dummy_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
return 0;
}


void dummy_deinit(UDF_INIT *initid)
{
}

long long dummy(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char
*error)
{

return secret;
}


#endif /* HAVE_DLOPEN */

//end

Thanks,
alejandro

Reply With Quote
  #2 (permalink)  
Old 04-26-2006
Bill Karwin
 
Posts: n/a
Default Re: constructor in dynamicly loaded library containing user definedfunctions not run when loading from mysql?

Alejandro Dubrovsky wrote:
> I've been writing a user defined function with a very expensive
> initialisation which only needs to run once.


The above immediately gives me a gut feeling that the work done by your
UDF should be implemented in the application, not in a UDF.

Or alternately by using additional tables in the database. That is,
there are ways to keep predefined data in the database and use operators
like JOIN to perform work that could have been done by a UDF.

Regards,
Bill K.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0