Jump to content

How many SQL queries are too much?


KenBrace

Recommended Posts

What do you think is the feasible limit of database queries before it becomes too much?

 

In my experience you want to keep your query count below 20 if possible. Otherwise you'll start noticing loss in speed. I'm not sure about max though.

Link to comment
Share on other sites

I've seen 40+ on pages that still load quickly. I don't think the number of queries matter, but how many rows are in the tables and how efficient it's written.

 

Maybe so. I remember one mistake that I used to always make when writing database query script is that I always wrote "SELECT * FROM" instead of selecting only the fields needed. You should only select all fields when you're going to use all or almost all of the fields in the table.

Link to comment
Share on other sites

  • Administrators

Maybe so. I remember one mistake that I used to always make when writing database query script is that I always wrote "SELECT * FROM" instead of selecting only the fields needed. You should only select all fields when you're going to use all or almost all of the fields in the table.

For sure.  I get yelled at for this at times by my boss that codes some.  He spends a lot of time with PHP errors only to find it's because he called a field in PHP that was not defined in a SQL query I wrote :)  I told him for efficiency we need to do this, but he always select *'s.

Link to comment
Share on other sites

For sure.  I get yelled at for this at times by my boss that codes some.  He spends a lot of time with PHP errors only to find it's because he called a field in PHP that was not defined in a SQL query I wrote :)  I told him for efficiency we need to do this, but he always select *'s.

 

Doing a SELECT * FROM is definitely easier because there is less room for error but it isn't worth the resources you are sacrificing. In my opinion it is definitely worth your time and effort to make the queries as efficient as possible; even if it means a few more errors to deal with every now and then. It pays off after the project is complete.

Link to comment
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.

Guest
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...