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

Assertion `!pk->has_virtual ()' failed in dict_index_build_internal_clust

Details

    Description

      Run with --mysqld=--innodb-page-size=8K

      --source include/have_innodb.inc
      CREATE TABLE t (c TEXT,PRIMARY KEY(c(1871))) ENGINE=InnoDB;
      

      Leads to:

      mysqld: /test/10.6_dbg/storage/innobase/dict/dict0dict.cc:2503: dict_index_t* dict_index_build_internal_clust(dict_index_t*): Assertion `!index->has_virtual()' failed.
      

      Original issue (outdated)

      Run with --mysqld=--innodb-page-size=8K

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a TEXT, PRIMARY KEY(a(1871))) ENGINE=InnoDB;
      ALTER TABLE t1 MODIFY IF EXISTS b TINYINT AFTER c;
       
      # Cleanup
      DROP TABLE t1;
      

      10.4 09e9f884

      mysqld: /data/src/10.4/storage/innobase/handler/handler0alter.cc:1487: bool instant_alter_column_possible(const dict_table_t&, const Alter_inplace_info*, const TABLE*, const TABLE*, bool): Assertion `!pk->has_virtual()' failed.
      190723 16:11:33 [ERROR] mysqld got signal 6 ;
       
      #6  0x00007fc1df1f2e67 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x5617050bf541 "!pk->has_virtual()", file=file@entry=0x5617050be608 "/data/src/10.4/storage/innobase/handler/handler0alter.cc", line=line@entry=1487, function=function@entry=0x5617050c4800 <instant_alter_column_possible(dict_table_t const&, Alter_inplace_info const*, TABLE const*, TABLE const*, bool)::__PRETTY_FUNCTION__> "bool instant_alter_column_possible(const dict_table_t&, const Alter_inplace_info*, const TABLE*, const TABLE*, bool)") at assert.c:92
      #7  0x00007fc1df1f2f12 in __GI___assert_fail (assertion=0x5617050bf541 "!pk->has_virtual()", file=0x5617050be608 "/data/src/10.4/storage/innobase/handler/handler0alter.cc", line=1487, function=0x5617050c4800 <instant_alter_column_possible(dict_table_t const&, Alter_inplace_info const*, TABLE const*, TABLE const*, bool)::__PRETTY_FUNCTION__> "bool instant_alter_column_possible(const dict_table_t&, const Alter_inplace_info*, const TABLE*, const TABLE*, bool)") at assert.c:101
      #8  0x000056170485d39b in instant_alter_column_possible (ib_table=..., ha_alter_info=0x7fc1d85bf7c0, table=0x7fc18c14e850, altered_table=0x7fc1d85bf850, strict=true) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:1487
      #9  0x000056170485f86f in ha_innobase::check_if_supported_inplace_alter (this=0x7fc18c00ada8, altered_table=0x7fc1d85bf850, ha_alter_info=0x7fc1d85bf7c0) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:2347
      #10 0x00005617043abe09 in mysql_alter_table (thd=0x7fc18c000b00, new_db=0x7fc18c0052b0, new_name=0x7fc18c0056b8, create_info=0x7fc1d85c1d30, table_list=0x7fc18c013218, alter_info=0x7fc1d85c1c70, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:9998
      #11 0x000056170443d8a7 in Sql_cmd_alter_table::execute (this=0x7fc18c0139f0, thd=0x7fc18c000b00) at /data/src/10.4/sql/sql_alter.cc:508
      #12 0x00005617042cb57d in mysql_execute_command (thd=0x7fc18c000b00) at /data/src/10.4/sql/sql_parse.cc:6098
      #13 0x00005617042d07ed in mysql_parse (thd=0x7fc18c000b00, rawbuf=0x7fc18c013108 "ALTER TABLE t1 MODIFY IF EXISTS b TINYINT AFTER c", length=49, parser_state=0x7fc1d85c3180, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7908
      #14 0x00005617042bca96 in dispatch_command (command=COM_QUERY, thd=0x7fc18c000b00, packet=0x7fc18c19dca1 "ALTER TABLE t1 MODIFY IF EXISTS b TINYINT AFTER c", packet_length=49, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1843
      #15 0x00005617042bb1dc in do_command (thd=0x7fc18c000b00) at /data/src/10.4/sql/sql_parse.cc:1360
      #16 0x0000561704434716 in do_handle_one_connection (connect=0x561707712a10) at /data/src/10.4/sql/sql_connect.cc:1404
      #17 0x0000561704434465 in handle_one_connection (arg=0x561707712a10) at /data/src/10.4/sql/sql_connect.cc:1306
      #18 0x0000561704d5fb09 in pfs_spawn_thread (arg=0x5617076913a0) at /data/src/10.4/storage/perfschema/pfs.cc:1862
      #19 0x00007fc1e0d674a4 in start_thread (arg=0x7fc1d85c4700) at pthread_create.c:456
      #20 0x00007fc1df2afd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      No crash on a non-debug build.
      The test case is not applicable to 10.3.

      Attachments

        Issue Links

          Activity

            marko it fortunately turned out that Long Unique algorithm removes HA_NOSAME flag from the index:

                  if (key_info->algorithm == HA_KEY_ALG_LONG_HASH)
                  {
                    key_part_end++;
                    key_info->flags&= ~HA_NOSAME;
                  }
            

            This is not suitable for PRIMARY key, so better to leave it only for UNIQUE. Besides, the uniqueness of hash is not expected, since it's only 8 bytes (see HA_HASH_FIELD_LENGTH).

            The uniqueness itself is guaranteed by check_duplicate_long_entries call from ha_write_row, and similar one from ha_update_row. Which is not suitable for PRIMARY key again

            nikitamalyavin Nikita Malyavin added a comment - marko it fortunately turned out that Long Unique algorithm removes HA_NOSAME flag from the index: if (key_info->algorithm == HA_KEY_ALG_LONG_HASH) { key_part_end++; key_info->flags&= ~HA_NOSAME; } This is not suitable for PRIMARY key, so better to leave it only for UNIQUE. Besides, the uniqueness of hash is not expected, since it's only 8 bytes (see HA_HASH_FIELD_LENGTH). The uniqueness itself is guaranteed by check_duplicate_long_entries call from ha_write_row, and similar one from ha_update_row. Which is not suitable for PRIMARY key again

            In mysql_prepare_create_table we have:

                if (is_hash_field_needed ||
                    (key_info->algorithm == HA_KEY_ALG_HASH &&
                     key->type != Key::PRIMARY &&
                     key_info->flags & HA_NOSAME &&
                     !(file->ha_table_flags() & HA_CAN_HASH_KEYS ) &&
                     file->ha_table_flags() & HA_CAN_VIRTUAL_COLUMNS))
            

            Suchwise, we have key->type Unable to render embedded object: File (:PRIMARY}} check, but it can be [wrongly) not found.] superseded by {{is_hash_field_needed, which, in turn, is set in a little cumbersome amount of ways.

            I will prevent this flag set to true for PRIMARY keys and will prettify the flag setup a little.

            nikitamalyavin Nikita Malyavin added a comment - In mysql_prepare_create_table we have: if (is_hash_field_needed || (key_info->algorithm == HA_KEY_ALG_HASH && key->type != Key::PRIMARY && key_info->flags & HA_NOSAME && !(file->ha_table_flags() & HA_CAN_HASH_KEYS ) && file->ha_table_flags() & HA_CAN_VIRTUAL_COLUMNS)) Suchwise, we have key->type Unable to render embedded object: File (:PRIMARY}} check, but it can be [wrongly) not found. ] superseded by {{is_hash_field_needed , which, in turn, is set in a little cumbersome amount of ways. I will prevent this flag set to true for PRIMARY keys and will prettify the flag setup a little.

            Please review commit 518abf49f4d59

            nikitamalyavin Nikita Malyavin added a comment - Please review commit 518abf49f4d59
            Roel Roel Van de Paar added a comment - - edited

            nikitamalyavin Thank you! Can you confirm that all testcases in this bug were tested against the patch and could you please include all (relevant) testcases into the patch if not covered in the main testcase already? Thanks!

            Roel Roel Van de Paar added a comment - - edited nikitamalyavin Thank you! Can you confirm that all testcases in this bug were tested against the patch and could you please include all (relevant) testcases into the patch if not covered in the main testcase already? Thanks!

            Roel yes, this long PRIMARY KEY is not forbidden (again), and the table will not be created in all these cases.

            The problem was that it accidentally considered PRIMARY key as long UNIQUE, which is meaningless. One can still create UNIQUE key with the same spec.

            nikitamalyavin Nikita Malyavin added a comment - Roel yes, this long PRIMARY KEY is not forbidden (again), and the table will not be created in all these cases. The problem was that it accidentally considered PRIMARY key as long UNIQUE, which is meaningless. One can still create UNIQUE key with the same spec.

            People

              nikitamalyavin Nikita Malyavin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              7 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.