php - SQL query with multiple joins impacting performance -


i have relational mysql database 4000 records. contacts table related both keywords , notes tables manny-to-many relationships. wrote query (with php) retrieve each contact record and, each contact, related notes , keywords in group concat function. if grab contacts, query performs relatively 2 left joins , group concat, takes 30 seconds. there way speed up?

here query:

select  c.*, group_concat(distinct n.id, '[-]', n.value, '' separator '---') notes,         group_concat(distinct kk.id, '[-]', kk.value) keywords      contacts c     left join  notes n  on c.id n._contactid     left join           ( select  k.*, kc._contactid contactid              keywords k             inner join  keywords_contacts kc  on k.id kc._keywordid         ) kk  on kk.contactid c.id     group  c.id     order  c.`last name`, c.`first name` 

i query can see c.id n._contactid, here making performace low use = operator , give index foreign key field _contactid.

same k.id kc._keywordid use = operator instead of , apply index on field _keywordid.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -