[MDEV-23162] Improve Protocol performance for numeric data Created: 2020-07-14  Updated: 2020-08-14  Resolved: 2020-07-15

Status: Closed
Project: MariaDB Server
Component/s: Character Sets, Protocol
Fix Version/s: 10.5.5

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

Issue Links:
Blocks
is blocked by MDEV-23282 FLOAT(53,0) badly handles out-of-rang... Closed
Relates
relates to MDEV-23435 Functions do not convert numbers to c... Closed
relates to MDEV-23478 Improve Protocol performance for nume... Closed

 Description   

Recent benchmarks made by axel 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.


Generated at Thu Feb 08 09:20:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.