dolthub / dolthub/doltgresql

ALTER COLUMN ... SET NOT NULL fails on text columns with a secondary index

Open
#3,217 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.1k
Forks
73
Avg merge
1d 10h
Merged PRs (30d)
129

Description

`ALTER TABLE ... ALTER COLUMN ... SET NOT NULL` fails on a text column that has a secondary index, with a MySQL-dialect error:

```sql
CREATE TABLE t1 (pk integer PRIMARY KEY, value text);
CREATE INDEX t1_value_idx ON t1 (value);
INSERT INTO t1 VALUES (1, 'one');

ALTER TABLE t1 ALTER COLUMN value SET NOT NULL;
ERROR: blob/text column 'value' used in key specification without a key length
```

The statement works when the column has no secondary index. The error comes from GMS's `ValidateModifyColumn`, which applies MySQL's key-prefix-length rule to text/blob columns on any column modification; Postgres text columns are indexable without a key length, so the rule shouldn't apply to Doltgres.

Contributor guide

Open the contributing guide

Research direction

Reproduce the SQL example, then locate GMS's ValidateModifyColumn and inspect how it applies the MySQL key-prefix-length rule to text columns. Verify the change with a regression case covering a secondary-indexed text column, and confirm ALTER COLUMN ... SET NOT NULL succeeds without the key-length error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.