Bug #102669 incorrect comment in source code
Submitted: 20 Feb 2021 8:40 Modified: 19 May 2021 12:19
Reporter: hao lu (OCA) Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Connection Handling Severity:S4 (Feature request)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: comment

[20 Feb 2021 8:40] hao lu
The flags in class "Field" has a series of macro (in include/mysql_com.h), such as:

  #define NOT_NULL_FLAG 1     /**< Field can't be NULL */
  #define PRI_KEY_FLAG 2      /**< Field is part of a primary key */
  #define UNIQUE_KEY_FLAG 4   /**< Field is part of a unique key */
  #define MULTIPLE_KEY_FLAG 8 /**< Field is part of a key */

However, the comment of macro "UNIQUE_KEY_FLAG" seems incorrect. When setting field's flag in "sql/table.cc:752", this flag is set only when field is the only key part of unique key.

  /* Flag field as unique if it is the only keypart in a unique index */
  if (key_part_n == 0 && key_n != primary_key_n)
        ((keyinfo->flags & HA_NOSAME) && (keyinfo->user_defined_key_parts == 1))
            ? UNIQUE_KEY_FLAG
            : MULTIPLE_KEY_FLAG);

How to repeat:
  `pk0` int NOT NULL,
  `pk1` int NOT NULL,
  `c1` int DEFAULT NULL,
  `c2` int DEFAULT NULL,
  PRIMARY KEY (`pk0`, `pk1`),
  UNIQUE KEY `udx1` (`c1`),
  UNIQUE KEY `udx2` (`c1`,`c2`)

Using gdb to print the flags of field.
[19 May 2021 12:19] MySQL Verification Team
Hi Mr. sephiroth,

Thank you for your bug report.

We agree with your conclusions.

Verified as reported.