pingcap / pingcap/tidb

Unexpected Result for RIGHT() function in MPP Execution

Open
#60,960 1 comment 0 reactions 0 assignees View on GitHub
component/tiflash fuzz/sqlancer impact/inconsistency may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

```sql
CREATE TABLE t0(c0 CHAR(1));
INSERT t0 VALUES('1');
ALTER TABLE t0 SET TIFLASH REPLICA 1;
SELECT * FROM t0 WHERE RIGHT(c0, -1 | 0); -- 0 row, but 1 rows after several seconds
```
This query should return 0 row if we execute the query immediately after `ALTER` statements. It is expected that `RIGHT(c0, -1 | 0)` should not be true. In this case, it uses TiKV storage:
```bash
mysql> EXPLAIN SELECT * FROM t0 WHERE RIGHT(c0, -1 | 0);
+-------------------------+----------+-----------+---------------+-------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+-------------------------------------------+
| TableReader_7 | 8000.00 | root | | data:Selection_6 |
| └─Selection_6 | 8000.00 | cop[tikv] | | right(dbtest.t0.c0, 18446744073709551615) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t0 | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+-------------------------------------------+
```

However, if we wait until the tables `t0` and `t1` are copied into TIFLASH (5 seconds in my machine) and then execute the query, it returns 1 row.
```bash
mysql> EXPLAIN SELECT * FROM t0 WHERE RIGHT(c0, -1 | 0);
+----------------------------+----------+--------------+---------------+----------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+----------+--------------+---------------+----------------------------------------------------------+
| TableReader_16 | 8000.00 | root | | MppVersion: 3, data:ExchangeSender_15 |
| └─ExchangeSender_15 | 8000.00 | mpp[tiflash] | | ExchangeType: PassThrough |
| └─Selection_14 | 8000.00 | mpp[tiflash] | | right(dbtest.t0.c0, 18446744073709551615) |
| └─TableFullScan_13 | 10000.00 | mpp[tiflash] | table:t0 | pushed down filter:empty, keep order:false, stats:pseudo |
+----------------------------+----------+--------------+---------------+----------------------------------------------------------+
```
The 1 row is unexpected.

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

### 3. What did you see instead (Required)
{1}

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

`tiup playground nightly --host 0.0.0.0 --kv 3 --tiflash 3`
```bash
8.0.11-TiDB-v9.0.0-beta.1.pre-554-gb1a5536a64-dirty
```

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.