Skip to content

Nested cast() clause outputs zero length #34901

@Willendless

Description

@Willendless

Bug Report

1. Minimal reproduce step (Required)

First open a mysql client with option --column-type-info, such as mysql --comments --column-type-info --host 127.0.0.1 --port 3306 -u root -p.

Then by executing a statement with nested CAST(), such as select cast(cast(1 as binary) as binary);, it can be found that the length field is wrong.

2. What did you expect to see? (Required)

mysql> select cast(cast(1 as binary) as binary);
Field   1:  `cast(cast(1 as binary) as binary)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     2
Max_length: 1
Decimals:   31
Flags:      BINARY


+----------------------------------------------------------------------+
| cast(cast(1 as binary) as binary)                                    |
+----------------------------------------------------------------------+
| 0x31                                                                 |
+----------------------------------------------------------------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> select cast(cast(1 as binary) as binary);
Field   1:  `cast(cast(1 as binary) as binary)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     0
Max_length: 1
Decimals:   31
Flags:      NOT_NULL BINARY


+----------------------------------------------------------------------+
| cast(cast(1 as binary) as binary)                                    |
+----------------------------------------------------------------------+
| 0x31                                                                 |
+----------------------------------------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

| Release Version: v6.1.0-alpha-490-g9d0d45981
Edition: Community
Git Commit Hash: 9d0d459816705e60205d074f3183c8773086e2b0
Git Branch: master
UTC Build Time: 2022-05-23 14:59:53
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions