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

Assertion `ptr == a || ptr == b' failed in Field_bit::cmp upon query with GROUP_CONCAT

    Details

      Description

      SET group_concat_max_len= 1024;
       
      CREATE TABLE t1 ( 
          a TINYINT(44) ZEROFILL,
          b BIT(15),
          c BINARY(229)
      );
      CREATE VIEW v1 AS SELECT * FROM t1;
      INSERT INTO t1 VALUES
          (1,b'0','a'),(2,b'0','b'),(3,b'1','c'),(4,b'1','d'),
          (5,b'1','e'),(6,b'1','f'),(7,b'1','g'),(8,b'0','h');
      INSERT INTO t1 SELECT a.* FROM t1 a, t1 b, t1 c, t1 d;
       
      SELECT GROUP_CONCAT(c,b,a ORDER BY 3,2,1) AS f FROM v1;
       
      # Cleanup
      DROP VIEW v1;
      DROP TABLE t1;
      

      10.1 0573744a

      mysqld: /data/src/10.1/sql/field.h:3387: virtual int Field_bit::cmp(const uchar*, const uchar*): Assertion `ptr == a || ptr == b' failed.
      190508 15:22:54 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007fbe1f6acf12 in __GI___assert_fail (assertion=0x55e350e9cac0 "ptr == a || ptr == b", file=0x55e350e9c8df "/data/src/10.1/sql/field.h", line=3387, function=0x55e350ea1a00 <Field_bit::cmp(unsigned char const*, unsigned char const*)::__PRETTY_FUNCTION__> "virtual int Field_bit::cmp(const uchar*, const uchar*)") at assert.c:101
      #8  0x000055e350684acb in Field_bit::cmp (this=0x7fbe16903d20, a=0x7fbe16ad6195 "", b=0x7fbe16acb615 "") at /data/src/10.1/sql/field.h:3387
      #9  0x000055e35074cc06 in group_concat_key_cmp_with_order (arg=0x7fbe16845788, key1=0x7fbe16ad60a8, key2=0x7fbe16acb528) at /data/src/10.1/sql/item_sum.cc:2992
      #10 0x000055e350cf80bc in tree_insert (tree=0x7fbe210d45f0, key=0x7fbe16acb528, key_size=0, custom_arg=0x7fbe16845788) at /data/src/10.1/mysys/tree.c:210
      #11 0x000055e35074dc4d in copy_to_tree (key=0x7fbe16acb528, count=1, arg=0x7fbe210d45f0) at /data/src/10.1/sql/item_sum.cc:3324
      #12 0x000055e350cf8f76 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16acb508, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:551
      #13 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16acac88, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #14 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16ac9b88, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #15 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16ac7988, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #16 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16ac5788, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #17 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16ac1388, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #18 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16abce48, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #19 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16ab4648, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #20 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16aabe48, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #21 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16a9ad08, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #22 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16a89bc8, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #23 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16bf3a88, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #24 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16bd1888, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #25 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16b8d448, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #26 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16a5e088, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #27 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16a5e198, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #28 0x000055e350cf8f27 in tree_walk_left_root_right (tree=0x7fbe168458d8, element=0x7fbe16a5e3b8, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0) at /data/src/10.1/mysys/tree.c:550
      #29 0x000055e350cf8ebe in tree_walk (tree=0x7fbe168458d8, action=0x55e35074db86 <copy_to_tree(void*, element_count, void*)>, argument=0x7fbe210d45f0, visit=left_root_right) at /data/src/10.1/mysys/tree.c:538
      #30 0x000055e35074dd80 in Item_func_group_concat::repack_tree (this=0x7fbe16845788, thd=0x7fbe187d0070) at /data/src/10.1/sql/item_sum.cc:3342
      #31 0x000055e35074e1ac in Item_func_group_concat::add (this=0x7fbe16845788) at /data/src/10.1/sql/item_sum.cc:3410
      #32 0x000055e35074fa0d in Aggregator_simple::add (this=0x7fbe168faab8) at /data/src/10.1/sql/item_sum.h:672
      #33 0x000055e3504cf20b in Item_sum::aggregator_add (this=0x7fbe16845788) at /data/src/10.1/sql/item_sum.h:521
      #34 0x000055e3504c5894 in update_sum_func (func_ptr=0x7fbe1684a048) at /data/src/10.1/sql/sql_select.cc:23534
      #35 0x000055e3504bc829 in end_send_group (join=0x7fbe16848a20, join_tab=0x7fbe1684ada0, end_of_records=false) at /data/src/10.1/sql/sql_select.cc:19824
      #36 0x000055e3504b9ba0 in evaluate_join_record (join=0x7fbe16848a20, join_tab=0x7fbe1684aa58, error=0) at /data/src/10.1/sql/sql_select.cc:18702
      #37 0x000055e3504b9641 in sub_select (join=0x7fbe16848a20, join_tab=0x7fbe1684aa58, end_of_records=false) at /data/src/10.1/sql/sql_select.cc:18518
      #38 0x000055e3504b8ce9 in do_select (join=0x7fbe16848a20, fields=0x7fbe16848e20, table=0x0, procedure=0x0) at /data/src/10.1/sql/sql_select.cc:18134
      #39 0x000055e350493a18 in JOIN::exec_inner (this=0x7fbe16848a20) at /data/src/10.1/sql/sql_select.cc:3275
      #40 0x000055e350490cab in JOIN::exec (this=0x7fbe16848a20) at /data/src/10.1/sql/sql_select.cc:2562
      #41 0x000055e350494239 in mysql_select (thd=0x7fbe187d0070, rref_pointer_array=0x7fbe187d4560, tables=0x7fbe16845c90, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fbe16848a00, unit=0x7fbe187d3bb8, select_lex=0x7fbe187d42b8) at /data/src/10.1/sql/sql_select.cc:3499
      #42 0x000055e350489923 in handle_select (thd=0x7fbe187d0070, lex=0x7fbe187d3af0, result=0x7fbe16848a00, setup_tables_done_option=0) at /data/src/10.1/sql/sql_select.cc:376
      #43 0x000055e3504590f2 in execute_sqlcom_select (thd=0x7fbe187d0070, all_tables=0x7fbe16845c90) at /data/src/10.1/sql/sql_parse.cc:5951
      #44 0x000055e35044f453 in mysql_execute_command (thd=0x7fbe187d0070) at /data/src/10.1/sql/sql_parse.cc:3038
      #45 0x000055e35045cd6b in mysql_parse (thd=0x7fbe187d0070, rawbuf=0x7fbe16845088 "SELECT GROUP_CONCAT(c,b,a ORDER BY 3,2,1) AS f FROM v1", length=54, parser_state=0x7fbe210d61e0) at /data/src/10.1/sql/sql_parse.cc:7469
      #46 0x000055e35044b465 in dispatch_command (command=COM_QUERY, thd=0x7fbe187d0070, packet=0x7fbe1a7f0071 "", packet_length=54) at /data/src/10.1/sql/sql_parse.cc:1499
      #47 0x000055e35044a223 in do_command (thd=0x7fbe187d0070) at /data/src/10.1/sql/sql_parse.cc:1131
      #48 0x000055e350585745 in do_handle_one_connection (thd_arg=0x7fbe187d0070) at /data/src/10.1/sql/sql_connect.cc:1330
      #49 0x000055e35058548b in handle_one_connection (arg=0x7fbe187d0070) at /data/src/10.1/sql/sql_connect.cc:1242
      #50 0x000055e3509b8a8c in pfs_spawn_thread (arg=0x7fbe1ec39c70) at /data/src/10.1/storage/perfschema/pfs.cc:1861
      #51 0x00007fbe20d534a4 in start_thread (arg=0x7fbe210d7700) at pthread_create.c:456
      #52 0x00007fbe1f769d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      The problem is somehow related to group_concat_max_len, but not as simply as exceeding the value.

      Reproducible with MyISAM, Aria, InnoDB.

      Reproducible on 10.1, 10.2. Not reproducible yet on 10.3 and 10.4, but it might be because the commit with which it started happening is not in 10.3+ yet:

      commit 979cad229148ba8d28d94c1ca621bacd11847b66
      Author: Sergei Golubchik
      Date:   Wed Jun 21 16:07:54 2017 +0200
       
          MDEV-9531 GROUP_CONCAT with ORDER BY inside takes a lot of memory while it's executed
          
          group concat tree is allocated in a memroot, so the only way to free
          memory is to copy a part of the tree into a new memroot.
          
          track the accumilated length of the result, and when it crosses
          the threshold  - copy the result into a new tree, free the old one.
      

      No obvious problem on a non-debug build.

        Attachments

          Activity

            People

            • Assignee:
              serg Sergei Golubchik
              Reporter:
              elenst Elena Stepanova
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: