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 1sqx4k-00EIyf-Eg for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2024 15:58:42 +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 1sqx4i-00CGsq-Q0 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Sep 2024 15:58:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqx4i-00CGnu-FL for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2024 15:58:40 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sqx4f-001pfN-V2 for pgsql-hackers@lists.postgresql.org; Wed, 18 Sep 2024 15:58:39 +0000 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-82ab349320fso255513439f.1 for ; Wed, 18 Sep 2024 08:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726675117; x=1727279917; darn=lists.postgresql.org; 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=5pf+Fpfg0+ZGjJh5zDn9+JjqgG1sZnQ6lvFHVOi3GZk=; b=TxR/lubnkgt114yg6PP59zetbCS39N7tjgaJ9kxKrNvaLzb3RB7Gqcd+36girg14Zv NBg1x6B7qOnFQ1W39d5u7zc47mSc4BS8uSyvHHJO1qs2rMRA9FUA+h2Iv2skb7SBvQvG e3hOuIqL6zC0c12HIw8Cr11zefBMyq4GSJgHtvv7/42+BShVSm8AyM2NdKEiv/zgwKyX 5/213y2r3nAR0XZPN0s/ZoInRtTfYaarH8X4h19iaGazt9i8MbDaCdKuplp2R9C/l6JT ZQ7w+VPiyy+/yqndItEAWbLmpNLVCwxc3gUaCy7ugVXxSeI8Z921CuVF5rOB5K0NGnL6 dd6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726675117; x=1727279917; 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=5pf+Fpfg0+ZGjJh5zDn9+JjqgG1sZnQ6lvFHVOi3GZk=; b=DO+oELzVRg+wdCe2pau68QBVJ4uKB38DHwEuMtekBD38wz6DCtx3mFuj4Rgqat7zax NjfEHnqnMz0YUnfNfDMKVvC3SlN5JPg+mOawKvUk3zbhzr9oOCsnifglUnv1nFH+Oj3m EHUPwe0gwHlttOnIg3nM1PRA0jhLMzSDAlI95vO1JD094ZmJt94rPk2FyRxujxtrbtz0 /ebVnkEzoGwpUr9LGkw2nOH6hDK7uAl5Ed3H6T4l6Y618PNWmJnZaqQCCEmD8NcR4WPK Qzmd6WVU8zVHbMrGpdXJYvYK2s4nz5eCgachf+YczAycz7NYy49Dtv05pg6rI4wicepv KkaQ== X-Forwarded-Encrypted: i=1; AJvYcCVX3Y+OrGUupp8P9fZen17vnqjLQgDRDfkiDFMIEpBhsTK2hM1WqxH8vEaW8RkmrBUj3s6g0IRxsPphUD7G@lists.postgresql.org X-Gm-Message-State: AOJu0YwW9HfWW/yUXYcw1zVX01XIMwjUn0d5PjK/oIFw1Wmw5LsNeubL gP8+5OnPzDUBkWh9Eq7Izv/8Q6KXVlIzwn9GF1Y4v+5ey00+w/IGLcMAvA== X-Google-Smtp-Source: AGHT+IH4t4CESZ9o0c7KGU7Y2E+IQrvRUBfEmjDsmKzOXNczMn6gN4MMP1C2wrAZ1pbyC8lXOuBSOQ== X-Received: by 2002:a05:6e02:13a6:b0:398:39f:8b4d with SMTP id e9e14a558f8ab-3a0848e54afmr229655345ab.5.1726675116937; Wed, 18 Sep 2024 08:58:36 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4d37ebf4c5fsm2523197173.13.2024.09.18.08.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 08:58:36 -0700 (PDT) Date: Wed, 18 Sep 2024 10:58:34 -0500 From: Nathan Bossart To: Michael Paquier Cc: "David G. Johnston" , Postgres hackers Subject: Re: Partitioned tables and [un]loggedness Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="erolw0sa1as0wTI7" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --erolw0sa1as0wTI7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 18, 2024 at 10:17:47AM -0500, Nathan Bossart wrote: > Could we also use ATT_PARTITIONED_TABLE to remove the partitioned table > check in ATExecAddIndexConstraint()? Eh, never mind. That ends up being gross because you have to redo the relation type check in a few places. -- nathan --erolw0sa1as0wTI7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="add_constraint_using_index_on_part_table.patch" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 9966d1f53c..777de48c69 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -4922,7 +4922,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, pass = AT_PASS_ADD_CONSTR; break; case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */ - ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_PARTITIONED_TABLE); + ATSimplePermissions(cmd->subtype, rel, ATT_TABLE); /* This command never recurses */ /* No command-specific prep needed */ pass = AT_PASS_ADD_INDEXCONSTR; @@ -5583,6 +5583,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, pass = AT_PASS_ADD_INDEX; break; case AT_AddIndexConstraint: + ATSimplePermissions(cmd2->subtype, rel, ATT_TABLE); /* This command never recurses */ /* No command-specific prep needed */ pass = AT_PASS_ADD_INDEXCONSTR; @@ -5596,6 +5597,7 @@ ATParseTransformCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, case CONSTR_PRIMARY: case CONSTR_UNIQUE: case CONSTR_EXCLUSION: + ATSimplePermissions(cmd2->subtype, rel, ATT_TABLE); pass = AT_PASS_ADD_INDEXCONSTR; break; default: @@ -9208,15 +9210,6 @@ ATExecAddIndexConstraint(AlteredTableInfo *tab, Relation rel, Assert(OidIsValid(index_oid)); Assert(stmt->isconstraint); - /* - * Doing this on partitioned tables is not a simple feature to implement, - * so let's punt for now. - */ - if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables"))); - indexRel = index_open(index_oid, AccessShareLock); indexName = pstrdup(RelationGetRelationName(indexRel)); diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index cf6eac5734..bdb7731543 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -1593,7 +1593,8 @@ DROP TABLE cwi_test; CREATE TABLE cwi_test(a int) PARTITION BY hash (a); create unique index on cwi_test (a); alter table cwi_test add primary key using index cwi_test_a_idx ; -ERROR: ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables +ERROR: ALTER action ADD CONSTRAINT cannot be performed on relation "cwi_test" +DETAIL: This operation is not supported for partitioned tables. DROP TABLE cwi_test; -- PRIMARY KEY constraint cannot be backed by a NULLS NOT DISTINCT index CREATE TABLE cwi_test(a int, b int); --erolw0sa1as0wTI7--