Jump to content

Using Dtabase Efficiently


Piyush
 Share

Recommended Posts

Performance in general is a cost/benefit ratio that you must work out. If a cost is acceptable for the performance benefits for making it, then do it.Some things in general:1. Write efficient queries, that fetch the least amount of needed data, but no less. If there's a faster way to get everything you need, without getting anything extra, do use it.2. Connect to the database as rarely as possible. If your server side language of choise can persist connections (as with PHP's mysql_pconnect()), do use this ability.3. If you need to use a result from a database more than once, do not execute a second query to refetch it. Instead, store the result, and then reuse it when needed.4. When possible and feasable (depending on the scenario), do not store the query results (e.g. in PHP, use mysql_unbuffered_query()).5. If you do not store the query results or the result set is expected to be of "medium" size, make sure to make as few queries as possible. Otherwise, if the query result is expected to be big, make a few separate queries instead of a single big one. The exact definitions of "medium" and "big" depend on the available RAM memory for your server side language.

Edited by boen_robot
Link to comment
Share on other sites

Also, make maximum use of JOIN, GROUP BY and related constructs - avoid sending multiple queries to get related information.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...