mysql - Optimizing of database with multiple JOINs -


first, details website , database structure -

with website can learn english words, , can insert on each word sentence, association, image, in addition - each word has category, sub category, group...

my database includes 20 tables. user registers website 'add' users table 4000 rows - number of words on website. have serious problem while user filtering words (somthing 'search' word according char/s & category/s & group/s etc.. have 9 joins in sql query, , takes 1 min display results..

the target of joins - inside table users (where each user has 4000 rows / each row = word) there joins on style:

$this->db->join('users', 'sentences.id = users.sentence_id' ,'left'); 

the same thing associations, groups, images, binds between words etc.. users table includes id of sentences, associations, groups.. , join there connection.

i don't know do.. takes time. maybe problem structure of database? multiple joins? maybe using indexing? how , where? because it's necessary retrieve words indexing wouldn't help.

i'm using mysql.

first of all, if you're using many joins, indexes not save (as not used in joins of time).

there few things can do.

schema design

you want reconsider schema design/query if need 9 joins achieve doing!

from looks of it, seems your tables normalized, perhaps in 3rd normal form? in case consider denormalizing tables larger 1 avoid joins (joins more expensive full table scans!). there many online documentations on this, there's costs this, increases development complexity , data redundancy. denormalizing tables avoid joins , can make better use of indexes.

also believe myisam storage engine in mysql supports full text indexes. not have transactions , have table level-locking , no mvcc, depends on need.

resources

i suggest have read @ book high performance mysql. awesome book on tuning mysql databases

i suggest having read @ official documentation on chosen storage engine. significant each storage engine very different! innodb different myisam different pbxt. each engine has benefits , have consider 1 fits situation.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -