Penguine Penguine - 1 year ago 86
MySQL Question

Average number of queries for best performance

I hope you guys wont mind my asking an off-topic and naive question. But, I could not find any satisfying answer for this.
Maximum, how many queries on an average a page must be allowed to process for rendering output(I am looking for the quality aspect). For example in an e-commerce application, 4 to 5 queries on average are required. The minimum the number of queries, shorter is its response time. Hence the question.
This question is irrespective of any programming platform. But, lets consider PHP and MySql as an example.

Answer Source

A single complex query that takes half a second to execute is less optimal than running 5 simple queries that take a total of 1/10 of a second to complete.

Having a higher number of simple queries may also be a trade-off in order to keep your code more organized. ORMs, for example, often wind up making a higher number of database calls than if you were manually writing the queries, but they make the application substantially simpler to develop.

Ultimately, though, any application that's complex enough to need to worry about the number of database calls is complex enough that it should really be utilizing a caching layer wherever possible anyway. As long as there are no pages that take a long time to load, it's not really worth nitpicking the exact number of queries.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download