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

Cleanup: Move MEM_ROOT allocation methods from THD to Query_arena

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 11.3.0
    • OTHER
    • None

    Description

      The class Query_arena has a number of methods allocating data on Query_arena::mem_root:

        inline void* alloc(size_t size) const { return alloc_root(mem_root,size); }
        inline void* calloc(size_t size) const
        {
          void *ptr;
          if (likely((ptr=alloc_root(mem_root,size))))
            bzero(ptr, size);
          return ptr;
        }
        inline char *strdup(const char *str) const
        { return strdup_root(mem_root,str); }
        inline char *strmake(const char *str, size_t size) const
        { return strmake_root(mem_root,str,size); }
        inline LEX_CSTRING strcat(const LEX_CSTRING &a, const LEX_CSTRING &b) const
        {
          char *buf= (char*)alloc(a.length + b.length + 1);
          if (unlikely(!buf))
            return null_clex_str;
          memcpy(buf, a.str, a.length);
          memcpy(buf + a.length, b.str, b.length);
          buf[a.length + b.length] = 0;
          return {buf, a.length + b.length};
        }
        inline void *memdup(const void *str, size_t size) const
        { return memdup_root(mem_root,str,size); }
        inline void *memdup_w_gap(const void *str, size_t size, size_t gap) const
        {
          void *ptr;
          if (likely((ptr= alloc_root(mem_root,size+gap))))
            memcpy(ptr,str,size);
          return ptr;
        }
      

      Additionally, {{class THD} has more methods allocating data on Query_arena::mem_root:

        LEX_CSTRING strmake_lex_cstring(const char *str, size_t length) const
        {
          const char *tmp= strmake_root(mem_root, str, length);
          if (!tmp)
            return {0,0};
          return {tmp, length};
        }
        LEX_CSTRING strmake_lex_cstring(const LEX_CSTRING &from) const
        {
          return strmake_lex_cstring(from.str, from.length);
        }
       
        LEX_STRING *make_lex_string(LEX_STRING *lex_str, const char* str,
                                    size_t length) const
        {
          if (!(lex_str->str= strmake_root(mem_root, str, length)))
          {
            lex_str->length= 0;
            return 0;
          }
          lex_str->length= length;
          return lex_str;
        }
        LEX_CSTRING *make_lex_string(LEX_CSTRING *lex_str, const char* str,
                                     size_t length) const
        {
          if (!(lex_str->str= strmake_root(mem_root, str, length)))
          {
            lex_str->length= 0;
            return 0;
          }
          lex_str->length= length;
          return lex_str;
        }
      };
      

      These methods use nothing of THD except Query_arena::mem_root.

      Obviously, these methods are in a wrong place. Let's move them to Query_arena, so all MEM_ROOT allocating methods reside in the same place.

      Note, MDEV-31606 will add some more MEM_ROOT allocating methods to Query_arena. It's better to collect all allocating methods into one place.

      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.