MCPcopy Create free account
hub / github.com/MariaDB/server / execute_function

Method execute_function

sql/sp_head.cc:1896–2139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1894*/
1895
1896bool
1897sp_head::execute_function(THD *thd, Item **argp, uint argcount,
1898 Field *return_value_fld, sp_rcontext **func_ctx,
1899 Query_arena *call_arena)
1900{
1901 ulonglong UNINIT_VAR(binlog_save_options);
1902 bool need_binlog_call= FALSE;
1903 uint params= m_pcont->context_var_count();
1904 uint default_params= m_pcont->default_context_var_count();
1905 uint arg_no;
1906 sp_rcontext *octx = thd->spcont;
1907 char buf[STRING_BUFFER_USUAL_SIZE];
1908 String binlog_buf(buf, sizeof(buf), &my_charset_bin);
1909 bool err_status= FALSE;
1910 Query_arena backup_arena;
1911 DBUG_ENTER("sp_head::execute_function");
1912 DBUG_PRINT("info", ("function %s", m_name.str));
1913
1914 if (m_parent && m_parent->instantiate_if_needed(thd))
1915 DBUG_RETURN(true);
1916
1917 /*
1918 Check that the function is called with all specified arguments.
1919
1920 If it is not, use my_error() to report an error, or it will not terminate
1921 the invoking query properly.
1922 */
1923 if (argcount < (params - default_params) ||
1924 argcount > params)
1925 {
1926 /*
1927 Need to use my_error here, or it will not terminate the
1928 invoking query properly.
1929 */
1930 my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0),
1931 "FUNCTION", ErrConvDQName(this).ptr(),
1932 m_pcont->context_var_count(), argcount);
1933 DBUG_RETURN(TRUE);
1934 }
1935 /*
1936 Prepare arena and memroot for objects which lifetime is whole
1937 duration of function call (sp_rcontext, it's tables and items,
1938 sp_cursor and Item_cache holders for case expressions).
1939 We can't use caller's arena/memroot for those objects because
1940 in this case some fixed amount of memory will be consumed for
1941 each function/trigger invocation and so statements which involve
1942 lot of them will hog memory.
1943 TODO: we should create sp_rcontext once per command and reuse
1944 it on subsequent executions of a function/trigger.
1945 */
1946 if (!(*func_ctx))
1947 {
1948 thd->set_n_backup_active_arena(call_arena, &backup_arena);
1949
1950 if (!(*func_ctx= rcontext_create(thd, return_value_fld, argp, argcount)))
1951 {
1952 thd->restore_active_arena(call_arena, &backup_arena);
1953 err_status= TRUE;

Callers 1

execute_implMethod · 0.80

Calls 15

my_errorFunction · 0.85
ErrConvDQNameClass · 0.85
set_routine_security_ctxFunction · 0.85
get_query_idFunction · 0.85
query_error_codeFunction · 0.85
push_warningFunction · 0.85
context_var_countMethod · 0.80
instantiate_if_neededMethod · 0.80
restore_active_arenaMethod · 0.80

Tested by

no test coverage detected