Described herein are approaches to implementing dynamic sampling in a way
that lessens or eliminates the additional overhead incurred to perform
dynamic sampling. Also described are techniques for determining
characteristics about predicates not previously determined by
conventional techniques for dynamic sampling. Dynamic sampling is used by
a query optimizer to dynamically estimate predicate selectivities and
statistics. When a database statement is received by a database server,
an initial analysis of the database statement is made to determine the
efficacy of dynamic sampling, that is, to determine whether optimization
of the query would benefit from dynamic sampling and whether performance
is not excessively impacted by the dynamic sampling process. If this
analysis determines dynamic sampling should be used, then dynamic
sampling is undertaken.