From f073ef1906d1a7889864730fb42cdd8ffbe4e85f Mon Sep 17 00:00:00 2001 From: Emily Na Date: Tue, 24 Jan 2023 12:18:49 -0500 Subject: [PATCH] [MERGE PG13][#14509]YSQL: Fix merge conflict occuring while checking the condition for creating a primary key index Summary: The attribute `yb_is_add_primary_key` was created as part of the `AlterTableCmd` struct to indicate this alter command is for adding primary key. In the past, there were 2 subcommands involved when creating a primary key: 1) `AddIndex` 2) `SetNotNull` (only if any one of the primary key attributes are not set as NOT NULL). In PG13, setting the primary key columns to NOT NULL is triggered in a separate API called `transformIndexConstraint`. The boolean flag has been set in the corresponding section where `AlterTableCmd` is prepared to alter the primary key column to be not null. Here is the excerpt from the PG13 comment mentioning the need to satisfy NOT NULL requirement prior to creating primary key index: ```Now we expect that the parser inserted any required ALTER TABLE SET NOT NULL operations before trying to create a primary-key index.``` Test Plan: Jenkins Reviewers: neil, myang Reviewed By: myang Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D21331 --- src/postgres/src/backend/catalog/index.c | 8 -------- src/postgres/src/backend/parser/parse_utilcmd.c | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/postgres/src/backend/catalog/index.c b/src/postgres/src/backend/catalog/index.c index 6eabb32e195d..d69908447fee 100644 --- a/src/postgres/src/backend/catalog/index.c +++ b/src/postgres/src/backend/catalog/index.c @@ -258,14 +258,6 @@ index_check_primary_key(Relation heapRel, attform = (Form_pg_attribute) GETSTRUCT(atttuple); if (!attform->attnotnull) - /* YB_TODO(ena@yugabyte) - * - * - The following code is removed as Postgres 13 raise error in this case. - * - Check if it is still needed, and implement accordingly. - - cmd->yb_is_add_primary_key = true; - - */ ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION), errmsg("primary key column \"%s\" is not marked NOT NULL", diff --git a/src/postgres/src/backend/parser/parse_utilcmd.c b/src/postgres/src/backend/parser/parse_utilcmd.c index caf1b4ed6888..c17a1b05dbf1 100644 --- a/src/postgres/src/backend/parser/parse_utilcmd.c +++ b/src/postgres/src/backend/parser/parse_utilcmd.c @@ -2876,6 +2876,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) notnullcmd->subtype = AT_SetNotNull; notnullcmd->name = pstrdup(key); + notnullcmd->yb_is_add_primary_key = true; notnullcmds = lappend(notnullcmds, notnullcmd); } }