Managing the WHERE Clause

The WHERE clause is the place to start your search for SQL you can change to get better performance. You already know what indexes you have. Now look at the optimizer plan for a problem query and see if the indexes are getting used or if the optimizer is searching the table row by row.

Why a Table Scan?

Just because you have an index on a column doesn’t mean your optimizer will use it.

  • If the amount of data is trivial (as in the msdpn tables), a search using an index may not be faster than a table scan and the optimizer may choose not to use the index.
  • If the query includes all rows in the table (no WHERE clause), the optimizer does a table scan.
  • If you’re retrieving a lot of data from the table, an index may give no advantage.
  • If the optimizer does not have accurate information on data distribution, it may pick the wrong index or no index at all.
  • If you include certain elements in the WHERE clause, you may make the index unavailable.
  • Of these elements, only the last two are under your control.
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • E-mail this story to a friend!
  • MySpace
  • StumbleUpon

Comments

Leave a Reply




  • About

    HD Techblog is a collection of knowledge about Information Technology from HD Expertise. We, HD engineers, contribute many different topics from small technical things like programming tips to broad view such as technology trends, business review. Our aim is to help you to find useful knowledge for your work from our expertise.