On Mon, Feb 5, 2024 at 5:51 PM Alvaro Herrera <alvhe...@alvh.no-ip.org> wrote: > > On 2024-Feb-05, Alvaro Herrera wrote: > > > Hmm, let me have a look, I can probably get this one fixed today before > > embarking on a larger fix elsewhere in the same feature. > > You know what -- this missing CCI has a much more visible impact, which > is that the attnotnull marker that a primary key imposes on a partition > is propagated early. So this regression test no longer fails: > > create table cnn2_parted(a int primary key) partition by list (a); > create table cnn2_part1(a int); > alter table cnn2_parted attach partition cnn2_part1 for values in (1); > > Here, in the existing code the ALTER TABLE ATTACH fails with the error > message that > ERROR: primary key column "a" is not marked NOT NULL > but with the patch, this no longer occurs. > > I'm not sure that this behavior change is desirable ... I have vague > memories of people complaining that this sort of error was not very > welcome ... but on the other hand it seems now pretty clear that if it > *is* desirable, then its implementation is no good, because a single > added CCI breaks it. > > I'm leaning towards accepting the behavior change, but I'd like to > investigate a little bit more first, but what do others think? >
if you place CommandCounterIncrement inside the `if (recurse)` branch, then the regression test will be ok. diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9f516967..25e225c2 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7719,6 +7719,9 @@ set_attnotnull(List **wqueue, Relation rel, AttrNumber attnum, bool recurse, false)); retval |= set_attnotnull(wqueue, childrel, childattno, recurse, lockmode); + + CommandCounterIncrement();