Bug #118817 Code Comment Error for row_import::m_n_instant_cols in storage/innobase/row/row0import.cc
Submitted: 12 Aug 11:35 Modified: 13 Aug 7:22
Reporter: Wuhao Cao (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: code comment, INSTANT add column

[12 Aug 11:35] Wuhao Cao
Description:
There is an error in the code comment for the variable m_n_instant_cols. According to the code logic:

/* If .cfg file indicates no INSTANT column in source table. */
if (m_n_instant_cols == 0) {
  /* But if target table has INSTANT columns, report error. */
  if (m_table->has_instant_cols()) {
    ib_errf(thd, IB_LOG_LEVEL_ERROR, ER_TABLE_SCHEMA_MISMATCH,
            "The .cfg file indicates no INSTANT column in the source table"
            " whereas the metadata in data dictionary says there are instant"
            " columns in the target table");

    return (DB_ERROR);
  }

  /* All good. Return success. */
  m_table->set_instant_cols(m_table->get_n_user_cols());
  ut_ad(!m_table->has_instant_cols());
  return (DB_SUCCESS);
}

The variable m_n_instant_cols actually represents the number of columns that were added using the “instant ADD COLUMN” feature. However, the current comment is:

  uint16_t m_n_instant_cols; /*!< Number of columns before
                             first instant ADD COLUMN in
                             the meta-data file */

How to repeat:
In all code locations where m_n_instant_cols is used, it indicates the number of columns that were instant added,rather than the number of columns before first instant ADD COLUMN.

This is also clarified by the following error message:

  if (error == DB_SUCCESS && instants != m_n_instant_cols) {
    ib_errf(thd, IB_LOG_LEVEL_ERROR, ER_TABLE_SCHEMA_MISMATCH,
            "Number of instant columns don't match, table has"
            " %lu instant columns record in meta-data file but"
            " there are %lu columns with default value",
            static_cast<ulong>(m_n_instant_cols), static_cast<ulong>(instants));

Suggested fix:
uint16_t	m_n_instant_cols;	/*!< Number of instant columns in
					the meta-data file */
[13 Aug 7:22] MySQL Verification Team
Hello Wuhao Cao,

Thank you for the report and feedback.

regards,
Umesh Shastry