Jump to content

MySQL performance question

Recommended Posts

Hey all! What option do you think will scale better? To have 1 big select statement joining columns. Or multiple small queries to retreive the same information. Let me illustrate what I mean exaclty. Table2 and Table3 could have millions of records while, Table1 would only have thousands. The big select with Joining

SELECT table1.uri, table1.name, table2.random1, table2.random2, table3.something1, table3.something2FROM table1, table2, table3WHERE table1.id = 1 AND table2.id = 1 AND table3.id = 1

Multi small queries

SELECT uri, name FROM table1 WHERE id = 1SELECT random1, random2 FROM table2 WHERE id = 1SELECT something1, something2 FROM table3 WHERE id = 1


Link to post
Share on other sites

One bigger query is always preferable. However, you should use appropriate LIMIT clauses whenever that makes sense, so that each subquery can be as fast as possible and deliver only what's needed.So for example, if you're only displaying the first 100 records, adding "LIMIT 100" at the very end is not just a nice to have, but a must.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...