PL/SQL parser (MDEV-10142)

[MDEV-13302] Avoid using LEX::spname during CREATE PROCEDURE and CREATE FUNCTION Created: 2017-07-12  Updated: 2018-08-31  Resolved: 2017-07-12

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.3
Fix Version/s: 10.3.1

Type: Technical task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: refactoring

Issue Links:
Blocks
blocks MDEV-10591 Oracle-style packages Closed
Sprint: 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

 Description   

The code in sp_create_routine() uses two ways to access the routine name:

  • Via sp_head: sp->m_db and sp->m_name
  • Via LEX: lex->spname

This is a fragment from sp_create_routine():

  if (!(table= open_proc_table_for_update(thd)))
  {
    my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(type),sp->m_name.str)
    goto done;
  }
  else
  {   
    /* Checking if the routine already exists */
    if (db_find_routine_aux(thd, type, lex->spname, table) == SP_OK)
    {

The function mysql_create_routine() uses the same style:

  if (check_db_name((LEX_STRING*) &lex->sphead->m_db))  
  {
  ...
    if (lex->create_info.or_replace())
  {
    if (check_routine_access(thd, ALTER_PROC_ACL, lex->spname->m_db.str,
  ...

In the above code, both LEX::sp_name and sp_sphead point to copies of the same qualified routine name. Copying is done in sql_yacc.yy:

             if (!Lex->make_sp_head_no_recursive(thd, $1, $2,
                                                 TYPE_ENUM_FUNCTION))
               MYSQL_YYABORT;
             Lex->spname= $2;

We're going to reuse sp_head to store Oracle-style packages soon (see MDEV-10591).
To avoid duplicating of this redundancy, we should get rid of it before implementing packages.

Under terms of this task we will:
1. Fix the code responsible for CREATE PROCEDURE and CREATE FUNCTION not to use lex->spname, and to use sphead instead. This includes functions:

  • mysql_create_routine()
  • sp_create_routine()

2. Remove copying of the routine name to LEX::spname. The latter should stay NULL during CREATE PROCEDURE and CREATE FUNCTION.



 Comments   
Comment by Alexander Barkov [ 2017-07-12 ]

Pushed to bb-10.2-ext

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