MySQL  8.0.17
Source Code Documentation
sql_udf.cc File Reference
#include "sql/sql_udf.h"
#include "my_config.h"
#include <stdio.h>
#include <string.h>
#include <iterator>
#include <memory>
#include <new>
#include <string>
#include <unordered_map>
#include <utility>
#include "m_ctype.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_sharedlib.h"
#include "my_sys.h"
#include "my_thread_local.h"
#include "mysql/components/service_implementation.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/components/services/mysql_rwlock_bits.h"
#include "mysql/components/services/psi_memory_bits.h"
#include "mysql/components/services/psi_rwlock_bits.h"
#include "mysql/psi/mysql_memory.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql/psi/psi_base.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/mdl.h"
#include "sql/mysqld.h"
#include "sql/records.h"
#include "sql/row_iterator.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_parse.h"
#include "sql/sql_plugin.h"
#include "sql/sql_table.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/transaction.h"
#include "thr_lock.h"
#include "sql/udf_registration_imp.h"

Functions

static udf_funcadd_udf (LEX_STRING *name, Item_result ret, char *dl, Item_udftype typ)
 
static void udf_hash_delete (udf_func *udf)
 Delete the UDF function from the UDF hash. More...
 
static void * find_udf_dl (const char *dl)
 
static char * init_syms (udf_func *tmp, char *nm)
 
static void init_udf_psi_keys (void)
 
void udf_init_globals ()
 Initialize the UDF global structures. More...
 
void udf_read_functions_table ()
 
void udf_unload_udfs ()
 Deintialize the UDF subsystem. More...
 
void udf_deinit_globals ()
 Deintialize the UDF subsystem. More...
 
void free_udf (udf_func *udf)
 
udf_funcfind_udf (const char *name, size_t length, bool mark_used)
 
static bool udf_end_transaction (THD *thd, bool rollback, udf_func *udf, bool insert_udf)
 Commit or rollback a transaction. More...
 
bool mysql_create_function (THD *thd, udf_func *udf)
 Create a user defined function. More...
 
bool mysql_drop_function (THD *thd, const LEX_STRING *udf_name)
 Drop a user defined function. More...
 
void udf_hash_rlock (void)
 
void udf_hash_unlock (void)
 
ulong udf_hash_size (void)
 
void udf_hash_for_each (udf_hash_for_each_func_t *func, void *arg)
 

Variables

static bool initialized = 0
 A local flag indicating whether SQL based UDF operations are allowed. More...
 
static MEM_ROOT mem
 
static collation_unordered_map< std::string, udf_func * > * udf_hash
 
static mysql_rwlock_t THR_LOCK_udf
 
static PSI_memory_key key_memory_udf_mem
 
static PSI_rwlock_key key_rwlock_THR_LOCK_udf
 
static PSI_rwlock_info all_udf_rwlocks []
 
static PSI_memory_info all_udf_memory []
 

Function Documentation

◆ add_udf()

static udf_func * add_udf ( LEX_STRING name,
Item_result  ret,
char *  dl,
Item_udftype  typ 
)
static

◆ find_udf()

udf_func* find_udf ( const char *  name,
size_t  length,
bool  mark_used 
)

◆ find_udf_dl()

static void * find_udf_dl ( const char *  dl)
static

◆ free_udf()

void free_udf ( udf_func udf)

◆ init_syms()

static char* init_syms ( udf_func tmp,
char *  nm 
)
static

◆ init_udf_psi_keys()

static void init_udf_psi_keys ( void  )
static

◆ mysql_create_function()

bool mysql_create_function ( THD thd,
udf_func udf 
)

Create a user defined function.

Atomicity: The operation to create a user defined function is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. UDF hash is in sync with operation state. UDF hash do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

Parameters
thdTHD context.
udfPointer to UDF function.
Note
Like implementations of other DDL/DML in MySQL, this function relies on the caller to close the thread tables. This is done in the end of dispatch_command().

◆ mysql_drop_function()

bool mysql_drop_function ( THD thd,
const LEX_STRING udf_name 
)

Drop a user defined function.

Atomicity: The operation to drop a user defined function is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. UDF hash is in sync with operation state. UDF hash do not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

Parameters
thdTHD context.
udf_nameName of the UDF function.

◆ udf_deinit_globals()

void udf_deinit_globals ( )

Deintialize the UDF subsystem.

This function does the following:

  1. Free the UDF hash.
  2. Free the memroot allocated.
  3. Destroy the RW mutex object.

◆ udf_end_transaction()

static bool udf_end_transaction ( THD thd,
bool  rollback,
udf_func udf,
bool  insert_udf 
)
static

Commit or rollback a transaction.

Also close tables which it has opened and release metadata locks. Add/Remove from the in-memory hash depending on transaction commit or rollback and the bool flag passed to this function.

Parameters
thdTHD context.
rollbackRollback transaction if true.
udfPointer to UDF function.
insert_udfInsert UDF in hash if true.
Return values
False- Success.
True- Error.

◆ udf_hash_delete()

static void udf_hash_delete ( udf_func udf)
static

Delete the UDF function from the UDF hash.

Parameters
udfPointer to the UDF function.
Note
The function remove the udf function from the udf hash if it is not in use. If the function is in use, the function name is renamed so that it is not used. The function shall be removed when no threads use it.

◆ udf_hash_for_each()

void udf_hash_for_each ( udf_hash_for_each_func_t func,
void *  arg 
)

◆ udf_hash_rlock()

void udf_hash_rlock ( void  )

◆ udf_hash_size()

ulong udf_hash_size ( void  )

◆ udf_hash_unlock()

void udf_hash_unlock ( void  )

◆ udf_init_globals()

void udf_init_globals ( )

Initialize the UDF global structures.

This is done as a separate step so that the UDF registration service can work when initalizing plugins, which happens before reading the UDF table.

◆ udf_read_functions_table()

void udf_read_functions_table ( )

◆ udf_unload_udfs()

void udf_unload_udfs ( )

Deintialize the UDF subsystem.

This function closes the shared libaries.

Variable Documentation

◆ all_udf_memory

PSI_memory_info all_udf_memory[]
static
Initial value:
= {{&key_memory_udf_mem, "udf_mem",
static PSI_memory_key key_memory_udf_mem
Definition: sql_udf.cc:145
#define PSI_FLAG_ONLY_GLOBAL_STAT
Global stat only flag.
Definition: psi_base.h:105
#define PSI_DOCUMENT_ME
Definition: psi_base.h:46

◆ all_udf_rwlocks

PSI_rwlock_info all_udf_rwlocks[]
static
Initial value:
"THR_LOCK_udf", PSI_FLAG_SINGLETON,
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: psi_base.h:54
static PSI_rwlock_key key_rwlock_THR_LOCK_udf
Definition: sql_udf.cc:148
#define PSI_DOCUMENT_ME
Definition: psi_base.h:46

◆ initialized

bool initialized = 0
static

A local flag indicating whether SQL based UDF operations are allowed.

Now the UDF structures are always allocated/deallocated due to the component service.

So this variable does not cover initialization/deinitialization of these. mem and THR_LOCK_udf are always initialized, even in –skip-grant-tables mode.

◆ key_memory_udf_mem

PSI_memory_key key_memory_udf_mem
static

◆ key_rwlock_THR_LOCK_udf

PSI_rwlock_key key_rwlock_THR_LOCK_udf
static

◆ mem

MEM_ROOT mem
static

◆ THR_LOCK_udf

mysql_rwlock_t THR_LOCK_udf
static

◆ udf_hash

collation_unordered_map<std::string, udf_func *>* udf_hash
static