pingcap / pingcap/tidb

maybe wrong INSERT behavior when there's not null virtual column on nullable column

Open
#54,854 4 comments 0 reactions 0 assignees View on GitHub
affects-8.5 impact/wrong-result may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 severity/major 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)

``` sql
CREATE TABLE t0(c0 BOOL UNSIGNED , c1 DECIMAL UNSIGNED , c2 BOOL UNSIGNED ZEROFILL AS (c0) VIRTUAL NOT NULL );
CREATE TABLE t1 LIKE t0;
CREATE UNIQUE INDEX i0 ON t1(c2 DESC, c1 DESC, c0);
INSERT INTO t0(c0) VALUES (true);
INSERT IGNORE INTO t1(c1) VALUES (1);
```
``` sql
mysql> select * from t0;
+------+------+----+
| c0 | c1 | c2 |
+------+------+----+
| 1 | NULL | 1 |
+------+------+----+
1 row in set (0.01 sec)
```
``` sql
mysql> select * from t1;
+------+------+----+
| c0 | c1 | c2 |
+------+------+----+
| 0 | 1 | 0 |
+------+------+----+
1 row in set (0.01 sec)
```
### 2. What did you expect to see? (Required)
``` sql
mysql> select * from t1;
+------+------+----+
| c0 | c1 | c2 |
+------+------+----+
| NULL | 1 | 0 |
+------+------+----+
1 row in set (0.00 sec)
```
### 3. What did you see instead (Required)
``` sql
mysql> select * from t1;
+------+------+----+
| c0 | c1 | c2 |
+------+------+----+
| 0 | 1 | 0 |
+------+------+----+
1 row in set (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```
tidb_version()
-----------------------------------------------------------
Release Version: v8.2.0 +
Edition: Community +
Git Commit Hash: 821e491a20fbab36604b36b647b5bae26a2c1418+
Git Branch: HEAD +
UTC Build Time: 2024-07-05 09:16:25 +
GoVersion: go1.21.10 +
Race Enabled: false +
Check Table Before Drop: false +
Store: tikv
```

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.