Saya tidak bisa menjelaskan mengapa , tapi saya membuat pengamatan yang bisa membuat Anda solusi masalahnya.
Berikut adalah hasil dari explain_mview
untuk permintaan dari MV
. Anda
exec dbms_mview.explain_mview(q'[select A.y, B.z from A join B on A.x = B.x]');
SELECT capability_name, possible, SUBSTR(related_text,1,8)
AS rel_text, SUBSTR(msgtxt,1,60) AS msgtxt
FROM MV_CAPABILITIES_TABLE
WHERE capability_name like '%REWRITE%'
ORDER BY seq;
CAPABILITY_NAME P REL_TEXT MSGTXT
------------------------------ - -------- ------------------------------------------------------------
REWRITE Y
REWRITE_FULL_TEXT_MATCH Y
REWRITE_PARTIAL_TEXT_MATCH Y
REWRITE_GENERAL N the reason why the capability is disabled has escaped analys
REWRITE_PCT N general rewrite is not possible or PCT is not possible on an
Masalahnya adalah IMO di REWRITE_GENERAL = 'N'
Jika Anda mengulangi explain_mview
yang sama hanya menggunakan POJO
(=gabung lama biasa di Oracle) Anda akan melihat hasil yang berbeda.
truncate table mv_capabilities_table;
exec dbms_mview.explain_mview(q'[select A.y, B.z from A, B where A.x = B.x]');
CAPABILITY_NAME P REL_TEXT MSGTXT
------------------------------ - -------- ------------------------------------------------------------
REWRITE Y
REWRITE_FULL_TEXT_MATCH Y
REWRITE_PARTIAL_TEXT_MATCH Y
REWRITE_GENERAL Y
REWRITE_PCT N general rewrite is not possible or PCT is not possible on an
PCT_TABLE_REWRITE N A relation is not a partitioned table
PCT_TABLE_REWRITE N B relation is not a partitioned table
Sekali lagi penting `REWRITE_GENERAL ='Y'.
Perhatikan bahwa saya menggunakan 18.4 XE dan ini sangat mencurigakan dan harus diklarifikasi dengan Dukungan Oracle.
kabar baik terakhir adalah, jika Anda mendefinisikan MV
dengan Oracle bergabung , Anda dapat menggunakan ASNI bergabung dan Anda akan melihat penulisan ulang:
Contoh
create materialized view MV2
enable query rewrite
as
select
A.y, B.z from A, B where A.x = B.x
EXPLAIN PLAN SET STATEMENT_ID = 'jara1' into plan_table FOR
select A.y, B.z from A join B on A.x = B.x where y = 'A' and z = 'Z'
;
SELECT * FROM table(DBMS_XPLAN.DISPLAY('plan_table', 'jara1','ALL'));
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3846 | 15384 | 456 (8)| 00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV2 | 3846 | 15384 | 456 (8)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("MV2"."Z"='Z' AND "MV2"."Y"='A')