# How the optimizer uses densities and histograms

When the optimizer analyzes a SARG, it uses the histogram values, densities, and the number of rows in the table to estimate the number of rows that match the value specified in the SARG:

• If the SARG value matches a frequency cell, the estimated number of matching rows is equal to the weight of the frequency cell multiplied by the number of rows in the table. This query includes a data value with a high number of duplicates, so it matches a frequency cell:

```where authors.city = "New York"
```

If the weight of the frequency cell is #.015606, and the authors table has 5000 rows, the optimizer estimates that the query returns 5000 * .015606 = 78 rows.

• If the SARG value falls within a range cell, the optimizer uses the range cell density to estimate the number of rows. For example, a query on a city value that falls in a range cell, with a range cell density of .000586 for the column, would estimate that 5000 * .000586 = 3 rows would be returned.

• For range queries, the optimizer adds the weights of all cells spanned by the range of values. When the beginning or end of the range falls in a range cell, the optimizer uses interpolation to estimate the number of rows from that cell that are included in the range.