Home » Developer & Programmer » Data Integration » Materialized views
Materialized views [message #93361] |
Mon, 30 August 2004 20:36 |
PagInit
Messages: 9 Registered: January 2004
|
Junior Member |
|
|
Hi,
Could any one please throw some light on my problem.
I have a Materialized view.
Create Materialized view test007
enable query rewrite as
SELECT
BOOKING_LINE.FISCAL_WEEK,
BOOKING_LINE.NET_SALES,
BOOKING_LINE.TRS_CURR,
CUSTOMER_MASTER_SOLD.CUST_ID,
CUSTOMER_MASTER_SOLD.TRD_INTRACO,
BOOKING_LINE.NET_SALES * BOOKING_LINE.EXRT_EURO
FROM
BOOKING_LINE,
CUSTOMER_MASTER CUSTOMER_MASTER_SOLD
Where
CUSTOMER_MASTER_SOLD.CUST_ID=BOOKING_LINE.CUST_SOL D_ID
AND CUSTOMER_MASTER_SOLD.TRD_INTRACO IN( 'TRADE','INTERCO')
When i used the below query , oracle rewrite the query only when
the condition (EXCHANGE_RATES_YEAR.FISCAL_YEAR)=substr((BOOKING_ LINE.FISCAL_WEEK),1,4)
is commented. When it is uncommented oracle is not using the Mat View.
May be some where i am wrong, could any one please help me to figure out my problem.
I tried with all options i.e enforced,thrusted and stale_tolerated.
I also tried by including column substr((BOOKING_LINE.FISCAL_WEEK),1,4) in the Materialized view.
SELECT
CUSTOMER_MASTER_SOLD.CUST_ID,
sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_FLOAT_YEAR.EXCHANGE_RATE),
sum(BOOKING_LINE.NET_SALES * BOOKING_LINE.EXRT_EURO),
sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_YEAR.EXCHANGE_RATE)
FROM
BOOKING_LINE,
EXCHANGE_RATES_YEAR EXCHANGE_RATES_FLOAT_YEAR,
EXCHANGE_RATES_YEAR,
CUSTOMER_MASTER CUSTOMER_MASTER_SOLD
WHERE
EXCHANGE_RATES_YEAR.CURR_CODE=BOOKING_LINE.TRS_CUR R
--And (EXCHANGE_RATES_YEAR.FISCAL_YEAR)=substr((BOOKING_ LINE.FISCAL_WEEK),1,4)
AND (CUSTOMER_MASTER_SOLD.CUST_ID=BOOKING_LINE.CUST_SO LD_ID)
AND (CUSTOMER_MASTER_SOLD.TRD_INTRACO IN( 'TRADE','INTERCO'))
AND ( EXCHANGE_RATES_FLOAT_YEAR.CURR_CODE= BOOKING_LINE.TRS_CURR )
GROUP BY
CUSTOMER_MASTER_SOLD.CUST_ID
test@orcl> select * from V$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
test@orcl> show parameter query
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled string TRUE
query_rewrite_integrity string TRUSTED
test@orcl> delete from plan_table;
test@orcl> explain plan for
2 SELECT
3 CUSTOMER_MASTER_SOLD.CUST_ID,
4 sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_FLOAT_YEAR.EXCHANGE_RATE),
5 sum(BOOKING_LINE.NET_SALES * BOOKING_LINE.EXRT_EURO),
6 sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_YEAR.EXCHANGE_RATE)
7 FROM
8 BOOKING_LINE,
9 EXCHANGE_RATES_YEAR EXCHANGE_RATES_FLOAT_YEAR,
10 EXCHANGE_RATES_YEAR,
11 CUSTOMER_MASTER CUSTOMER_MASTER_SOLD
12 WHERE
13 EXCHANGE_RATES_YEAR.CURR_CODE=BOOKING_LINE.TRS_CUR R
14 --And (EXCHANGE_RATES_YEAR.FISCAL_YEAR)=substr((BOOKING_ LINE.FISCAL_WEEK),1,4)
15 AND (CUSTOMER_MASTER_SOLD.CUST_ID=BOOKING_LINE.CUST_SO LD_ID)
16 AND (CUSTOMER_MASTER_SOLD.TRD_INTRACO IN( 'TRADE','INTERCO'))
17 AND ( EXCHANGE_RATES_FLOAT_YEAR.CURR_CODE= BOOKING_LINE.TRS_CURR )
18 GROUP BY
19 CUSTOMER_MASTER_SOLD.CUST_ID;
Explained.
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2776 | 94384 | | 230K|
| 1 | SORT GROUP BY | | 2776 | 94384 | 276M| 230K|
|* 2 | HASH JOIN | | 6541K| 212M| | 62 |
| 3 | TABLE ACCESS FULL | EXCHANGE_RATES_YEAR | 297 | 2376 | | 2 |
|* 4 | HASH JOIN | | 726K| 18M| | 48 |
| 5 | TABLE ACCESS FULL| EXCHANGE_RATES_YEAR | 297 | 2376 | | 2 |
| 6 | TABLE ACCESS FULL| TEST007 | 80764 | 1419K| | 44 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EXCHANGE_RATES_YEAR"."CURR_CODE"="TEST007"."TRS_CURR")
4 - access("EXCHANGE_RATES_FLOAT_YEAR"."CURR_CODE"="TEST007"."TRS_CURR")
test@orcl> explain plan for
2 SELECT
3 CUSTOMER_MASTER_SOLD.CUST_ID,
4 sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_FLOAT_YEAR.EXCHANGE_RATE),
5 sum(BOOKING_LINE.NET_SALES * BOOKING_LINE.EXRT_EURO),
6 sum(BOOKING_LINE.NET_SALES * EXCHANGE_RATES_YEAR.EXCHANGE_RATE)
7 FROM
8 BOOKING_LINE,
9 EXCHANGE_RATES_YEAR EXCHANGE_RATES_FLOAT_YEAR,
10 EXCHANGE_RATES_YEAR,
11 CUSTOMER_MASTER CUSTOMER_MASTER_SOLD
12 WHERE
13 EXCHANGE_RATES_YEAR.CURR_CODE=BOOKING_LINE.TRS_CUR R
14 And (EXCHANGE_RATES_YEAR.FISCAL_YEAR)=substr((BOOKING_ LINE.FISCAL_WEEK),1,4)
15 AND (CUSTOMER_MASTER_SOLD.CUST_ID=BOOKING_LINE.CUST_SO LD_ID)
16 AND (CUSTOMER_MASTER_SOLD.TRD_INTRACO IN( 'TRADE','INTERCO'))
17 AND ( EXCHANGE_RATES_FLOAT_YEAR.CURR_CODE= BOOKING_LINE.TRS_CURR )
18 GROUP BY
19 CUSTOMER_MASTER_SOLD.CUST_ID
20 ;
Explained.
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2982 | 139K| | 30148 |
| 1 | SORT GROUP BY NOSORT | | 2982 | 139K| | 30148 |
| 2 | MERGE JOIN | | 899K| 41M| | 30148 |
| 3 | SORT JOIN | | 900K| 32M| 82M| 29386 |
|* 4 | HASH JOIN | | 900K| 32M| | 736 |
| 5 | TABLE ACCESS FULL | EXCHANGE_RATES_YEAR | 297 | 2376 | | 2 |
|* 6 | HASH JOIN | | 100K| 2929K| | 732 |
| 7 | TABLE ACCESS FULL| EXCHANGE_RATES_YEAR | 297 | 3267 | | 2 |
| 8 | TABLE ACCESS FULL| BOOKING_LINE | 100K| 1855K| | 728 |
|* 9 | SORT JOIN | | 29312 | 286K| 1160K| 762 |
|* 10 | TABLE ACCESS FULL | CUSTOMER_MASTER | 29312 | 286K| | 667 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("EXCHANGE_RATES_FLOAT_YEAR"."CURR_CODE"="BOOKING_LINE"."TRS_CURR")
6 - access("EXCHANGE_RATES_YEAR"."CURR_CODE"="BOOKING_LINE"."TRS_CURR" AND "EXCHA
NGE_RATES_YEAR"."FISCAL_YEAR"=TO_NUMBER(SUBSTR(TO_CHAR("BOOKING_LINE".
"FISCAL_WEEK"),1,4))
9 - access("CUSTOMER_MASTER_SOLD"."CUST_ID"="BOOKING_LINE"."CUST_SOLD_ID")
filter("CUSTOMER_MASTER_SOLD"."CUST_ID"="BOOKING_LINE"."CUST_SOLD_ID")
10 - filter("CUSTOMER_MASTER_SOLD"."TRD_INTRACO"='INTERCO' OR "CUSTOMER_MASTER_SOL
D"."TRD_INTRACO"='TRADE')
Thanks in Advance
|
|
|
Goto Forum:
Current Time: Fri Dec 27 11:17:12 CST 2024
|