php - MySQL relationships vs performance -
i create relationships between tables of databases.
i have read indexes slow write queries , unused indexes useless.
to relationship required column foreign key (i using innodb) can link table's primary key.
some of these indexes never used on search query , used relationship purpose.
i'm using php , yii framework queries , writes code based , checked integrity (unique, exists, etc).
will benefit these relationships if can slow down queries in future in big data context?
this highly depends on queries run on tables.
first: yes, every index slows down write operation, since new data has added @ right place (indexes sorted). if index used, not problem, since highly speeds operations.
but lets have @ example:
lets have table data1(id1,id2,some_text) , 1 table data2(id1,some_more_text). , lets have index (id2,id1) on data1 , index id1 on data2. here have add index id1 on data1 add relationship between data1 , data2. can improve changing index (id2, id1) (id1,id2). since indexes in mysql prefix indexes, can use (id1,id2) index id1 , use foreign key.
loose ability use index ups use field id2, since no prefix of index more.
if add indexes should consider following:
- what queries run on table?
if filter multiple columns, should put them in 1 index (mysql uses 1 index per table , query) - do need foreign key?
foreign keys useful make database take care data integrity. should try use existing indexes setup relationship, maybe changing order of multi-column index, if possible.
Comments
Post a Comment