Connecting Tech Pros Worldwide Help | Site Map

MQT with MQT

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: 2 Weeks Ago
Hi,

I am using DB2 UDB 9.1, today i tried to create an MQT using another MQT.

For example : create table mqt_test as (select col1,col2 from mqt1) data initially deferred refresh deferred;

In the above statement mqt1 is one MQT created in my db, now i am trying to create another mqt i.e, mqt_test on top of it.

Is it possible to create like this because Oracle Mat views supports this, but i dont know about DB2. Can any one suggest me on this.


Thanks,
Siva
Member
 
Join Date: Aug 2007
Posts: 51
#2: 1 Week Ago

re: MQT with MQT


Using the sample EMPMDC, I just successfully created one along the lines you suggest so looks like this is fine in DB2 also.

Expand|Select|Wrap|Line Numbers
  1. create table testmdc as (select empno, dept from colin.empmdc) data initially deferred refresh deferred
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: 1 Week Ago

re: MQT with MQT


Thanks BURNETT,

"colin.empmdc" is the table or MQT in your database????
Member
 
Join Date: Aug 2007
Posts: 51
#4: 1 Week Ago

re: MQT with MQT


Oops. Freudian slip - I read this as MDC (Multi-dimensional Cluster) tables. For MQTs, you cannot create an MQT based on another MQT. The following sample code:

Expand|Select|Wrap|Line Numbers
  1. create table dept_sum(deptno,
  2.                       employees,
  3.                       total_salary) as
  4.        (select workdept, count(*), sum(salary)
  5.           from colin.employee
  6.          group by workdept)
  7.        data initially deferred refresh deferred;
  8.  
  9. create table dept_avgsal(deptno, avg_salary) as
  10.        (select deptno,
  11.                total_salary/employees
  12.           from dept_sum)
  13.        data initially deferred refresh deferred;
yields error message:

SQL20058N The fullselect specified for the materialized query table
"COLIN.DEPT_AVGSAL" is not valid. Reason code = "2". SQLSTATE=428EC

2 The fullselect must not reference any of the following object
types:
* materialized query table
* staging table
* declared global temporary table
* typed table
* system catalog table
* view that violates any of the materialized query table
restrictions
* A protected table
* A nickname that was created using the DISALLOW CACHING
clause in the CREATE NICKNAME or ALTER NICKNAME statement
* A view that depends, either directly or indirectly, on a
protected table.


This is the behaviour for V9.5 and V9.7.
Reply