sql >> Base de Datos >  >> RDS >> Oracle

La reescritura de consulta falla si el MV usa ASNI Join

Realmente no puedo explicar por qué , pero hice una observación que puede hacerle una solución alternativa el problema.

Aquí está el resultado de explain_mview para la consulta de tu MV

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

El problema es IMO en el REWRITE_GENERAL = 'N'

Si repites el mismo explain_mview solo usando POJO (=combinación simple y antigua en Oracle) verá un resultado diferente.

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

Nuevamente importante `REWRITE_GENERAL ='Y'.

Tenga en cuenta que estoy usando 18.4 XE y esto es muy sospechoso y debe aclararse con Oracle Support.

Las buenas noticias finales es, si define el MV con la unión de Oracle , puede usar la unión ASNI y verá la reescritura:

Ejemplo

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')