Here are five ways to reduce fetch time of our sql queries.
1 – If you have access to check the execution plan of you query then check which part of your query is taking to much time. The execution time will show you which step is taking more resources and how many records are read in that step
2 – Then Based upon your execution plan SQL server will suggest you to create indexes to reduce the cpu usage. But creating index on top of any table should be the last option because of the following two reasons
- Creating two many index on top of one table might end up increasing the time of the query
- Creating index might also reduce the efficiency of the application which is writing into the table that you used in your query
3 – Only keep those columns in select clause which are required in your query. We should not read all the data unnecessarily by doing select * from table.Another reason of not using select * from table is that if you are using union operation in your job and if there is addition or removal of a column from the table then your job will start failing
4 – Try to do predicate push down on your transactional table so that you can reduce the number of records on which join would be performed. To do this you can make use of temporary variables.
5- You can also do an order by on join columns of two tables before joining. This also helps to reduce the time taken to join two tables.