diff --git a/executor/show.go b/executor/show.go index 9f40d2abc5efb..c82dd616a3076 100644 --- a/executor/show.go +++ b/executor/show.go @@ -306,13 +306,6 @@ func (e *ShowExec) fetchShowColumns() error { columnDefault = defaultValStr } } - // issue #9807 - // Some types in show full columns should print other collations. - switch col.Tp { - case mysql.TypeTimestamp, mysql.TypeDate, mysql.TypeDuration, mysql.TypeDatetime, - mysql.TypeYear, mysql.TypeNewDate: - desc.Collation = "NULL" - } // The FULL keyword causes the output to include the column collation and comments, // as well as the privileges you have for each column. diff --git a/executor/show_test.go b/executor/show_test.go index 6a6844939fe50..73ad89a307c4e 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -213,7 +213,7 @@ func (s *testSuite) TestShow(c *C) { tk.MustExec(`drop table if exists show_test_comment`) tk.MustExec(`create table show_test_comment (id int not null default 0 comment "show_test_comment_id")`) tk.MustQuery(`show full columns from show_test_comment`).Check(testutil.RowsWithSep("|", - "id|int(11)|binary|NO||0||select,insert,update,references|show_test_comment_id", + "id|int(11)||NO||0||select,insert,update,references|show_test_comment_id", )) // Test show create table with AUTO_INCREMENT option @@ -575,18 +575,66 @@ func (s *testSuite) TestShow2(c *C) { // TODO: In MySQL, the result is "autocommit ON". tk2.MustQuery("show global variables where variable_name = 'autocommit'").Check(testkit.Rows("autocommit 1")) + // TODO: Specifying the charset for national char/varchar should not be supported. tk.MustExec("drop table if exists test_full_column") - tk.MustExec(`create table test_full_column( a date , b datetime , c year(4), d timestamp,e time ,f year, h datetime(2) );`) + tk.MustExec(`create table test_full_column( + c_int int, + c_float float, + c_bit bit, + c_bool bool, + c_char char(1) charset ascii collate ascii_bin, + c_nchar national char(1) charset ascii collate ascii_bin, + c_binary binary, + c_varchar varchar(1) charset ascii collate ascii_bin, + c_nvarchar national varchar(1) charset ascii collate ascii_bin, + c_varbinary varbinary(1), + c_year year, + c_date date, + c_time time, + c_datetime datetime, + c_timestamp timestamp, + c_blob blob, + c_tinyblob tinyblob, + c_mediumblob mediumblob, + c_longblob longblob, + c_text text charset ascii collate ascii_bin, + c_tinytext tinytext charset ascii collate ascii_bin, + c_mediumtext mediumtext charset ascii collate ascii_bin, + c_longtext longtext charset ascii collate ascii_bin, + c_json json, + c_enum enum('1') charset ascii collate ascii_bin, + c_set set('1') charset ascii collate ascii_bin + );`) tk.MustQuery(`show full columns from test_full_column`).Check(testkit.Rows( "" + - "a date NULL YES select,insert,update,references ]\n" + - "[b datetime NULL YES select,insert,update,references ]\n" + - "[c year NULL YES select,insert,update,references ]\n" + - "[d timestamp NULL YES select,insert,update,references ]\n" + - "[e time NULL YES select,insert,update,references ]\n" + - "[f year NULL YES select,insert,update,references ]\n" + - "[h datetime(2) NULL YES select,insert,update,references ")) + "c_int int(11) YES select,insert,update,references ]\n" + + "[c_float float YES select,insert,update,references ]\n" + + "[c_bit bit(1) YES select,insert,update,references ]\n" + + "[c_bool tinyint(1) YES select,insert,update,references ]\n" + + "[c_char char(1) ascii_bin YES select,insert,update,references ]\n" + + "[c_nchar char(1) ascii_bin YES select,insert,update,references ]\n" + + "[c_binary binary(1) YES select,insert,update,references ]\n" + + "[c_varchar varchar(1) ascii_bin YES select,insert,update,references ]\n" + + "[c_nvarchar varchar(1) ascii_bin YES select,insert,update,references ]\n" + + "[c_varbinary varbinary(1) YES select,insert,update,references ]\n" + + "[c_year year YES select,insert,update,references ]\n" + + "[c_date date YES select,insert,update,references ]\n" + + "[c_time time YES select,insert,update,references ]\n" + + "[c_datetime datetime YES select,insert,update,references ]\n" + + "[c_timestamp timestamp YES select,insert,update,references ]\n" + + "[c_blob blob YES select,insert,update,references ]\n" + + "[c_tinyblob tinyblob YES select,insert,update,references ]\n" + + "[c_mediumblob mediumblob YES select,insert,update,references ]\n" + + "[c_longblob longblob YES select,insert,update,references ]\n" + + "[c_text text ascii_bin YES select,insert,update,references ]\n" + + "[c_tinytext tinytext ascii_bin YES select,insert,update,references ]\n" + + "[c_mediumtext mediumtext ascii_bin YES select,insert,update,references ]\n" + + "[c_longtext longtext ascii_bin YES select,insert,update,references ]\n" + + "[c_json json YES select,insert,update,references ]\n" + + "[c_enum enum('1') ascii_bin YES select,insert,update,references ]\n" + + "[c_set set('1') ascii_bin YES select,insert,update,references ")) + tk.MustExec("drop table if exists test_full_column") tk.MustExec("drop table if exists t") diff --git a/go.mod b/go.mod index 7a0cdd00e5394..e307eeb4fde4f 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/pingcap/tidb require ( github.com/BurntSushi/toml v0.3.1 - github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect - github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 // indirect github.com/beorn7/perks v0.0.0-20160229213445-3ac7bf7a47d1 // indirect github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d @@ -51,13 +49,13 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030 github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11 github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 - github.com/pingcap/parser v0.0.0-20190328044348-9945885931bb + github.com/pingcap/parser v0.0.0-20190410113155-72aa33252485 github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93 github.com/prometheus/client_golang v0.8.0 github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 - github.com/prometheus/common v0.0.0-20180426121432-d811d2e9bf89 + github.com/prometheus/common v0.0.0-20180426121432-d811d2e9bf89 // indirect github.com/prometheus/procfs v0.0.0-20180408092902-8b1c2da0d56d // indirect github.com/sirupsen/logrus v0.0.0-20170323161349-3bcb09397d6d github.com/spaolacci/murmur3 v0.0.0-20150829172844-0d12bf811670 @@ -77,7 +75,6 @@ require ( golang.org/x/tools v0.0.0-20181105230042-78dc5bac0cac google.golang.org/genproto v0.0.0-20180427144745-86e600f69ee4 // indirect google.golang.org/grpc v1.12.0 - gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect gopkg.in/fsnotify.v1 v1.4.7 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index 263937b4c3537..fbdeb625f333d 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 h1:CZI8h5fmYwCCvd2RMSsjLqHN6OqABlWJweFKxz4vdEs= github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/beorn7/perks v0.0.0-20160229213445-3ac7bf7a47d1 h1:OnJHjoVbY69GG4gclp0ngXfywigLhR6rrgUxmxQRWO4= @@ -100,8 +96,8 @@ github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11 h1:iGNfAHgK0VHJobW github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v0.0.0-20190328044348-9945885931bb h1:JCc0MMW4fqfhbaI8LS1dXRmql1PbpoKLxoYq6GUlSaQ= -github.com/pingcap/parser v0.0.0-20190328044348-9945885931bb/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190410113155-72aa33252485 h1:tmK/bExJ3Mcnh3Lo07naQZjd7ADX9eo6kjM02z5h6OM= +github.com/pingcap/parser v0.0.0-20190410113155-72aa33252485/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE= github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible h1:e9Gi/LP9181HT3gBfSOeSBA+5JfemuE4aEAhqNgoE4k= @@ -111,8 +107,6 @@ github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93/go.mod h1:RtkHW8WbcNx github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -165,8 +159,6 @@ google.golang.org/genproto v0.0.0-20180427144745-86e600f69ee4 h1:0rk3/gV3HbvCeUz google.golang.org/genproto v0.0.0-20180427144745-86e600f69ee4/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.12.0 h1:Mm8atZtkT+P6R43n/dqNDWkPPu5BwRVu/1rJnJCeZH8= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/infoschema/tables.go b/infoschema/tables.go index cd6f7c1eeb89b..b2742d998ff71 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1082,8 +1082,8 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types numericPrecision, // NUMERIC_PRECISION numericScale, // NUMERIC_SCALE datetimePrecision, // DATETIME_PRECISION - col.Charset, // CHARACTER_SET_NAME - col.Collate, // COLLATION_NAME + columnDesc.Charset, // CHARACTER_SET_NAME + columnDesc.Collation, // COLLATION_NAME columnType, // COLUMN_TYPE columnDesc.Key, // COLUMN_KEY columnDesc.Extra, // EXTRA @@ -1091,12 +1091,6 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types columnDesc.Comment, // COLUMN_COMMENT col.GeneratedExprString, // GENERATION_EXPRESSION ) - // In mysql, 'character_set_name' and 'collation_name' are setted to null when column type is non-varchar or non-blob in information_schema. - if col.Tp != mysql.TypeVarchar && col.Tp != mysql.TypeBlob { - record[13].SetNull() - record[14].SetNull() - } - rows = append(rows, record) } return rows diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index f510e74032d63..de73b11d116d5 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -137,7 +137,6 @@ func (s *testSuite) TestDataForTableStatsField(c *C) { } func (s *testSuite) TestCharacterSetCollations(c *C) { - testleak.BeforeTest() defer testleak.AfterTest(c)() store, err := mockstore.NewMockTikvStore() @@ -159,10 +158,76 @@ func (s *testSuite) TestCharacterSetCollations(c *C) { tk.MustQuery("SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name").Check( testkit.Rows("armscii8 64 1", "armscii8 32 1", "ascii 65 1", "ascii 11 1", "big5 84 1", "big5 1 1", "binary 63 1", "cp1250 66 1", "cp1250 44 1", "cp1250 34 1", "cp1250 26 1", "cp1250 99 1", "cp1251 50 1", "cp1251 14 1", "cp1251 51 1", "cp1251 52 1", "cp1251 23 1", "cp1256 67 1", "cp1256 57 1", "cp1257 58 1", "cp1257 59 1", "cp1257 29 1", "cp850 80 1", "cp850 4 1", "cp852 81 1", "cp852 40 1", "cp866 68 1", "cp866 36 1", "cp932 96 1", "cp932 95 1", "dec8 69 1", "dec8 3 1", "eucjpms 98 1", "eucjpms 97 1", "euckr 85 1", "euckr 19 1", "gb2312 86 1", "gb2312 24 1", "gbk 87 1", "gbk 28 1", "geostd8 93 1", "geostd8 92 1", "greek 70 1", "greek 25 1", "hebrew 71 1", "hebrew 16 1", "hp8 72 1", "hp8 6 1", "keybcs2 73 1", "keybcs2 37 1", "koi8r 74 1", "koi8r 7 1", "koi8u 75 1", "koi8u 22 1", "latin1 47 1", "latin1 15 1", "latin1 48 1", "latin1 49 1", "latin1 5 1", "latin1 31 1", "latin1 94 1", "latin1 8 1", "latin2 77 1", "latin2 27 1", "latin2 2 1", "latin2 9 1", "latin2 21 1", "latin5 78 1", "latin5 30 1", "latin7 79 1", "latin7 20 1", "latin7 41 1", "latin7 42 1", "macce 43 1", "macce 38 1", "macroman 53 1", "macroman 39 1", "sjis 88 1", "sjis 13 1", "swe7 82 1", "swe7 10 1", "tis620 89 1", "tis620 18 1", "ucs2 90 1", "ucs2 149 1", "ucs2 138 1", "ucs2 139 1", "ucs2 145 1", "ucs2 134 1", "ucs2 35 1", "ucs2 159 1", "ucs2 148 1", "ucs2 146 1", "ucs2 129 1", "ucs2 130 1", "ucs2 140 1", "ucs2 144 1", "ucs2 133 1", "ucs2 143 1", "ucs2 131 1", "ucs2 147 1", "ucs2 141 1", "ucs2 132 1", "ucs2 142 1", "ucs2 135 1", "ucs2 136 1", "ucs2 137 1", "ucs2 150 1", "ucs2 128 1", "ucs2 151 1", "ujis 91 1", "ujis 12 1", "utf16 55 1", "utf16 122 1", "utf16 111 1", "utf16 112 1", "utf16 118 1", "utf16 107 1", "utf16 54 1", "utf16 121 1", "utf16 119 1", "utf16 102 1", "utf16 103 1", "utf16 113 1", "utf16 117 1", "utf16 106 1", "utf16 116 1", "utf16 104 1", "utf16 120 1", "utf16 114 1", "utf16 105 1", "utf16 115 1", "utf16 108 1", "utf16 109 1", "utf16 110 1", "utf16 123 1", "utf16 101 1", "utf16 124 1", "utf16le 62 1", "utf16le 56 1", "utf32 61 1", "utf32 181 1", "utf32 170 1", "utf32 171 1", "utf32 177 1", "utf32 166 1", "utf32 60 1", "utf32 180 1", "utf32 178 1", "utf32 161 1", "utf32 162 1", "utf32 172 1", "utf32 176 1", "utf32 165 1", "utf32 175 1", "utf32 163 1", "utf32 179 1", "utf32 173 1", "utf32 164 1", "utf32 174 1", "utf32 167 1", "utf32 168 1", "utf32 169 1", "utf32 182 1", "utf32 160 1", "utf32 183 1", "utf8 83 1", "utf8 213 1", "utf8 202 1", "utf8 203 1", "utf8 209 1", "utf8 198 1", "utf8 33 1", "utf8 223 1", "utf8 212 1", "utf8 210 1", "utf8 193 1", "utf8 194 1", "utf8 204 1", "utf8 208 1", "utf8 197 1", "utf8 207 1", "utf8 195 1", "utf8 211 1", "utf8 205 1", "utf8 196 1", "utf8 206 1", "utf8 199 1", "utf8 200 1", "utf8 201 1", "utf8 214 1", "utf8 192 1", "utf8 215 1", "utf8mb4 46 1", "utf8mb4 245 1", "utf8mb4 234 1", "utf8mb4 235 1", "utf8mb4 241 1", "utf8mb4 230 1", "utf8mb4 45 1", "utf8mb4 244 1", "utf8mb4 242 1", "utf8mb4 225 1", "utf8mb4 226 1", "utf8mb4 236 1", "utf8mb4 240 1", "utf8mb4 229 1", "utf8mb4 239 1", "utf8mb4 227 1", "utf8mb4 243 1", "utf8mb4 237 1", "utf8mb4 228 1", "utf8mb4 238 1", "utf8mb4 231 1", "utf8mb4 232 1", "utf8mb4 233 1", "utf8mb4 246 1", "utf8mb4 224 1", "utf8mb4 247 1")) + // Test charset/collation in information_schema.COLUMNS table. + tk.MustExec("DROP DATABASE IF EXISTS charset_collate_test") + tk.MustExec("CREATE DATABASE charset_collate_test; USE charset_collate_test") + + // TODO: Specifying the charset for national char/varchar should not be supported. + tk.MustExec(`CREATE TABLE charset_collate_col_test( + c_int int, + c_float float, + c_bit bit, + c_bool bool, + c_char char(1) charset ascii collate ascii_bin, + c_nchar national char(1) charset ascii collate ascii_bin, + c_binary binary, + c_varchar varchar(1) charset ascii collate ascii_bin, + c_nvarchar national varchar(1) charset ascii collate ascii_bin, + c_varbinary varbinary(1), + c_year year, + c_date date, + c_time time, + c_datetime datetime, + c_timestamp timestamp, + c_blob blob, + c_tinyblob tinyblob, + c_mediumblob mediumblob, + c_longblob longblob, + c_text text charset ascii collate ascii_bin, + c_tinytext tinytext charset ascii collate ascii_bin, + c_mediumtext mediumtext charset ascii collate ascii_bin, + c_longtext longtext charset ascii collate ascii_bin, + c_json json, + c_enum enum('1') charset ascii collate ascii_bin, + c_set set('1') charset ascii collate ascii_bin + )`) + + tk.MustQuery(`SELECT column_name, character_set_name, collation_name + FROM information_schema.COLUMNS + WHERE table_schema = "charset_collate_test" AND table_name = "charset_collate_col_test" + ORDER BY column_name`, + ).Check(testkit.Rows( + "c_binary ", + "c_bit ", + "c_blob ", + "c_bool ", + "c_char ascii ascii_bin", + "c_date ", + "c_datetime ", + "c_enum ascii ascii_bin", + "c_float ", + "c_int ", + "c_json ", + "c_longblob ", + "c_longtext ascii ascii_bin", + "c_mediumblob ", + "c_mediumtext ascii ascii_bin", + "c_nchar ascii ascii_bin", + "c_nvarchar ascii ascii_bin", + "c_set ascii ascii_bin", + "c_text ascii ascii_bin", + "c_time ", + "c_timestamp ", + "c_tinyblob ", + "c_tinytext ascii ascii_bin", + "c_varbinary ", + "c_varchar ascii ascii_bin", + "c_year ", + )) + tk.MustExec("DROP DATABASE charset_collate_test") } func (s *testSuite) TestSchemataCharacterSet(c *C) { - testleak.BeforeTest() defer testleak.AfterTest(c)() store, err := mockstore.NewMockTikvStore() diff --git a/table/column.go b/table/column.go index 319ebb1f0d887..595429b19fb2b 100644 --- a/table/column.go +++ b/table/column.go @@ -28,6 +28,7 @@ import ( "github.com/pingcap/parser/charset" "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" + field_types "github.com/pingcap/parser/types" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" @@ -205,9 +206,12 @@ func CastValue(ctx sessionctx.Context, val types.Datum, col *model.ColumnInfo) ( // ColDesc describes column information like MySQL desc and show columns do. type ColDesc struct { - Field string - Type string - Collation string + Field string + Type string + // Charset is nil if the column doesn't have a charset, or a string indicating the charset name. + Charset interface{} + // Collation is nil if the column doesn't have a collation, or a string indicating the collation name. + Collation interface{} Null string Key string DefaultValue interface{} @@ -267,9 +271,10 @@ func NewColDesc(col *Column) *ColDesc { } } - return &ColDesc{ + desc := &ColDesc{ Field: name.O, Type: col.GetTypeDesc(), + Charset: col.Charset, Collation: col.Collate, Null: nullFlag, Key: keyFlag, @@ -278,6 +283,11 @@ func NewColDesc(col *Column) *ColDesc { Privileges: defaultPrivileges, Comment: col.Comment, } + if !field_types.HasCharset(&col.ColumnInfo.FieldType) { + desc.Charset = nil + desc.Collation = nil + } + return desc } // ColDescFieldNames returns the fields name in result set for desc and show columns.