[Colocation][YSQL] Fix ADD PRIMARY KEY setting colocated when it was unset #9812
Labels
area/ysql
Yugabyte SQL (YSQL)
kind/bug
This issue is a bug
pgcm
priority/medium
Medium priority issue
Projects
Jira Link: [DB-384](https://yugabyte.atlassian.net/browse/DB-384)
ALTER TABLE ADD PRIMARY KEY
orALTER TABLE ADD CONSTRAINT ... PRIMARY KEY
may fail with error messageeven when the user does nothing related to colocation. It happens when the table has any reloptions set (see
SELECT reloptions FROM pg_class WHERE relname = 'mytabname'
). Since pk is tied to the main table, adding a primary key is done by creating a new table (YBCloneRelationSetPrimaryKey
). One part of it doesmeaning that, if any reloptions are set, the colocated reloptions is copied over. However, the colocated reloption could be unset while some other reloption, like fillfactor, was set, so this could end up explicitly setting colocated to the default value (true). There is a check later on that makes sure colocation is unset or false when operating on a noncolocated database (the default), so the error is thrown.
Repro:
Issue #9129 could have reduced the scope of this bug.
Credits to Suranjan Kumar for the initial bug report and Ted Yu for tracing to the root cause.
The text was updated successfully, but these errors were encountered: