A method for evaluating a user query on a
relational database having records stored therein, a
workload made up of a set of queries that have been executed on the
database, and a query optimizer that generates a query
execution plan for the user query. Each
query plan includes a plurality of intermediate
query plan components that verify a subset of records from the
database meeting query criteria. The method accesses the
query plan and a set of stored intermediate statistics for records verified by query components, such as histograms that summarize the cardinality of the records that verify the query component. The method forms a transformed query plan based on the selected intermediate statistics (possibly by
rewriting the query plan) and estimates the cardinality of the transformed query plan to arrive at a more accurate cardinality estimate for the query. If additional intermediate statistics are necessary, a
pool of intermediate statistics may be generated based on the queries in the
workload by evaluating the benefit of a given statistic over the
workload and adding intermediate statistics to the
pool that provide relatively great benefit.