Skip to content

Don't create redundant unique indexes on PG and SQLite#2950

Merged
tyt2y3 merged 1 commit intoSeaQL:masterfrom
rumpuslabs:fix-redundant-unique-index
Feb 15, 2026
Merged

Don't create redundant unique indexes on PG and SQLite#2950
tyt2y3 merged 1 commit intoSeaQL:masterfrom
rumpuslabs:fix-redundant-unique-index

Conversation

@rumpuslabs
Copy link
Contributor

PR Info

Bug Fixes

  • Prevent creation of redundant UNIQUE indexes on Postgres and SQLite

@rumpuslabs rumpuslabs force-pushed the fix-redundant-unique-index branch from 2b732ca to 892e327 Compare February 11, 2026 03:09
Copy link
Member

@tyt2y3 tyt2y3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the fix! it seems correct, can you briefly explain the root cause of the issue and the fix?

why is this applicable to SQLite as well?

@rumpuslabs
Copy link
Contributor Author

Postgres and SQLite both automatically create indexes for UNIQUE constraints, so the additional explicit index creation is redundant.

Postgres:

Adding a unique constraint will automatically create a unique B-tree index on the column or group of columns listed in the constraint.

SQLite:

In most cases, UNIQUE and PRIMARY KEY constraints are implemented by creating a unique index in the database.

let column_def = column.def();

if column_def.indexed || column_def.unique {
if column_def.indexed || (column_def.unique && backend == DbBackend::MySql) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’d help to add a comment here to explain why we filter pg/sqlite out.

@rumpuslabs
Copy link
Contributor Author

In the process of writing the requested comment, I got to thinking and did some checking, and it seems like MySQL also automatically creates an index from a UNIQUE constraint. I'm not sure where I got the idea that this was a MySQL-specific workaround.

Perhaps the correct fix is simply to remove || column_def.unique from that line? It was added in bc0f6b0 by @tyt2y3

@rumpuslabs
Copy link
Contributor Author

Or even if column_def.indexed && !column_def.unique since the indexed attribute is redundant?

@tyt2y3
Copy link
Member

tyt2y3 commented Feb 15, 2026

Or even if column_def.indexed && !column_def.unique since the indexed attribute is redundant?

let's do this. I will make the change

@tyt2y3 tyt2y3 merged commit 0c7f8ea into SeaQL:master Feb 15, 2026
38 checks passed
@rumpuslabs rumpuslabs deleted the fix-redundant-unique-index branch February 15, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redundant unique index on entity-first approach

3 participants