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:
None 
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
Description:
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)
    field->set_flag(
        ((keyinfo->flags & HA_NOSAME) && (keyinfo->user_defined_key_parts == 1))
            ? UNIQUE_KEY_FLAG
            : MULTIPLE_KEY_FLAG);

How to repeat:
CREATE TABLE `t1` (
  `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`)
) ENGINE=InnoDB;

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.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.