Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-31153

New methods Schema::make_item_func_* for REPLACE, SUBSTRING, TRIM

    XMLWordPrintable

Details

    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.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.