Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruq85-007y0U-N2 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2024 08:49:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ruq83-00FG7W-Kh for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2024 08:49:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ruq83-00FG7M-8U for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2024 08:49:55 +0000 Received: from mail-vs1-xe2c.google.com ([2607:f8b0:4864:20::e2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ruq7w-000LY8-Gq for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2024 08:49:54 +0000 Received: by mail-vs1-xe2c.google.com with SMTP id ada2fe7eead31-47a085dbeb9so1437236137.3 for ; Thu, 11 Apr 2024 01:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712825386; x=1713430186; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DQxgfL2i8cLtglxn6ZmuMr/+DcLAgHnPzc78XYn5xaE=; b=aKysH6jWFPt9wl9dtPUTauiWCncCJOGIjrcanhCeCzu9jlNHCBdg8ebBk5Yp25NJgD Shk1PYycP+xlWGi+v7BO74PRF1Lx10PbYiYIGuNg85DRl56PZWMsE0zvoU5vOynC/HDA Q6ZW+2SjuyDhwLapmkdrSDcxHEI3UkzpD7o/mZSvdDnq6vgS/f/WsRlb21nA7lBlApGr Ey6Eb0+/VHspRv+SO4A+YQ4IFt8oUyOdZXOE6nW3FQnKfnPB2ZxOWeUS1mb2gSVc8XWO Qx1io3yoCEfP9x2EJyGVTkVpMJoXVAmUPVrz0JLYVMdK9inu3u8fMAQdQtz4zemCRR0b gp2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712825386; x=1713430186; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DQxgfL2i8cLtglxn6ZmuMr/+DcLAgHnPzc78XYn5xaE=; b=DFMCpR8JdDy5Z/3XjJ5AWdIohjsjoU7is1iw7R5N6fdDXIv6XXzvuh6gbxi3H47WPS bRkdJXE58/2HSJxA5YyptXWIqs41j4kpKVK1dfDYTlCYgOi0rF/Y4qmapHf8XtneRYDK 2alNo2l6Yd8GNc8K6XI7qF85zjuktWqhhM14yNtOJObyJ18TEI0On8fvGf3Ry7AOZnUq +jD80pvJv/Ik6eINKLzKJ4iGqjvw5/8wFX3Q5qrkR5uDYWXCs+/THwA4PLJ/gsBMN8/G kCwyOGF9NCJeDQfmaS3mQqtTo0LIxpBZT/9iH7UHo8E/nzqPNO+rMoEPlabtgZrXpNFW kEXA== X-Forwarded-Encrypted: i=1; AJvYcCXyji0bUNq3Eaw5sJwPPU3/atkglFz6EONSr1Mhfq/M1GuLlqPCnJq6a4A5GSDpJDo06r6NBgsrILkZl8Qce/etxDxCo2sY2n62MKPKwKCbINlX X-Gm-Message-State: AOJu0YxkeWoNKwCXfbzSMc7agW9asyEuFBJig2+R9OVwTOISs5depMXv e0dDrIxH9lKptHJW8PFrlsvsN3ELfOMnqgM6TOoehm+VVX6oT7VBkJ5KluCidNdU3mXQnPD2mjg 9HCr5ZmICZoKlrbIsfRjtoWV67z5KDMd3oKM= X-Google-Smtp-Source: AGHT+IFhfjZBidvu4uuEjF12T6mRA+yaUkGkpw+A5ojKj/mFUaWtE5ngP7j18g3YiDlhzTNH6nK14Xvh3KjFR9AlH6s= X-Received: by 2002:a05:6102:1494:b0:478:8a0f:b47e with SMTP id d20-20020a056102149400b004788a0fb47emr6544207vsv.32.1712825386504; Thu, 11 Apr 2024 01:49:46 -0700 (PDT) MIME-Version: 1.0 References: <202404101358.iet3euazs5zf@alvherre.pgsql> <202404101723.4ag5z2mbgmsl@alvherre.pgsql> In-Reply-To: From: jian he Date: Thu, 11 Apr 2024 16:49:35 +0800 Message-ID: Subject: Re: Can't find not null constraint, but \d+ shows that To: Tender Wang Cc: Alvaro Herrera , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Apr 11, 2024 at 3:19=E2=80=AFPM Tender Wang wr= ote: > >> +DROP TABLE notnull_tbl1; >> +-- make sure attnotnull is reset correctly when a PK is dropped indirec= tly >> +CREATE TABLE notnull_tbl1 (c0 int, c1 int, PRIMARY KEY (c0, c1)); >> +ALTER TABLE notnull_tbl1 DROP c1; >> +\d+ notnull_tbl1 >> + Table "public.notnull_tbl1" >> + Column | Type | Collation | Nullable | Default | Storage | Stats >> target | Description >> +--------+---------+-----------+----------+---------+---------+---------= -----+------------- >> + c0 | integer | | not null | | plain | = | >> + >> >> this is not what we expected? >> "not null" for "c0" now should be false? >> am I missing something? > > Yeah, now this is expected behavior. > Users can drop manually not-null of "c0" if they want, and no error repo= rte. > sorry for the noise. these two past patches confused me: 0001-Correctly-reset-attnotnull-when-constraints-dropped-.patch v4-0001-Fix-pg_attribute-attnotnull-not-reset-when-droppe.patch I thought dropping a column of primary key (ALTER TABLE notnull_tbl2 DROP c= 1) will make the others key columns to not have "not null" property. now I figured out that dropping a column of primary key columns will not change other key columns' "not null" property. dropping the primary key associated constraint will make all key columns "not null" property disappear. v2-0001-Handle-ALTER-.-DROP-NOT-NULL-when-no-pg_constrain.patch behavior looks fine to me now. inline drop_orphaned_notnull in ATExecDropNotNull looks fine to me.