Bug #42832 | INFORMATION_SCHEMA.COLUMNS reports wrong CHARACTER_MAXIMUM_LENGTH for SET | ||
---|---|---|---|
Submitted: | 13 Feb 2009 13:45 | Modified: | 13 Feb 2009 14:02 |
Reporter: | Ulf Wendel | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Information schema | Severity: | S3 (Non-critical) |
Version: | 5.1.30-debug | OS: | Linux (OpenSuse 10.3) |
Assigned to: | CPU Architecture: | Any |
[13 Feb 2009 13:45]
Ulf Wendel
[13 Feb 2009 13:49]
Ulf Wendel
Metadata and I_S seem to differ. +-------+--------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+--------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `col1` set('yes','no') DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=ucs2 | +-------+--------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT col1, length(col1), char_length(col1) FROM test.test; Field 1: `col1` Catalog: `def` Database: `test` Table: `test` Org_table: `test` Type: STRING Collation: latin1_swedish_ci (8) Length: 6 Max_length: 3 Decimals: 0 Flags: SET Field 2: `length(col1)` Catalog: `def` Database: `` Table: `` Org_table: `` Type: LONGLONG Collation: binary (63) Length: 10 Max_length: 1 Decimals: 0 Flags: BINARY NUM Field 3: `char_length(col1)` Catalog: `def` Database: `` Table: `` Org_table: `` Type: LONGLONG Collation: binary (63) Length: 10 Max_length: 1 Decimals: 0 Flags: BINARY NUM +------+--------------+-------------------+ | col1 | length(col1) | char_length(col1) | +------+--------------+-------------------+ | yes | 6 | 3 | | no | 4 | 2 | | NULL | NULL | NULL | +------+--------------+-------------------+ 3 rows in set (0.00 sec)
[13 Feb 2009 14:01]
Andrey Hristov
It is very strange. I use the command line to dump the metadata sent from the server. For simplicity character_set_results is latin1. I try different enums: enum('yes', 'no') enum('yes, 'no', 'maybe') enum('yes', 'no, 'probably') It seems that the length is the combined of all strings inclusive a space (probably a \0) in between. Seems like the length of the definition, not what is the maximal length of a field. Enum has one choice, would have it been a SET, maybe then this would have been correct. +--------------+ | VERSION() | +--------------+ | 5.1.31-debug | +--------------+ 1 row in set (0.00 sec) DROP TABLE IF EXISTS test.test; CREATE TABLE test.test(col1 SET('yes', 'no')) CHARSET latin1; INSERT INTO test.test(col1) VALUES ('yes'), ('no'), (NULL); SELECT col1, length(col1), char_length(col1) FROM test.test; Records: 3 Duplicates: 0 Warnings: 0 Field 1: `col1` Catalog: `def` Database: `test` Table: `test` Org_table: `test` Type: STRING Collation: latin1_swedish_ci (8) Length: 6 Max_length: 3 Decimals: 0 Flags: SET ... +------+--------------+-------------------+ | col1 | length(col1) | char_length(col1) | +------+--------------+-------------------+ | yes | 3 | 3 | | no | 2 | 2 | | NULL | NULL | NULL | +------+--------------+-------------------+ 3 rows in set (0.00 sec) ----------------------------------------------------------- DROP TABLE IF EXISTS test.test; CREATE TABLE test.test(col1 SET('yes', 'no', 'maybe')) CHARSET latin1; INSERT INTO test.test(col1) VALUES ('yes'), ('no'), (NULL); SELECT col1, length(col1), char_length(col1) FROM test.test; Field 1: `col1` Catalog: `def` Database: `test` Table: `test` Org_table: `test` Type: STRING Collation: latin1_swedish_ci (8) Length: 12 Max_length: 3 Decimals: 0 Flags: SET .... +------+--------------+-------------------+ | col1 | length(col1) | char_length(col1) | +------+--------------+-------------------+ | yes | 3 | 3 | | no | 2 | 2 | | NULL | NULL | NULL | +------+--------------+-------------------+ -------------------------------------------- DROP TABLE IF EXISTS test.test; CREATE TABLE test.test(col1 SET('yes', 'no', 'maybe', 'prolly')) CHARSET latin1; INSERT INTO test.test(col1) VALUES ('yes'), ('no'), (NULL); SELECT col1, length(col1), char_length(col1) FROM test.test; Field 1: `col1` Catalog: `def` Database: `test` Table: `test` Org_table: `test` Type: STRING Collation: latin1_swedish_ci (8) Length: 19 Max_length: 3 Decimals: 0 Flags: SET .... +------+--------------+-------------------+ | col1 | length(col1) | char_length(col1) | +------+--------------+-------------------+ | yes | 3 | 3 | | no | 2 | 2 | | NULL | NULL | NULL | +------+--------------+-------------------+ This affects the I_S.COLUMNS which gives wrong data, like *************************** 1. row *************************** TABLE_SCHEMA: test TABLE_NAME: test COLUMN_NAME: col1 CHARACTER_MAXIMUM_LENGTH: 19 CHARACTER_OCTET_LENGTH: 19 1 row in set (0.01 sec) For the last defition ('yes','no','maybe','prolly')
[13 Feb 2009 14:02]
Andrey Hristov
Not a bug, this is a SET, not an ENUM, values are concatenated