pingcap / pingcap/tidb

ANALYZE TABLE fails after adding a virtual generated column on existing rows

Open
#68,080 2 comments 0 reactions 0 assignees 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

### Summary

A successful `ALTER TABLE ... ADD COLUMN ... VIRTUAL` can leave the table in a state where later `ANALYZE TABLE` fails on existing rows instead of handling the problematic generated column gracefully.

### Minimal Reproduction

```sql
use test;

drop table if exists repro_analyze_gc_overflow;
create table repro_analyze_gc_overflow (
a bigint unsigned not null
);

insert into repro_analyze_gc_overflow values
(18446744073709551615);

alter table repro_analyze_gc_overflow
add column b bigint unsigned generated always as (a + 1) virtual;

analyze table repro_analyze_gc_overflow;
```

### Actual Behavior

`ANALYZE TABLE` fails:

```text
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(test.repro_analyze_gc_overflow.a + 1)'
```

### Expected Behavior

`ANALYZE TABLE` should not fail the whole stats collection for this table after a successful DDL.

### Version

Observed on current nightly / master-based TiDB build.

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.