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.
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.