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

Assertion `precision > 0' failed with a window function or window aggregate function

Details

    Description

      CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED);
      INSERT INTO t1 VALUES (1),(2);
      SELECT LAST_VALUE(d) OVER () FROM t1;
      # Can also be MIN(d) etc.
      

      10.2 e1f0f0dd0

      mysqld: /data/src/10.2/strings/decimal.c:1460: decimal_bin_size: Assertion `precision > 0' failed.
      170214  2:05:50 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f27c9a05312 in __GI___assert_fail (assertion=0x7f27cd2beee5 "precision > 0", file=0x7f27cd2bec60 "/data/src/10.2/strings/decimal.c", line=1460, function=0x7f27cd2bf150 <__PRETTY_FUNCTION__.11264> "decimal_bin_size") at assert.c:101
      #8  0x00007f27ccf23786 in decimal_bin_size (precision=0, scale=0) at /data/src/10.2/strings/decimal.c:1460
      #9  0x00007f27cc56d4b4 in my_decimal_get_binary_size (precision=0, scale=0) at /data/src/10.2/sql/my_decimal.h:263
      #10 0x00007f27cc727b4d in Field_new_decimal::Field_new_decimal (this=0x7f27c0c28060, len_arg=1, maybe_null_arg=true, name=0x7f27c0c644e8 "LAST_VALUE(d) OVER ()", dec_arg=0 '\000', unsigned_arg=false) at /data/src/10.2/sql/field.cc:2983
      #11 0x00007f27cc727cb9 in Field_new_decimal::create_from_item (mem_root=0x7f27c0d88b40, item=0x7f27c0c643f8) at /data/src/10.2/sql/field.cc:3028
      #12 0x00007f27cc551b7b in Item::create_tmp_field (this=0x7f27c0c643f8, group=false, table=0x7f27c0d88088, convert_int_length=9) at /data/src/10.2/sql/sql_select.cc:15880
      #13 0x00007f27cc428ff1 in Item::create_tmp_field (this=0x7f27c0c643f8, group=false, table=0x7f27c0d88088) at /data/src/10.2/sql/item.h:1722
      #14 0x00007f27cc551c80 in create_tmp_field_from_item (thd=0x7f27c0c16070, item=0x7f27c0c643f8, table=0x7f27c0d88088, copy_func=0x7f27cd5fe4f8, modify_item=true) at /data/src/10.2/sql/sql_select.cc:15924
      #15 0x00007f27cc5523cd in create_tmp_field (thd=0x7f27c0c16070, table=0x7f27c0d88088, item=0x7f27c0c643f8, type=Item::WINDOW_FUNC_ITEM, copy_func=0x7f27cd5fe4f8, from_field=0x7f27c0d89138, default_field=0x7f27c0d89118, group=false, modify_item=true, table_cant_handle_bit_fields=false, make_copy_field=false) at /data/src/10.2/sql/sql_select.cc:16142
      #16 0x00007f27cc5537cb in create_tmp_table (thd=0x7f27c0c16070, param=0x7f27c0c66da8, fields=..., group=0x0, distinct=false, save_sum_fields=false, select_options=2147748608, rows_limit=18446744073709551615, table_alias=0x7f27ccf6f664 "", do_not_open=true, keep_row_order=false) at /data/src/10.2/sql/sql_select.cc:16525
      #17 0x00007f27cc5308bd in JOIN::create_postjoin_aggr_table (this=0x7f27c0c64c68, tab=0x7f27c0c66268, table_fields=0x7f27c0c64f80, table_group=0x0, save_sum_fields=false, distinct=false, keep_row_order=false) at /data/src/10.2/sql/sql_select.cc:2813
      #18 0x00007f27cc52ecbc in JOIN::make_aggr_tables_info (this=0x7f27c0c64c68) at /data/src/10.2/sql/sql_select.cc:2392
      #19 0x00007f27cc52dec1 in JOIN::optimize_inner (this=0x7f27c0c64c68) at /data/src/10.2/sql/sql_select.cc:2150
      #20 0x00007f27cc52a3e8 in JOIN::optimize (this=0x7f27c0c64c68) at /data/src/10.2/sql/sql_select.cc:1081
      #21 0x00007f27cc533160 in mysql_select (thd=0x7f27c0c16070, tables=0x7f27c0c64560, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f27c0c64c48, unit=0x7f27c0c19b50, select_lex=0x7f27c0c1a280) at /data/src/10.2/sql/sql_select.cc:3633
      #22 0x00007f27cc527dbb in handle_select (thd=0x7f27c0c16070, lex=0x7f27c0c19a88, result=0x7f27c0c64c48, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:373
      #23 0x00007f27cc4f4255 in execute_sqlcom_select (thd=0x7f27c0c16070, all_tables=0x7f27c0c64560) at /data/src/10.2/sql/sql_parse.cc:6415
      #24 0x00007f27cc4ea294 in mysql_execute_command (thd=0x7f27c0c16070) at /data/src/10.2/sql/sql_parse.cc:3448
      #25 0x00007f27cc4f7c26 in mysql_parse (thd=0x7f27c0c16070, rawbuf=0x7f27c0c64088 "SELECT LAST_VALUE(d) OVER () FROM t1", length=36, parser_state=0x7f27cd5ffdd0, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7858
      #26 0x00007f27cc4e5d03 in dispatch_command (command=COM_QUERY, thd=0x7f27c0c16070, packet=0x7f27c0c58071 "SELECT LAST_VALUE(d) OVER () FROM t1", packet_length=36, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1812
      #27 0x00007f27cc4e4673 in do_command (thd=0x7f27c0c16070) at /data/src/10.2/sql/sql_parse.cc:1362
      #28 0x00007f27cc62d462 in do_handle_one_connection (connect=0x7f27c9071410) at /data/src/10.2/sql/sql_connect.cc:1354
      #29 0x00007f27cc62d1ef in handle_one_connection (arg=0x7f27c9071410) at /data/src/10.2/sql/sql_connect.cc:1260
      #30 0x00007f27cc97271c in pfs_spawn_thread (arg=0x7f27c900f9f0) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #31 0x00007f27cbb120a4 in start_thread (arg=0x7f27cd601300) at pthread_create.c:309
      #32 0x00007f27c9abf87d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            /10.4/strings/decimal.c:1466: decimal_bin_size: Assertion `precision > 0' failed.
             
            strings/decimal.c:1467(decimal_bin_size)[0x55f181b1b243]
            sql/my_decimal.h:325(my_decimal_get_binary_size(unsigned int, unsigned int))[0x55f18034c027]
            sql/field.cc:3125(Field_new_decimal::Field_new_decimal(unsigned char*, unsigned int, unsigned char*, unsigned char, Field::utype, st_mysql_const_lex_string const*, unsigned char, bool, bool))[0x55f1808c2120]
            sql/sql_type.cc:3130(Type_handler_newdecimal::make_table_field(st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE*) const)[0x55f180696a2f]
            sql/sql_type.cc:2956(Type_handler::make_and_init_table_field(st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE*) const)[0x55f18069591d]
            /10.4/sql/mysqld(_ZN4Item31tmp_table_field_from_field_typeEP5TABLE+0x228)[0x55f17ff8cfc2]
            sql/item.h:806(Item::tmp_table_field_from_field_type(TABLE*))[0x55f1802ff598]
            sql/sql_select.cc:17595(Item_result_field::create_tmp_field_ex(TABLE*, Tmp_field_src*, Tmp_field_param const*))[0x55f1802ffb92]
            sql/sql_select.cc:17668(create_tmp_field(TABLE*, Item*, Item***, Field**, Field**, bool, bool, bool, bool))[0x55f18030298b]
            sql/sql_select.cc:18063(create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long long, unsigned long long, st_mysql_const_lex_string const*, bool, bool))[0x55f1802a3b84]
            sql/sql_select.cc:3661(JOIN::create_postjoin_aggr_table(st_join_table*, List<Item>*, st_order*, bool, bool, bool))[0x55f18029fdf9]
            sql/sql_select.cc:3258(JOIN::make_aggr_tables_info())[0x55f18029c2cc]
            sql/sql_select.cc:2902(JOIN::optimize_stage2())[0x55f180295416]
            sql/sql_select.cc:2200(JOIN::optimize_inner())[0x55f18028f2eb]
            sql/sql_select.cc:1551(JOIN::optimize())[0x55f1802ac3e7]
            sql/sql_select.cc:4571(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x55f180283476]
            sql/sql_select.cc:424(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55f18020857a]
            sql/sql_parse.cc:6602(execute_sqlcom_select(THD*, TABLE_LIST*))[0x55f1801f56b6]
            sql/sql_parse.cc:3891(mysql_execute_command(THD*))[0x55f1802109bc]
            sql/sql_parse.cc:8154(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55f1801e93e8]
            sql/sql_parse.cc:1834(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55f1801e6327]
            sql/sql_parse.cc:1365(do_command(THD*))[0x55f18055b03b]
            sql/sql_connect.cc:1398(do_handle_one_connection(CONNECT*))[0x55f18055aa05]
            sql/sql_connect.cc:1302(handle_one_connection)[0x55f181918f1d]
            /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f543781c6ba]
            x86_64/clone.S:111(clone)[0x7f5436aad41d]
            

            alice Alice Sherepa added a comment - /10.4/strings/decimal.c:1466: decimal_bin_size: Assertion `precision > 0' failed.   strings/decimal.c:1467(decimal_bin_size)[0x55f181b1b243] sql/my_decimal.h:325(my_decimal_get_binary_size(unsigned int, unsigned int))[0x55f18034c027] sql/field.cc:3125(Field_new_decimal::Field_new_decimal(unsigned char*, unsigned int, unsigned char*, unsigned char, Field::utype, st_mysql_const_lex_string const*, unsigned char, bool, bool))[0x55f1808c2120] sql/sql_type.cc:3130(Type_handler_newdecimal::make_table_field(st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE*) const)[0x55f180696a2f] sql/sql_type.cc:2956(Type_handler::make_and_init_table_field(st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE*) const)[0x55f18069591d] /10.4/sql/mysqld(_ZN4Item31tmp_table_field_from_field_typeEP5TABLE+0x228)[0x55f17ff8cfc2] sql/item.h:806(Item::tmp_table_field_from_field_type(TABLE*))[0x55f1802ff598] sql/sql_select.cc:17595(Item_result_field::create_tmp_field_ex(TABLE*, Tmp_field_src*, Tmp_field_param const*))[0x55f1802ffb92] sql/sql_select.cc:17668(create_tmp_field(TABLE*, Item*, Item***, Field**, Field**, bool, bool, bool, bool))[0x55f18030298b] sql/sql_select.cc:18063(create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long long, unsigned long long, st_mysql_const_lex_string const*, bool, bool))[0x55f1802a3b84] sql/sql_select.cc:3661(JOIN::create_postjoin_aggr_table(st_join_table*, List<Item>*, st_order*, bool, bool, bool))[0x55f18029fdf9] sql/sql_select.cc:3258(JOIN::make_aggr_tables_info())[0x55f18029c2cc] sql/sql_select.cc:2902(JOIN::optimize_stage2())[0x55f180295416] sql/sql_select.cc:2200(JOIN::optimize_inner())[0x55f18028f2eb] sql/sql_select.cc:1551(JOIN::optimize())[0x55f1802ac3e7] sql/sql_select.cc:4571(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x55f180283476] sql/sql_select.cc:424(handle_select(THD*, LEX*, select_result*, unsigned long))[0x55f18020857a] sql/sql_parse.cc:6602(execute_sqlcom_select(THD*, TABLE_LIST*))[0x55f1801f56b6] sql/sql_parse.cc:3891(mysql_execute_command(THD*))[0x55f1802109bc] sql/sql_parse.cc:8154(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55f1801e93e8] sql/sql_parse.cc:1834(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55f1801e6327] sql/sql_parse.cc:1365(do_command(THD*))[0x55f18055b03b] sql/sql_connect.cc:1398(do_handle_one_connection(CONNECT*))[0x55f18055aa05] sql/sql_connect.cc:1302(handle_one_connection)[0x55f181918f1d] /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f543781c6ba] x86_64/clone.S:111(clone)[0x7f5436aad41d]
            varun Varun Gupta (Inactive) added a comment - Patch http://lists.askmonty.org/pipermail/commits/2020-July/014277.html

            Note that he issue is not reproducible in 10.5. This is because unsigned_flag is set here:

              Thread 15 "mysqld" hit Hardware watchpoint 3: -location unsigned_flag
              Old value = false
              New value = true
              0x0000555555ee3aa6 in Type_std_attributes::set (this=0x7fff9c0132d0, other=0x7fff9c013120) at /home/psergey/dev-git/10.5-cl2/sql/sql_type.h:2929
            (gdb) up
              #1  0x00005555563d32a8 in Item_window_func::fix_length_and_dec (this=0x7fff9c0132c8) at /home/psergey/dev-git/10.5-cl2/sql/item_windowfunc.h:1352
            (gdb) up
              #2  0x00005555563cf8e9 in Item_window_func::fix_fields (this=0x7fff9c0132c8, thd=0x7fff9c000d78, ref=0x7fff9c0133b8) at /home/psergey/dev-git/10.5-cl2/sql/item_windowfunc.cc:124
            

            psergei Sergei Petrunia added a comment - Note that he issue is not reproducible in 10.5. This is because unsigned_flag is set here: Thread 15 "mysqld" hit Hardware watchpoint 3: -location unsigned_flag Old value = false New value = true 0x0000555555ee3aa6 in Type_std_attributes::set (this=0x7fff9c0132d0, other=0x7fff9c013120) at /home/psergey/dev-git/10.5-cl2/sql/sql_type.h:2929 (gdb) up #1 0x00005555563d32a8 in Item_window_func::fix_length_and_dec (this=0x7fff9c0132c8) at /home/psergey/dev-git/10.5-cl2/sql/item_windowfunc.h:1352 (gdb) up #2 0x00005555563cf8e9 in Item_window_func::fix_fields (this=0x7fff9c0132c8, thd=0x7fff9c000d78, ref=0x7fff9c0133b8) at /home/psergey/dev-git/10.5-cl2/sql/item_windowfunc.cc:124

            Looking at other Items, I also can see that unsigned_flag is typically set in fix_length_and_dec function. I am not sure which settings must be done in fix_fields and which one in fix_length_in_dec (can one be called without another? If not, why is fix_length_and_dec virtual?)

            varun, in order to be consistent with the rest of the code, can you move the line that sets unsigned_flag into Item_window_func::fix_length_and_dec? (and NULL-merge this to 10.5 ?)

            Ok to push after this is addressed.

            psergei Sergei Petrunia added a comment - Looking at other Items, I also can see that unsigned_flag is typically set in fix_length_and_dec function. I am not sure which settings must be done in fix_fields and which one in fix_length_in_dec (can one be called without another? If not, why is fix_length_and_dec virtual?) varun , in order to be consistent with the rest of the code, can you move the line that sets unsigned_flag into Item_window_func::fix_length_and_dec? (and NULL-merge this to 10.5 ?) Ok to push after this is addressed.

            People

              varun Varun Gupta (Inactive)
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.