Showing posts with label optimization. Show all posts
Showing posts with label optimization. Show all posts

Thursday, July 19, 2012

Tips to Speed up SQL Query

Almost Every website data is stored in a database and served to visitors upon request. Databases are very fast, but there is lots of things that we need to  enhance  speed and make sure not to waste any server resources. In this article, I am suggesting you 10  tips to optimize and speed up your Sql query.

1. Do not Select column that we do not need.

    A very common practice is to use Select * from tablename.
    It's better to select column which you need in output.

2. Avoid using Cursor , use while loop instead of Cursor.

3. Avoid using Sql statement in a loop.It's takes a lot of resource.

4.Use Join instead of Subqueries.
    (SELECT MAX(created)
    FROM posts
    WHERE book_id =
AS latest_post FROM books a

However subqueries are useful, they often can be replaced by a join, which is definitely faster to execute.
SELECT, MAX(p.created) AS latest_post
FROM books 
INNER JOIN posts p
    ON ( = p.book_id)

Speeding Up Your Web Site

To speed up website we need to take care about certain things.
i am providing several points which you should take care while developing and deploying your website.

1. Minimize HTTP request
2. Use a CDN for static file.
3. Add an Expire Header.
4. Gzip or compress site text. here is the link for  Gzip Compression
5. Put CSS at top and script at the bottom.
6.minimize javascript.
7. Avoid duplicate Scripts.
8.Configure Etag.
9.Avoid Redirects.
10. Flush Buffer early

Definately i will elaborate on these tips or you can Google around to find some useful info!!!