DB2 10.5 for Linux, UNIX, and Windows

Statistics used from expression columns in statistical views

The query optimizer can use statistics from the expression columns in statistical views to obtain accurate cardinality estimates which results in better access plans.

For example, consider a query that uses the UCASE scalar function:
    SELECT * FROM t1, t2 WHERE t2.c2 = UCASE(t1.c1)

The query optimizer can use the statistics from a statistical view for these types of queries to obtain better access plans.

The earlier example query would benefit from a statistical view that includes the UCASE scalar function on column c1. The following example creates a view that includes the UCASE scalar function on column c1.
    CREATE VIEW sv AS (SELECT UCASE(c1) AS c1 FROM t1)
    ALTER VIEW sv ENABLE QUERY OPTIMIZATION
    RUNSTATS ON TABLE dba.sv WITH DISTRIBUTION

To obtain statistics for these types of queries, one side of the predicate must be an expression that matches an expression in the statistical view column definition exactly.

Here are some examples where the query optimizer does not use the statistics from a statistical view: