Hi Jian, On Tue, Sep 15, 2026 at 12:21 PM jian he <[email protected]> wrote:
> On Mon, Sep 14, 2026 at 5:21 AM Bryan Green <[email protected]> > wrote: > > > > On 8/3/2026 1:00 AM, Chao Li wrote: > > > > > >> On Aug 2, 2026, at 19:52, jian he <[email protected]> > wrote: > > >> > > > With that list added, the rest of the approach looks correct to me. > > > > Thanks. > I did not notice the newly added AlteredTableInfo->changedStatisticsOwners. > I have added some tests to stats_ext.sql > > > Hi jian, I tested v7 and found a case that it gets wrong. The command no longer fails with "cache lookup failed", but it now succeeds and leaves a foreign key violated! CREATE TABLE pk (x varchar(10), y int, PRIMARY KEY (x, y)); INSERT INTO pk VALUES ('a', 1); CREATE TABLE fk (f varchar(10), a int, e int GENERATED ALWAYS AS (a) STORED, FOREIGN KEY (f, e) REFERENCES pk); INSERT INTO fk (f, a) VALUES ('a', 1); ALTER TABLE fk ALTER COLUMN f TYPE varchar(20), ALTER COLUMN e SET EXPRESSION AS (a + 100); SELECT * FROM fk; -- ('a', 101): no matching row in pk On HEAD the ALTER fails with "cache lookup failed for constraint". With v7 it succeeds, and the FK stays marked as valid. Note that running the two changes as separate ALTER TABLE commands correctly fails with "insert or update on table "fk" violates foreign key constraint". Here is what happens. The first ATPostAlterTypeCleanup() call, after the ALTER TYPE pass, re-adds the FK using tab->rewrite as it stands at that moment. Because varchar(10) -> varchar(20) needs no rewrite, TryReuseForeignKey() lets the FK skip validation. The stored SET EXPRESSION runs afterwards: it sets tab->rewrite and changes e's values, but the FK is never checked again. The same thing happens on the referenced side, when the altered table's primary key includes the generated column and another table references it, and with a partitioned referencing table. Regards, Nikhil --- Nikhil Sontakke PlanetScale
