More input on the patch: Let's debug a regular table function: delimiter | create function f10() returns int deterministic begin return 1+3; end | delimiter ; flush tables; select f10(); Let's put a breakpoint on 'parse_sql': Breakpoint 4, parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb7100, creation_ctx=0x0, do_pfs_digest=true) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 (gdb) wher 5 #0 parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb7100, creation_ctx=0x0, do_pfs_digest=true) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 #1 0x0000555555a6929c in mysql_parse (thd=0x55555ac4aeb0, rawbuf=0x7fff5c007418 "select f10()", length=12, parser_state=0x7ffff7eb7100) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:7125 #2 0x0000555555a5838b in dispatch_command (command=COM_QUERY, thd=0x55555ac4aeb0, packet=0x55555ac51f71 "select f10()", packet_length=12) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:1470 #3 0x0000555555a570a5 in do_command (thd=0x55555ac4aeb0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:1093 #4 0x0000555555b95929 in do_handle_one_connection (thd_arg=0x55555ac4aeb0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_connect.cc:1347 ## Ok this is the query being parsed Breakpoint 4, parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb3e70, creation_ctx=0x7fff5c0089d0, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 (gdb) wher 5 #0 parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb3e70, creation_ctx=0x7fff5c0089d0, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 #1 0x0000555555dad91b in sp_compile (thd=0x55555ac4aeb0, defstr=0x7ffff7eb40f0, sql_mode=0, creation_ctx=0x7fff5c0089d0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:750 #2 0x0000555555dadd5b in db_load_routine (thd=0x55555ac4aeb0, type=TYPE_ENUM_FUNCTION, name=0x7ffff7eb5ca0, sphp=0x7ffff7eb5f00, sql_mode=0, params=0x5555564419b8 "", returns=0x7fff5c008960 "int(11)", body=0x7fff5c008968 "begin return 1+3; end", chistics=..., definer_user_name=0x7ffff7eb57b0, definer_host_name=0x7ffff7eb57c0, created=20150803231227, modified=20150803231227, creation_ctx=0x7fff5c0089d0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:876 #3 0x0000555555dad6d2 in db_find_routine (thd=0x55555ac4aeb0, type=TYPE_ENUM_FUNCTION, name=0x7ffff7eb5ca0, sphp=0x7ffff7eb5f00) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:666 #4 0x0000555555db1a28 in sp_cache_routine (thd=0x55555ac4aeb0, type=TYPE_ENUM_FUNCTION, name=0x7ffff7eb5ca0, lookup_only=false, sp=0x7ffff7eb5f00) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:2181 ## Ok, ot seems that something is parsing the stored function definition. Now, let's debug the example from the previous email: Breakpoint 4, parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb7100, creation_ctx=0x0, do_pfs_digest=true) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 (gdb) wher 4 #0 parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb7100, creation_ctx=0x0, do_pfs_digest=true) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 #1 0x0000555555a6929c in mysql_parse (thd=0x55555ac4aeb0, rawbuf=0x7fff5c007418 "select 1 from f1('aaa')", length=23, parser_state=0x7ffff7eb7100) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:7125 #2 0x0000555555a5838b in dispatch_command (command=COM_QUERY, thd=0x55555ac4aeb0, packet=0x55555ac51f71 "select 1 from f1('aaa')", packet_length=23) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:1470 #3 0x0000555555a570a5 in do_command (thd=0x55555ac4aeb0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:1093 ## this is the query. Breakpoint 4, parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb1c80, creation_ctx=0x7fff5c007db0, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 (gdb) wher 4 #0 parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb1c80, creation_ctx=0x7fff5c007db0, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 #1 0x0000555555dad91b in sp_compile (thd=0x55555ac4aeb0, defstr=0x7ffff7eb1f00, sql_mode=0, creation_ctx=0x7fff5c007db0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:750 #2 0x0000555555dadd5b in db_load_routine (thd=0x55555ac4aeb0, type=TYPE_ENUM_FUNCTION, name=0x7fff5c007c48, sphp=0x7ffff7eb3948, sql_mode=0, params=0x7fff5c007ce8 "param1 VARCHAR(11)", returns=0x7fff5c007d00 "TABLE t1(name varchar(11))", body=0x7fff5c007d20 "BEGIN\nINSERT INTO t1 SELECT a FROM t2 WHERE id = param1;\nEND", chistics=..., definer_user_name=0x7ffff7eb35c0, definer_host_name=0x7ffff7eb35d0, created=20150803230051, modified=20150803230051, creation_ctx=0x7fff5c007db0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:876 #3 0x0000555555dad6d2 in db_find_routine (thd=0x55555ac4aeb0, type=TYPE_ENUM_FUNCTION, name=0x7fff5c007c48, sphp=0x7ffff7eb3948) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sp.cc:666 (More stack frames follow...) ## This something parsing the definition. Breakpoint 4, parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb4580, creation_ctx=0xb, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 (gdb) wher 4 #0 parse_sql (thd=0x55555ac4aeb0, parser_state=0x7ffff7eb4580, creation_ctx=0xb, do_pfs_digest=false) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9090 #1 0x0000555555a6dcbb in check_and_process_table_functions (thd=0x55555ac4aeb0, table_list=0x7fff5c007640) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:9336 #2 0x0000555555a5ab77 in mysql_execute_command (thd=0x55555ac4aeb0) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:2471 #3 0x0000555555a6942e in mysql_parse (thd=0x55555ac4aeb0, rawbuf=0x7fff5c007418 "select 1 from f1('aaa')", length=23, parser_state=0x7ffff7eb7100) at /home/psergey/dev-git/10.1-gsoc-repo/sql/sql_parse.cc:7174 (More stack frames follow...) ## this is the code you've added. A question: why is your code trying to parse SP definition if it was just parsed? BR Sergei -- Sergei Petrunia, Software Developer MariaDB Corporation | Skype: sergefp | Blog: http://s.petrunia.net/blog