Closed KevinKelly25 closed 6 years ago
Since DROP INDEX IF EXISTS
is available as far back as at least 9.3, implementing this enhancement is relatively simple, and involves a guarded (only on server versions < 9.5) implementation of dropping the index (if it exists) and creating the index. CREATE UNIQUE INDEX IF NOT EXISTS
should still be used on server versions >= 9.6.
Edit: See comment from @smurthys directly below for an issue with this implementation. The index should only be created if it does not already exist, and not dropped if it already exists.
Just noting that this issue cannot be addressed using DROP INDEX IF EXISTS
because that would unnecessarily drop an already existing index. Also, it does not in any way help us in conditionally creating the index.
After removing some issues with versioning I have found another CREATE UNIQUE INDEX IF NOT EXISTS
so I ran a search to find all CREATE UNIQUE INDEX IF NOT EXISTS
in the project. There are two instances, both in addUserMgmtCore.sql
ln 200 and 216. This should probably also be addressed in PR #233
I apologize for not searching and mentioning additional cases of CREATE UNIQUE INDEX IF NOT EXISTS
in the original issue creation.
Thanks @KevinKelly25 for pointing out other places where the fix is required. I am working on the additional locations now.
Prior to 9.5 CREATE UNIQUE INDEX does not support IF NOT EXISTS. This causes a problem in
addRoleBaseMgmtCore.sql
LN 61, when trying to create a unique index on folded RoleName.Error:
As seen here in the docs IF NOT EXISTS is an modifier added to the functionality of CREATE UNIQUE INDEX in 9.5