Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much SQL Query is too much SQL Query?

Tags:

sql

mysql

I was researching for a CMS to use and ran into a review on vBulletin 4.0; using about 200 queries on one page load.

I was then worried.

Further research brought me to other sites to see how much queries they are using and I found that some forum software such as Invision Power Board and PHPBB are using queries as low as 6 or 8.

Currently, my site uses about 25 to 40 queries.

Should I be worried?

like image 303
Anraiki Avatar asked Jan 29 '10 22:01

Anraiki


People also ask

How many SQL queries is too much?

Executive Summary. 200 SQL statements per webpage is excessive for client/server database engines like MySQL, PostgreSQL, or SQL Server.

Can SQL handle 1 million records?

Millions of rows is not a problem, this is what SQL databases are designed to handle, if you have a well designed schema and good indexes.

Is there a limit to how long a SQL query can be?

This issue occurs because SQL Server limits the number of identifiers and constants that can be contained in a single expression of a query. This limit is 65,535.

How many queries can a database have per page?

If your database service only allows you to make simple SQL queries, less than 20 queries would be fine for a small, common webpage, but if it's the webpage for your university or a decision taking support application, 60 may not be enough.


2 Answers

Don't be worried about number of queries.

Be worried about:

  1. Pages loading too slowly
  2. The SQL being too complicated to maintain.

Clarification:

SQL being too complicated can come from either too many queries OR a few queries that are very complicated (lots of joins and sub queries, etc).

like image 66
David Oneill Avatar answered Oct 18 '22 06:10

David Oneill


If you aim for something, aim for 3 reads and 1 writes per HTTP hit.

While these are arbitrary numbers (somehow, they are actually taken from the Advanced PHP Programming), they emphasize the ideas:

  • the number of SQL roundtrips should be low, under 10 for sure, per HTTP call
  • there is a difference between reads and writes, and the ratio should favour reads. writes create contention

Also remember that not all reads are equal: the 3 reads should be highly optimized reads, not full table scans with 4-5 outer joins...

like image 40
Remus Rusanu Avatar answered Oct 18 '22 05:10

Remus Rusanu