Determining whether query rewrite occurred
You can use EXPLAIN to determine whether Db2 has rewritten a user query to use a materialized query table.
About this task
When Db2 rewrites
the query, the PLAN TABLE shows the name of the materialized query
that Db2 uses.
The value
of the TABLE_TYPE column is M to indicate that the table is a materialized
query table.
Example
Consider the following user query:
SELECT YEAR, AVG(QUANTITY * PRICE) AS AVGVAL
FROM TRANSITEM TI, TRANS T
WHERE TI.TRANSID = T.ID
GROUP BY YEAR;If Db2 rewrites the query to use a materialized query table, a portion of the plan table output might look like the following table.
| PLANNO | METHOD | TNAME | JOIN_TYPE | TABLE_TYPE |
|---|---|---|---|---|
| 1 | 0 | TRANSAVG | - | M |
| 2 | 3 | 2 | - | ? |
The value M in TABLE_TYPE indicates
that Db2 used
a materialized query table. TNAME shows that Db2 used
the materialized query table named TRANSAVG.You can also obtain
this information
from a performance trace (IFCID 0022).