Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pkUE5-0005w6-MX for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Apr 2023 18:20:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pkUE4-00039Z-9y for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Apr 2023 18:20:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pkUE3-00039N-RM for pgsql-hackers@lists.postgresql.org; Thu, 06 Apr 2023 18:20:48 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pkUE0-0003O6-MC for pgsql-hackers@lists.postgresql.org; Thu, 06 Apr 2023 18:20:46 +0000 Received: by mail-il1-x136.google.com with SMTP id t5so9676802ilu.5 for ; Thu, 06 Apr 2023 11:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; t=1680805244; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=SwVPOGUf1UE+N0vGpCENL8lSSHykH/kt8DP2hEiPMJ8=; b=puhon+JgwMeDWqU+jh8eNAJetLXmR91F1uIa2Lhx02ebc9pnlaMugNGC1TSkSKOuZr EEtHeyOasQQRzt+AK8zK3cPGXcyk7tb7R8mda8Pi8qDPCwix5l+G5JdXUpUUA30B40EZ UTVRb2VxL+2zKASGya95/ohtst23MY3g5J6E5PNvw7W66XUv/wX3h8npNmubBV1OVnT5 fJ8rkjZpG554zq0m2DX9DqViifb9BwGjlpSG6SJV2XgMCtTig78CKV4R/8A0UbuJkGvk bxCjOuDuqkuTFGH6Zem1L6ZINhHxJpyrKj2wEzh2chNisJkAiswPzbinRam67YNrR8Ze cdbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680805244; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SwVPOGUf1UE+N0vGpCENL8lSSHykH/kt8DP2hEiPMJ8=; b=CG3EwYc0HGKeum3JF0VjkhuZG12RPTwx1Rf3dq6BvbyG9H7w2gJLeDrF/+1q+mxzgI K+kGGeRNXf4DH88S1m+9IEDODw4jdU8ANxbHAetxB+1N0R3n011OjPl8B/olPQS6U6r/ ArBYFojeiGcqGW/+/ZeKMB38IUHij01WlEWoD8JahxaNAW+casJpJSlUg3SoB1LWJW31 B0HQLnMIr2CJ4Y+o65p2rA+0BUOOtpwEOmK9x9ZdCYuyONL50S2SWwwvC4jh+opdhU9b kZURfkEXcflEnPsl0DxX1rAf8AWTrnS7XaMyRw7ague59sRD7/SFTXyJIpvMc2NZVw/f 59uQ== X-Gm-Message-State: AAQBX9eZrfgFU4RI945UbdCAIspVZawFl1gfKlH+L+cMwbXMeF2B5iKz RoQzBjqA+uuRwXGMN2s/j3bxBA== X-Google-Smtp-Source: AKy350YNSfZmdnBLHIusGNyI4Fa5kpqc4EtZpgwwvl3Y/ORncYakAJ8VAMCOuNDpwIuUXoCZkDuGKQ== X-Received: by 2002:a92:d28c:0:b0:325:b9ac:9458 with SMTP id p12-20020a92d28c000000b00325b9ac9458mr7646719ilp.27.1680805243968; Thu, 06 Apr 2023 11:20:43 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id u18-20020a056638305200b004061d3cce02sm539564jak.67.2023.04.06.11.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 11:20:43 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id EE25A800C8A; Thu, 6 Apr 2023 13:20:41 -0500 (CDT) Date: Thu, 6 Apr 2023 13:20:41 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Peter Eisentraut , pgsql-hackers@lists.postgresql.org Subject: Re: cataloguing NOT NULL constraints Message-ID: References: <20230405233356.qs4w4jtfc3kq4obl@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405233356.qs4w4jtfc3kq4obl@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Apr 06, 2023 at 01:33:56AM +0200, Alvaro Herrera wrote: > - The forms ADD (without USING INDEX), > + The forms ADD (without USING INDEX, and > + except for the NOT NULL column_name > + form to add a table constraint), The "except" part seems pretty incoherent to me :( > + if (isnull) > + elog(ERROR, "null conkey for NOT NULL constraint %u", conForm->oid); could use SysCacheGetAttrNotNull() > + if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) > + ereport(ERROR, > + errcode(ERRCODE_INVALID_TABLE_DEFINITION), > + errmsg("cannot add constraint to only the partitioned table when partitions exist"), > + errhint("Do not specify the ONLY keyword.")); > + else > + ereport(ERROR, > + errcode(ERRCODE_INVALID_TABLE_DEFINITION), > + errmsg("cannot add constraint to table with inheritance children"), missing "only" ? > + conrel = table_open(ConstraintRelationId, RowExclusiveLock); Should this be opened after the following error check ? > + arr = DatumGetArrayTypeP(adatum); /* ensure not toasted */ > + numkeys = ARR_DIMS(arr)[0]; > + if (ARR_NDIM(arr) != 1 || > + numkeys < 0 || > + ARR_HASNULL(arr) || > + ARR_ELEMTYPE(arr) != INT2OID) > + elog(ERROR, "conkey is not a 1-D smallint array"); > + attnums = (int16 *) ARR_DATA_PTR(arr); > + > + for (int i = 0; i < numkeys; i++) > + unconstrained_cols = lappend_int(unconstrained_cols, attnums[i]); > + } Does "arr" need to be freed ? > + * Since the above deletion has been made visible, we can now > + * search for any remaining constraints on this column (or these > + * columns, in the case we're dropping a multicol primary key.) > + * Then, verify whether any further NOT NULL or primary key exist, If I'm reading it right, I think it should say "exists" > +/* > + * When a primary key index on a partitioned table is to be attached an index > + * on a partition, the partition's columns should also be marked NOT NULL. > + * Ensure that is the case. I think the comment may be missing words, or backwards. The index on the *partitioned* table wouldn't be attached. Is the index on the *partition* that's attached *to* the former index. > +create table c() inherits(inh_p1, inh_p2, inh_p3, inh_p4); > +NOTICE: merging multiple inherited definitions of column "f1" > +NOTICE: merging multiple inherited definitions of column "f1" > +ERROR: relation "c" already exists Do you intend to make an error here ? Also, I think these table names may be too generic, and conflict with other parallel tests, now or in the future. > +create table d(a int not null, f1 int) inherits(inh_p3, c); > +ERROR: relation "d" already exists And here ? > +-- with explicitely specified not null constraints sp: explicitly -- Justin