pingcap / pingcap/tidb

`cast(constant)` does not do constant folding

Open
#48,364 3 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
severity/moderate sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
```
use test;
drop table if exists test.t;
create table test.t(a json);
explain select JSON_ARRAY(a, '{\"a\" : \"b\", \"aa\" : \"bb\"}') from t;
explain select JSON_ARRAY(null, a) from t;
```

### 2. What did you expect to see? (Required)
There is no cast function in the output.

### 3. What did you see instead (Required)
```
mysql> explain select JSON_ARRAY(a, '{\"a\" : \"b\", \"aa\" : \"bb\"}') from t;
+-------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------+
| Projection_3 | 10000.00 | root | | json_array(test.t.a, cast({"a" : "b", "aa" : "bb"}, json BINARY))->Column#3 |
| └─TableReader_5 | 10000.00 | root | | data:TableFullScan_4 |
| └─TableFullScan_4 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------+

mysql> explain select JSON_ARRAY(null, a) from t;
+-------------------------+----------+-----------+---------------+---------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+---------------------------------------+
| Projection_3 | 10000.00 | root | | json_array(, test.t.a)->Column#3 |
| └─TableReader_5 | 10000.00 | root | | data:TableFullScan_4 |
| └─TableFullScan_4 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+---------------------------------------+
```

### 4. What is your TiDB version? (Required)
Git Commit Hash: 93bd0fc8dacb5b2e72703e1433f298ac6a6186c4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.