[MDEV-31153] New methods Schema::make_item_func_* for REPLACE, SUBSTRING, TRIM Created: 2023-04-29  Updated: 2023-08-01  Resolved: 2023-04-29

Status: Closed
Project: MariaDB Server
Component/s: Parser
Fix Version/s: 11.1.1, 10.11.3, 11.0.2, 10.4.29, 10.5.20, 10.6.13, 10.8.8, 10.9.6, 10.10.4

Type: Task Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-27744 LPAD in vcol created in ORACLE mode m... Closed

 Description   

In order to simplify the main patch for MDEV-27744, let's add the following methods into class Schema:

  virtual Item *make_item_func_replace(THD *thd,
                                       Item *subj,
                                       Item *find,
                                       Item *replace) const;
  virtual Item *make_item_func_substr(THD *thd,
                                      const Lex_substring_spec_st &spec) const;
 
  virtual Item *make_item_func_trim(THD *thd, const Lex_trim_st &spec) const;

where Lex_substring_spec_st is a new struct as follows:

class Lex_substring_spec_st
{
public:
  Item *m_subject;
  Item *m_from;
  Item *m_for;
  static Lex_substring_spec_st init(Item *subject,
                                    Item *from,
                                    Item *xfor= NULL)
  {
    Lex_substring_spec_st res;
    res.m_subject= subject;
    res.m_from= from;
    res.m_for= xfor;
    return res;
  }
};

Let's also add a new rule into sql_yacc.yy and sql_yacc_ora.yy:

substring_operands:
          expr ',' expr ',' expr
          {
            $$= Lex_substring_spec_st::init($1, $3, $5);
          }
        | expr ',' expr
          {
            $$= Lex_substring_spec_st::init($1, $3);
          }
        | expr FROM expr FOR_SYM expr
          {
            $$= Lex_substring_spec_st::init($1, $3, $5);
          }
        | expr FROM expr
          {
            $$= Lex_substring_spec_st::init($1, $3);
          }
        ;

The grammar code block creating the corresponding Item_func instances will change to:

        | TRIM '(' trim_operands ')'
          {
            if (unlikely(!($$= Schema::find_implied(thd)->
                                 make_item_func_trim(thd, $3))))
              MYSQL_YYABORT;
          }
...
        | SUBSTRING '(' substring_operands ')'
          {
            if (unlikely(!($$= Schema::find_implied(thd)->
                                 make_item_func_substr(thd, $3))))
              MYSQL_YYABORT;
          }
...
        | REPLACE '(' expr ',' expr ',' expr ')'
          {
            if (unlikely(!($$= Schema::find_implied(thd)->
                                 make_item_func_replace(thd, $3, $5, $7))))
              MYSQL_YYABORT;
          }

In the main patch for MDEV-27744 we'll also add similar blocks with an explicit schema specified.

This preparatory change is needed to reduce the amount of duplicate code for explicit and implicit schema branches.
This change is also good per se because it makes the code more symmetric/polymorthic for TRIM, SUBSTRING, REPLACE, and symmetric/polymorthic for sql_mode=DEFAULD vs sql_mode=ORACLE.


Generated at Thu Feb 08 10:21:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.