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

Statistics are lost after ALTER TABLE

    XMLWordPrintable

Details

    Description

      Merging to 10.5 the following code change of MDEV-23632 causes the last step of the test gcol.innodb_virtual_stats to fail:

       @@ -11189,44 +11237,19 @@ ha_innobase::commit_inplace_alter_table(
       	Currently dict_load_column_low() is the only place where
       	num_base for virtual columns is assigned to nonzero. */
       	if (ctx0->num_to_drop_vcol || ctx0->num_to_add_vcol
      +	    || (ctx0->new_table->n_v_cols && !new_clustered
      +		&& (ha_alter_info->alter_info->drop_list.elements
      +		    || ha_alter_info->alter_info->create_list.elements))
       	    || (ctx0->is_instant()
       		&& m_prebuilt->table->n_v_cols
       		&& ha_alter_info->handler_flags & ALTER_STORED_COLUMN_ORDER)) {
      ...
      

      The table will lose all persistent statistics:

      CURRENT_TEST: gcol.innodb_virtual_stats
      --- /mariadb/10.5m/mysql-test/suite/gcol/r/innodb_virtual_stats.result	2020-11-18 08:34:35.136411687 +0200
      +++ /mariadb/10.5m/mysql-test/suite/gcol/r/innodb_virtual_stats.reject	2021-01-11 12:57:24.756571844 +0200
      @@ -121,19 +121,4 @@
       FROM mysql.innodb_index_stats
       WHERE database_name = 'test' AND table_name = 't';
       index_name	stat_name	stat_description
      -GEN_CLUST_INDEX	n_diff_pfx01	DB_ROW_ID
      -GEN_CLUST_INDEX	n_leaf_pages	Number of leaf pages in the index
      -GEN_CLUST_INDEX	size	Number of pages in the index
      -idxb	n_diff_pfx01	b
      -idxb	n_diff_pfx02	b,DB_ROW_ID
      -idxb	n_leaf_pages	Number of leaf pages in the index
      -idxb	size	Number of pages in the index
      -vidxe	n_diff_pfx01	e
      -vidxe	n_diff_pfx02	e,DB_ROW_ID
      -vidxe	n_leaf_pages	Number of leaf pages in the index
      -vidxe	size	Number of pages in the index
      -vidxf	n_diff_pfx01	f
      -vidxf	n_diff_pfx02	f,DB_ROW_ID
      -vidxf	n_leaf_pages	Number of leaf pages in the index
      -vidxf	size	Number of pages in the index
       DROP TABLE t;
       
      mysqltest: Result length mismatch
      

      In both 10.4 and 10.5, we counter-intuitively have ha_alter_info->alter_info->create_list.elements == 5 for the preceding statement:

      ALTER TABLE t DROP INDEX vidxcd;
      

      The reason why this fails in 10.5 appears to be a change to "Remove not needed open/close call at end of inline alter table." The ha_innobase::open() call is needed for initializing the persistent statistics after a native ALTER TABLE:

      	if (ib_table->is_readable()) {
      		dict_stats_init(ib_table);
      	} else {
      		ib_table->stat_initialized = 1;
      	}
      

      I agree that this is not ideal, but that work-around was added in MySQL 5.7 and is not easy to remove without a major rewrite (MDEV-22363).

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.