[MDEV-8342] Support SELECT ... FROM table_func(...)" in the parser Created: 2015-06-19  Updated: 2015-06-28  Resolved: 2015-06-28

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Sergei Petrunia Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-8100 Table functions (aka SQL functions re... Stalled

 Description   

This is a part of dj's GSoC project.

Make the parser support

SELECT ... FROM table_func(parameters)

There is no execution yet. Attempt to run the statement should return an error.

The following is expected to work:

  • The parser should allow this statement
  • setup_tables() in SELECT code should check if parameters are base constants.
    • If they are not, emit an error.
    • If they are constants (i.e. everything would be ok), emit an error anyway. This way, we can have a minimal test suite.
  • name resolution in other parts e.g. UPDATE/DELETE can be ignored for now.


 Comments   
Comment by diwas joshi [ 2015-06-21 ]

This task required adding another rule for, using table functions in select queries, under table_factor in sql_yacc, but that was creating shift/reduce conflicts. Based on my discussion with Sergei on irc, we realized the problem seems to be in how the grammar handles bison's limitations. So we fixed it by factoring out the conflicting code in two rules into table_factor_part2. This fixed the problem. There was one more requirement of checking if the parameters are base constants or not. This was done by iterating over item_list and using basic_const_item(). Finally the input is getting parsed.

Comment by Sergei Petrunia [ 2015-06-22 ]

diwas, It would be nice if you submitted a separate patch for this task. The patch should do what is described in the description, and nothing else.

The patch you've sent as "changes3.diff" is not good - it does a part of this task, a part of MDEV-8344, and maybe something else. When I applied your patch and tried to run the query

select * from table_func('abc');

I got this crash:

  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7ffff7eb8700 (LWP 10443)]
  0x0000555555be4eec in MYSQLparse (thd=0x55555ab07b90) at /home/psergey/dev-git/10.1-gsoc/sql/sql_yacc.yy:10826
(gdb) p sel
  $2 = (SELECT_LEX *) 0x0
(gdb) p sel->get_item_list()
  Cannot access memory at address 0x0
(gdb) wher
  #0  0x0000555555be4eec in MYSQLparse (thd=0x55555ab07b90) at /home/psergey/dev-git/10.1-gsoc/sql/sql_yacc.yy:10826
  #1  0x0000555555a26e62 in parse_sql (thd=0x55555ab07b90, parser_state=0x7ffff7eb7110, creation_ctx=0x0, do_pfs_digest=true) at /home/psergey/dev-git/10.1-gsoc/sql/sql_parse.cc:9103
  #2  0x0000555555a22ea5 in mysql_parse (thd=0x55555ab07b90, rawbuf=0x7fff500051b8 "select * from table_func('abc')", length=31, parser_state=0x7ffff7eb7110) at /home/psergey/dev-git/10.1-gsoc/sql/sql_parse.cc:7116
  #3  0x0000555555a12061 in dispatch_command (command=COM_QUERY, thd=0x55555ab07b90, packet=0x55555ab0f2f1 "select * from table_func('abc')", packet_length=31) at /home/psergey/dev-git/10.1-gsoc/sql/sql_parse.cc:1462
  #4  0x0000555555a10e2b in do_command (thd=0x55555ab07b90) at /home/psergey/dev-git/10.1-gsoc/sql/sql_parse.cc:1090
  #5  0x0000555555b3dd04 in do_handle_one_connection (thd_arg=0x55555ab07b90) at /home/psergey/dev-git/10.1-gsoc/sql/sql_connect.cc:1347
  #6  0x0000555555b3da49 in handle_one_connection (arg=0x55555ab07b90) at /home/psergey/dev-git/10.1-gsoc/sql/sql_connect.cc:1258
  #7  0x00007ffff691de9a in start_thread (arg=0x7ffff7eb8700) at pthread_create.c:308
  #8  0x00007ffff604e3fd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
  #9  0x0000000000000000 in ?? ()

Comment by Sergei Petrunia [ 2015-06-23 ]

Before submitting the patch, please add a testcase into it (the same request as in MDEV-8343).

Comment by diwas joshi [ 2015-06-27 ]

The reviewed patch for this task has been pushed to https://github.com/djdij123/server.git this task can be closed now.

Generated at Thu Feb 08 07:26:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.