mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
WL#1447: Remove the UDF/function lookup in lex.
Moved the UDF and stored procedure lookup from sql_lex.cc to sql_yacc.yy. This will improve performance (since we don't have to check for stored functions in the lexer all the time), and make it possible to implement db qualified SPs. mysql-test/r/show_check.result: mysql.proc is not used in lex anymore (unless stored functions are really used). mysql-test/r/status.result: mysql.proc is not used in lex anymore (unless stored functions are really used). sql/sql_lex.cc: Moved the UDF and stored procedure lookup to sql_yacc.yy. sql/sql_yacc.yy: Moved the UDF and stored procedure lookup from sql_lex.cc. As a result, both stored function and UDF function calls get the argument list parsed the same way, so the "AS ..." syntax is recognized for both, eventhough it has no meaning for stored function.
This commit is contained in:
@ -127,7 +127,6 @@ insert into t1 values (1);
|
||||
show open tables;
|
||||
Database Table In_use Name_locked
|
||||
test t1 0 0
|
||||
mysql proc 0 0
|
||||
drop table t1;
|
||||
create table t1 (a int not null, b VARCHAR(10), INDEX (b) ) AVG_ROW_LENGTH=10 CHECKSUM=1 COMMENT="test" ENGINE=MYISAM MIN_ROWS=10 MAX_ROWS=100 PACK_KEYS=1 DELAY_KEY_WRITE=1 ROW_FORMAT=fixed;
|
||||
show create table t1;
|
||||
|
@ -14,6 +14,6 @@ update t1 set n = 3;
|
||||
unlock tables;
|
||||
show status like 'Table_lock%';
|
||||
Variable_name Value
|
||||
Table_locks_immediate 4
|
||||
Table_locks_immediate 3
|
||||
Table_locks_waited 1
|
||||
drop table t1;
|
||||
|
@ -166,38 +166,6 @@ static int find_keyword(LEX *lex, uint len, bool function)
|
||||
lex->yylval->symbol.length=len;
|
||||
return symbol->tok;
|
||||
}
|
||||
|
||||
LEX_STRING ls;
|
||||
ls.str = (char *)tok; ls.length= len;
|
||||
if (function && sp_function_exists(current_thd, &ls)) // QQ temp fix
|
||||
{
|
||||
lex->safe_to_cache_query= 0;
|
||||
lex->yylval->lex_str.str= lex->thd->strmake((char*)lex->tok_start, len);
|
||||
lex->yylval->lex_str.length= len;
|
||||
return SP_FUNC;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DLOPEN
|
||||
udf_func *udf;
|
||||
if (function && using_udf_functions && (udf=find_udf((char*) tok, len)))
|
||||
{
|
||||
lex->safe_to_cache_query=0;
|
||||
lex->yylval->udf=udf;
|
||||
switch (udf->returns) {
|
||||
case STRING_RESULT:
|
||||
return (udf->type == UDFTYPE_FUNCTION) ? UDF_CHAR_FUNC : UDA_CHAR_SUM;
|
||||
case REAL_RESULT:
|
||||
return (udf->type == UDFTYPE_FUNCTION) ? UDF_FLOAT_FUNC : UDA_FLOAT_SUM;
|
||||
case INT_RESULT:
|
||||
return (udf->type == UDFTYPE_FUNCTION) ? UDF_INT_FUNC : UDA_INT_SUM;
|
||||
case ROW_RESULT:
|
||||
default:
|
||||
// This case should never be choosen
|
||||
DBUG_ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -568,17 +568,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
%token SECOND_SYM
|
||||
%token SECOND_MICROSECOND_SYM
|
||||
%token SHARE_SYM
|
||||
%token SP_FUNC
|
||||
%token SUBDATE_SYM
|
||||
%token SUBSTRING
|
||||
%token SUBSTRING_INDEX
|
||||
%token TRIM
|
||||
%token UDA_CHAR_SUM
|
||||
%token UDA_FLOAT_SUM
|
||||
%token UDA_INT_SUM
|
||||
%token UDF_CHAR_FUNC
|
||||
%token UDF_FLOAT_FUNC
|
||||
%token UDF_INT_FUNC
|
||||
%token UNIQUE_USERS
|
||||
%token UNIX_TIMESTAMP
|
||||
%token USER
|
||||
@ -640,7 +633,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text
|
||||
UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal
|
||||
NCHAR_STRING opt_component key_cache_name
|
||||
SP_FUNC ident_or_spfunc sp_opt_label
|
||||
sp_opt_label
|
||||
|
||||
%type <lex_str_ptr>
|
||||
opt_table_alias
|
||||
@ -682,7 +675,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
simple_ident_nospvar simple_ident_q
|
||||
|
||||
%type <item_list>
|
||||
expr_list sp_expr_list udf_expr_list udf_expr_list2 when_list
|
||||
expr_list udf_expr_list udf_expr_list2 when_list
|
||||
ident_list ident_list_arg
|
||||
|
||||
%type <key_type>
|
||||
@ -700,10 +693,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
%type <table_list>
|
||||
join_table_list join_table
|
||||
|
||||
%type <udf>
|
||||
UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC
|
||||
UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM
|
||||
|
||||
%type <date_time_type> date_time_type;
|
||||
%type <interval> interval
|
||||
|
||||
@ -1029,7 +1018,7 @@ create:
|
||||
lex->name=$4.str;
|
||||
lex->create_info.options=$3;
|
||||
}
|
||||
| CREATE udf_func_type FUNCTION_SYM ident_or_spfunc
|
||||
| CREATE udf_func_type FUNCTION_SYM IDENT_sys
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
lex->udf.name = $4;
|
||||
@ -1097,11 +1086,6 @@ create:
|
||||
}
|
||||
;
|
||||
|
||||
ident_or_spfunc:
|
||||
IDENT_sys { $$= $1; }
|
||||
| SP_FUNC { $$= $1; }
|
||||
;
|
||||
|
||||
create_function_tail:
|
||||
RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
|
||||
{
|
||||
@ -1218,7 +1202,7 @@ sp_suid:
|
||||
;
|
||||
|
||||
call:
|
||||
CALL_SYM ident_or_spfunc
|
||||
CALL_SYM IDENT_sys
|
||||
{
|
||||
LEX *lex = Lex;
|
||||
|
||||
@ -3901,55 +3885,80 @@ simple_expr:
|
||||
{ $$= new Item_func_round($3,$5,1); }
|
||||
| TRUE_SYM
|
||||
{ $$= new Item_int((char*) "TRUE",1,1); }
|
||||
| SP_FUNC '(' sp_expr_list ')'
|
||||
| IDENT_sys '(' udf_expr_list ')'
|
||||
{
|
||||
sp_add_fun_to_lex(Lex, $1);
|
||||
if (sp_function_exists(YYTHD, &$1))
|
||||
{
|
||||
LEX *lex= Lex;
|
||||
|
||||
sp_add_fun_to_lex(lex, $1);
|
||||
if ($3)
|
||||
$$= new Item_func_sp($1, *$3);
|
||||
else
|
||||
$$= new Item_func_sp($1);
|
||||
}
|
||||
| UDA_CHAR_SUM '(' udf_expr_list ')'
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_DLOPEN
|
||||
udf_func *udf;
|
||||
|
||||
if (using_udf_functions && (udf=find_udf($1.str, $1.length)))
|
||||
{
|
||||
switch (udf->returns) {
|
||||
case STRING_RESULT:
|
||||
if (udf->type == UDFTYPE_FUNCTION)
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_sum_udf_str($1, *$3);
|
||||
$$ = new Item_func_udf_str(udf, *$3);
|
||||
else
|
||||
$$ = new Item_sum_udf_str($1);
|
||||
$$ = new Item_func_udf_str(udf);
|
||||
}
|
||||
| UDA_FLOAT_SUM '(' udf_expr_list ')'
|
||||
else
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_sum_udf_float($1, *$3);
|
||||
$$ = new Item_sum_udf_str(udf, *$3);
|
||||
else
|
||||
$$ = new Item_sum_udf_float($1);
|
||||
$$ = new Item_sum_udf_str(udf);
|
||||
}
|
||||
| UDA_INT_SUM '(' udf_expr_list ')'
|
||||
break;
|
||||
case REAL_RESULT:
|
||||
if (udf->type == UDFTYPE_FUNCTION)
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_sum_udf_int($1, *$3);
|
||||
$$ = new Item_func_udf_float(udf, *$3);
|
||||
else
|
||||
$$ = new Item_sum_udf_int($1);
|
||||
$$ = new Item_func_udf_float(udf);
|
||||
}
|
||||
| UDF_CHAR_FUNC '(' udf_expr_list ')'
|
||||
else
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_func_udf_str($1, *$3);
|
||||
$$ = new Item_sum_udf_float(udf, *$3);
|
||||
else
|
||||
$$ = new Item_func_udf_str($1);
|
||||
$$ = new Item_sum_udf_float(udf);
|
||||
}
|
||||
| UDF_FLOAT_FUNC '(' udf_expr_list ')'
|
||||
break;
|
||||
case INT_RESULT:
|
||||
if (udf->type == UDFTYPE_FUNCTION)
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_func_udf_float($1, *$3);
|
||||
$$ = new Item_func_udf_int(udf, *$3);
|
||||
else
|
||||
$$ = new Item_func_udf_float($1);
|
||||
$$ = new Item_func_udf_int(udf);
|
||||
}
|
||||
| UDF_INT_FUNC '(' udf_expr_list ')'
|
||||
else
|
||||
{
|
||||
if ($3 != NULL)
|
||||
$$ = new Item_func_udf_int($1, *$3);
|
||||
$$ = new Item_sum_udf_int(udf, *$3);
|
||||
else
|
||||
$$ = new Item_func_udf_int($1);
|
||||
$$ = new Item_sum_udf_int(udf);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
YYABORT;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_DLOPEN */
|
||||
}
|
||||
}
|
||||
| UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')'
|
||||
{
|
||||
@ -3997,10 +4006,6 @@ fulltext_options:
|
||||
| IN_SYM BOOLEAN_SYM MODE_SYM { $$= FT_BOOL; }
|
||||
;
|
||||
|
||||
sp_expr_list:
|
||||
/* empty */ { $$= NULL; }
|
||||
| expr_list { $$= $1;};
|
||||
|
||||
udf_expr_list:
|
||||
/* empty */ { $$= NULL; }
|
||||
| udf_expr_list2 { $$= $1;}
|
||||
|
Reference in New Issue
Block a user