33.16. Update Statistics

This is going to sound obvious, but the optimizer cannot work without valid statistics. Some signs that your statistics need to be updated are:

  1. Two queries with the same basic structure have different execution times. This usually means that the statistical distribution has changed, so one of the queries is being executed under old assumptions.

  2. You have just loaded a lot of new data. This is often a good time to do the update to the statistics, because some products can get them as part of the loading operation.

  3. You have just deleted a lot of old data. Unfortunately, deletion operations do not change statistics like insertions.

  4. You have changed the query mix. For example, the end-of-the-month reports depend on shared views ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.