Bug #108715 Mysql_field returns NUM_FLAG (32768) for grouped by columns
Submitted: 8 Oct 2022 20:11 Modified: 14 Nov 2024 17:36
Reporter: Kamil Tekiela Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Information schema Severity:S3 (Non-critical)
Version:5.7, 8.0 OS:Any
Assigned to: CPU Architecture:Any

[8 Oct 2022 20:11] Kamil Tekiela
Description:
Use mysql.exe with --column-type-info.

When a VARCHAR column is grouped in a SELECT statement, the metadata flag field contains value 32768 which means that the column is numeric. But a VARCHAR field is not numeric. 

This does not conform to the specification in the IS_NUM macro. 

How to repeat:
CREATE TABLE `test` (
    `id` int(11) NOT NULL,
    `col` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT INTO `test` (`id`, `col`) VALUES
(1, 'test1'),
(2, 'test2'),
(3, '1'),
(4, '\'\''),
(5, '\"\"'),
(6, '\'test\''),
(7, '\"test\"'),
(8, '\"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\"'),
(9, '\"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\", \"test\"');

-- This will show NUM for flags field
SELECT col FROM test GROUP BY col;
[10 Oct 2022 7:26] MySQL Verification Team
Hello Kamil,

Thank you for the report and feedback.

regards,
Umesh
[17 Oct 2022 4:19] huahua xu
Both `NUM` and `GROUP` flag values are 32768,which are defined in `mysql_com.h`

/* The following are only sent to new clients */
#define ENUM_FLAG	256		/* field is an enum */
#define AUTO_INCREMENT_FLAG 512		/* field is a autoincrement field */
#define TIMESTAMP_FLAG	1024		/* Field is a timestamp */
#define SET_FLAG	2048		/* field is a set */
#define NO_DEFAULT_VALUE_FLAG 4096	/* Field doesn't have default value */
#define ON_UPDATE_NOW_FLAG 8192         /* Field is set to NOW on UPDATE */
#define NUM_FLAG	32768		/* Field is num (for clients) */
#define PART_KEY_FLAG	16384		/* Intern; Part of some key */
#define GROUP_FLAG	32768		/* Intern: Group field */
#define UNIQUE_FLAG	65536		/* Intern: Used by sql_yacc */
#define BINCMP_FLAG	131072		/* Intern: Used by sql_yacc */
#define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
#define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
[14 Nov 2024 17:36] Jon Stephens
Fixed in MySQL 9.2.0 by BUG#115597.

Closed.