pingcap / pingcap/tidb

The expression index cannot be chosen because of different collations

Open
#56,560 4 comments 0 reactions 1 assignee Claimed by @YangKeao View on GitHub
affects-8.5 severity/moderate sig/sql-infra 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)

```
create table `t` (data json DEFAULT NULL, KEY idx((cast(json_extract(data, '$.test') as char(64)))));

explain select /*+ USE_INDEX(t, idx) */ * from t where cast(json_extract(data, '$.test') as char(64)) = 'a';
```

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

```
+---------------------------------+---------+-----------+--------------------------------------------------------------------------------------------------+-------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------------------+---------+-----------+--------------------------------------------------------------------------------------------------+-------------------------------------------------+
| Projection_4 | 10.00 | root | | test.t.data |
| └─IndexLookUp_8 | 10.00 | root | | |
| ├─IndexRangeScan_6(Build) | 10.00 | cop[tikv] | table:t, index:idx(cast(json_extract(`data`, _utf8mb4'$.test') as char(64))) | range:["a","a"], keep order:false, stats:pseudo |
| └─TableRowIDScan_7(Probe) | 10.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+---------------------------------+---------+-----------+--------------------------------------------------------------------------------------------------+-------------------------------------------------+
```

### 3. What did you see instead (Required)

```
+------------------------------+----------+-----------+------------------------------------------------------------------------------+--------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------+----------+-----------+------------------------------------------------------------------------------+--------------------------------------------------------------------+
| IndexLookUp_8 | 8000.00 | root | | |
| ├─IndexFullScan_5(Build) | 10000.00 | cop[tikv] | table:t, index:idx(cast(json_extract(`data`, _utf8mb4'$.test') as char(64))) | keep order:false, stats:pseudo |
| └─Selection_7(Probe) | 8000.00 | cop[tikv] | | eq(cast(json_extract(test.t.data, "$.test"), var_string(64)), "a") |
| └─TableRowIDScan_6 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+------------------------------+----------+-----------+------------------------------------------------------------------------------+--------------------------------------------------------------------+
```

### 4. What is your TiDB version? (Required)

```
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.3.0
Edition: Community
Git Commit Hash: 1a0c3ac3292fff7742faa0c00a662ccb66ba40db
Git Branch: HEAD
UTC Build Time: 2024-08-20 10:13:01
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

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.