Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't add indices on columns with UNIQUE constraint #113

Open
wants to merge 3 commits into
base: maint/0.0828xx
Choose a base branch
from

Conversation

hidden-primary-net
Copy link

SQL::Translator::Parser::DBIx::Class adds an index to foreign key
columns as this "is normally the sensible thing to do". Agreed.

Besides SQL::Translator::Parser::DBIx::Class takes care to not add an
additional index to primary key columns ("some RDBMS croak on this, and
it generally doesn't make much sense") but doesn't consider columns with
a UNIQUE constraint where it doesn't make any sense either.

Generally this should not be dangerous but it doesn't help at all.
From my understanding the SQL optimizer will use the better index thus
the UNIQUE constraint would win in any case.

Even worse any INSERT, UPDATE or DELETE operation would need to maintain
the index which is never used. This does not sound sensible to me.

The supposed patch avoids the adding of those indices if the column is
checked if it is the first column of a UNIQUE constraint. If it's not
the index is added, if it is the first column it is handled like a
primary key.

SQL::Translator::Parser::DBIx::Class adds an index to foreign key
columns as this "is normally the sensible thing to do". Agreed.

Besides SQL::Translator::Parser::DBIx::Class takes care to not add an
additional index to primary key columns ("some RDBMS croak on this, and
it generally doesn't make much sense") but doesn't consider columns with
a UNIQUE constraint where it doesn't make any sense either.

Generally this should not be dangerous but it doesn't help at all.
From my understanding the SQL optimizer will use the better index thus
the UNIQUE constraint would win in any case.

Even worse any INSERT, UPDATE or DELETE operation would need to maintain
the index which is never used. This does not sound sensible to me.

The supposed patch avoids the adding of those indices if the column is
checked if it is *the first column* of a UNIQUE constraint. If it's not
the index is added, if it is the first column it is handled like a
primary key.
@msouth
Copy link

msouth commented Feb 5, 2017

Another consideration in favor of this is the disk space that is taken up by an unnecessary index.

BTW, is something wrong with the Travis setup? I tried to look into the supposed failure and the one I picked that said it failed looked like it was displaying the output of a successful build ("all tests passed", and "job exited with 0", etc in the output). The one I looked at was https://travis-ci.org/dbsrgits/dbix-class/jobs/198374714

I want to achieve a test checking the given schema for automatic indices
on foreign key columns actually being covered by a UNIQUE constraint.

Unfortunately I don't understand the difference between this test and
t/86sqlt.

* I have to "use SQL::Translator"
* tables are not populated in SQL::Translator->schema
* SQL::Translator->schema->get_table returns undef
Test were failing earlier, thus adding SQL::Translator build dep.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants