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

Improve Protocol performance for numeric data

    XMLWordPrintable

    Details

      Description

      Recent benchmarks made by Axel Schwenke revealed that CPU is unnecessarily wasted on character string conversion for numeric data types, e.g. in this scenario:

      SET NAMES utf8;
      CREATE OR REPLACE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (1);
      SELECT a FROM t1;
      

      Although no character set conversion is needed in this case, the execution gets int my_convert() with this stack:

      #0  my_convert (to=0x7fff8c00dfa9 "def\004test\002t1\002t1\001a\001a\f?", 
          to_length=3, to_cs=0x55555789b500 <my_charset_utf8mb3_general_ci>, 
          from=0x7ffff4bebbc0 "1q\315VUU", from_length=1, 
          from_cs=0x5555577952c0 <my_charset_latin1>, errors=0x7ffff4bebae4)
          at /home/bar/maria-git/server.10.5.clu/strings/ctype.c:1225
      #1  0x0000555555d40f3b in copy_and_convert (
          to=0x7fff8c00dfa9 "def\004test\002t1\002t1\001a\001a\f?", to_length=3, 
          to_cs=0x55555789b500 <my_charset_utf8mb3_general_ci>, 
          from=0x7ffff4bebbc0 "1q\315VUU", from_length=1, 
          from_cs=0x5555577952c0 <my_charset_latin1>, errors=0x7ffff4bebae4)
          at /home/bar/maria-git/server.10.5.clu/sql/sql_string.h:51
      #2  0x0000555555d3bca3 in Protocol::net_store_data_cs (this=0x7fff8c001340, 
          from=0x7ffff4bebbc0 "1q\315VUU", length=1, 
          from_cs=0x5555577952c0 <my_charset_latin1>, 
          to_cs=0x55555789b500 <my_charset_utf8mb3_general_ci>)
          at /home/bar/maria-git/server.10.5.clu/sql/protocol.cc:118
      #3  0x0000555555d3ec51 in Protocol::store_string_aux (this=0x7fff8c001340, 
          from=0x7ffff4bebbc0 "1q\315VUU", length=1, 
          fromcs=0x5555577952c0 <my_charset_latin1>, 
          tocs=0x55555789b500 <my_charset_utf8mb3_general_ci>)
          at /home/bar/maria-git/server.10.5.clu/sql/protocol.cc:1186
      #4  0x0000555555d3fa62 in Protocol_text::store (this=0x7fff8c001340, 
          field=0x7fff8c086158)
          at /home/bar/maria-git/server.10.5.clu/sql/protocol.cc:1340
      #5  0x00005555561f790f in Item_field::send (this=0x7fff8c016a20, 
          protocol=0x7fff8c001340, buffer=0x7ffff4bebf90)
          at /home/bar/maria-git/server.10.5.clu/sql/item.cc:7229
      #6  0x0000555555d3e823 in Protocol::send_result_set_row (this=0x7fff8c001340, 
          row_items=0x7fff8c014ff8)
      

      Let's fix the code to avoid this conversion:

      • Add a new parameter of the my_repertoire_t to Protocol::store_string_aux()
      • Fix Protocol_text::store() and all affected functions to pass the Field's repertoire inside store_string_aux()
      • Fix Protocol::store_string_aux() to use memcpy() instead of my_convert() if the source repertoire is MY_REPERTOIRE_ASCII and character_set_results is ASCII-compatible.

      This should improve performance slightly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: