Chapter 2. DB2 UDB’s materialized views 83
Isolation Level: Cursor Stability
---------------- STATEMENT 1 SECTION 203 ----------------
QUERYNO: 1
QUERYTAG:
Statement Type: Select
Updatable: No
Deletable: No
Query Degree: 1
Original Statement:
------------------
with dt as
(select cast(country_name as varchar(20)) as country_name, COUNT(*) as
count, year, month, cast(root_level as varchar(20)) as root_level,
cast(first_level as varchar(20)) as first_level
from fact1_subset, mesh, time, country
where fact1_subset.mesh_id=mesh.mesh_id and
fact1_subset.time_id=time.time_id and
fact1_subset.country_id=country.country_id
group by rollup(year, month), rollup(root_level, first_level),
country_name) select *
from dt
order by country_name, year, month, root_level, first_level
Optimized Statement:
-------------------
SELECT Q1.COUNTRY_NAME AS "COUNTRY_NAME", Q1.COUNT AS "COUNT", Q1.YEAR AS
"YEAR", Q1.MONTH AS "MONTH", Q1.ROOT_LEVEL AS "ROOT_LEVEL",
Q1.FIRST_LEVEL AS "FIRST_LEVEL"
FROM DB2ADMIN.AST6 AS Q1
ORDER BY Q1.COUNTRY_NAME, Q1.YEAR, Q1.MONTH, Q1.ROOT_LEVEL, Q1.FIRST_LEVEL
Query 7:
Note the following generalization of local predicates for this query:
? The YEAR, ROOT_LEVEL, and COUNTRY_NAME columns in the GROUP
BY list are all nullable, and therefore require the GROUPING function to be
defined in the select list of the materialized view.
We see that a materialized view from the above generalization is a coarser
granular version of AST6, since it only groups on three of the five columns
defined in AST6. We can therefore potentially reuse AST6.