Skip to content

Commit

Permalink
[MERGE PG13][#14509]YSQL: Fix merge conflict occuring while checking …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
emhna authored and nocaway committed Jul 20, 2023
1 parent a6974e5 commit f073ef1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
8 changes: 0 additions & 8 deletions src/postgres/src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/backend/parser/parse_utilcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f073ef1

Please sign in to comment.