Chapter 7. Understand and address data latency requirements 287
Example 7-1 represents one type of MQT, and shows how to create a partitioned
MQT for “customer sales by product line by day.”
Example 7-1 Creating partitioned MQT
CREATE TABLE CSTINSIGHT.MQT_CUST_PD_SALES_DATE AS
(SELECT C.CST_NUM, C.FULL_NM, F.DATE_ID, P.PD_GRP, SUM(QTY_SOLD*UNIT_PRICE) AS
SALES_TOTAL_DAY
FROM CSTINSIGHT.CUSTOMER C, CSTINSIGHT.CUSTOMER_TXN F, CSTINSIGHT.PRODUCT P
WHERE F.PD_ID= F.PD_ID AND C.CST_NUM = F.CUST_NUM
GROUP BY F.CST_NUM, P.PD_ID)
DATA INITIALLY DEFERRED REFRESH DEFERRED
ENABLE QUERY OPTIMIZATION MAINTAINED BY SYSTEM
COMPRESS YES
DISTRIBUTE BY HASH(PD_ID)
PARTITION BY RANGE(DATE_ID)
(PART PART_PAST STARTING(MINVALUE)
ENDING(’2010-06-30’) EXCLUSIVE IN TS_PROD_MQT_SALES,
PART PART_2010_Q3 STARTING (’2010-07-01’)
ENDING(’2010-09-30’) EXCLUSIVE IN TS_ PROD _MQT_SALES,
PART PART_2010_Q4 STARTING (’2010-09-01’)
ENDING(’2011-12-31’) EXCLUSIVE IN TS_ PROD _MQT_SALES,
PART PART_2011_Q1 STARTING (’2011-01-01’)
ENDING(’2011-03-30’) EXCLUSIVE IN TS_ PROD _MQT_SALES)
ORGANIZE BY (DATE_ID);
After the MQT table is created, perform these tasks:
1. Populate the CSTINSIGHT.MQT_CUST_PD_SALES_DATE by issuing the
following SQL statement; this operation is logged in the database transaction
logs.
Example 7-2 Refresh MQT table
REFRESH TABLE CSTINSIGHT.MQT_CUST_PD_SALES_DATE;
2. After populating the MQT, create an index on product and date columns to
improve the performance of operations on the MQT by issuing the DDL
statements shown in Example 7-3.
Example 7-3 Create index on MQT table
CREATE INDEX CSTINSIGHT.IDX_MQT_SALES_PD_DATE_PROD ON
CSTINSIGHT.MQT_CUST_PD_SALES_DATE (PD_ID, DATE_ID);
3. Collect statistics on the MQT by issuing the SQL statement shown in
Example 7-4 on page 288.