Home > OS >  How to improuve performance in MySQL query-join
How to improuve performance in MySQL query-join

Time:10-20

⛰️ Hi comunity,

I'm using a normal MySQL query to join 2 tables.

My query in a simpler way looks like these (for these example i just put *, otherwise i have targeted elements)

SELECT table1.*, table2.*     
FROM table1
INNER JOIN table2 ON table1.table1_id = table2.id
WHERE table1.user_id = 5
ORDER BY date DESC

These code is working fine for me.. but speaking with my CTO he explained me that JOIN is actually joining 2 tables with all the data of all users_ids and then is selecting my asked data in "WHERE table1.user_id = 5".

He asked me to improve the code because when our app reach 50.000 users the database will get bigger so these query will get a long time to load.

I tried to move "WHERE table1.user_id = 5" above the INNER JOIN to select first the info i need and then to join it. but didn't work.

on these article explaining WHERE enter image description here

  • Do you have any sugestions to improve my query?
  • Do you have any articles to read ?

I'm really new to MySQL language

  • Related