Question

We have a query in our system that has been a problem in the amount of logical reads it is using. The query is run often enough (a few times a day), but it is report in nature (i.e. gathering data, it is not transactional).

After having a couple of people look at it we are mulling over a few different options.

  1. Using OPTION (FORCE ORDER) and a few MERGE JOIN hints to get the optimizer to process the data more efficiently (at least on the data that has been tested).

  2. Using temp tables to break up the query so the optimizer isn't dealing with a very large query which is allowing it process it more efficiently.

We do not really have the option of doing a major schema change or anything, tuning the query is kind of the rallying point for this issue.

The query hints option is performing a little better than the other option, but both options are acceptable in terms of performance at this point.

So the question is, which would you prefer? The query hints are viewed as slightly dangerous because it we are overriding the optimizer etc. The temp table solution needs to write out to the tempdb etc.

In the past we have been able to see large performance gains using temp tables on our larger reporting queries but that has generally been for queries that are run less frequently than this query.

Was it helpful?

Solution

if you have exhausted optimizing via indexes and removed non-SARGABLE sql then I recommend going for the temp tables option:

  1. temp tables provide repeatable performance, provided they do not put excessive pressure on the tempdb in terms of size increase and performance - you will need to monitor those
  2. sql hints may stop being effective because of other table/index changes in the future
  3. remember to clean up temp tables when you are finished.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top