|
- SQL> @?/rdbms/admin/utlxrw.sql;
- Table created.
- SQL> exec dbms_mview.explain_rewrite('SELECT SUM(prod_list_price - prod_min_price) M1, COUNT(prod_category) M2, prod_category FROM products GROUP BY prod_category', 'PROD_MV');
- PL/SQL procedure successfully completed.
- SQL> select message from rewrite_table order by sequence;
- MESSAGE
- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- QSM-01150: query did not rewrite
- QSM-01091: cost based optimizer found query rewrite is more expensive
- QSM-01209: query rewritten with materialized view, PROD_MV, using text match algorithm
- SQL> exec dbms_stats.gather_schema_stats('SH');
- PL/SQL procedure successfully completed.
复制代码- declare
- v_task varchar2(32);
- v_sqltext varchar2(4000);
- begin
- v_sqltext := ' CREATE MATERIALIZED VIEW sh.mv1 AS SELECT SUM(p.prod_list_price - p.prod_min_price) M1, COUNT(p.prod_category) M2, p.prod_category, sum(s.AMOUNT_SOLD) FROM sh.products p, sh.sales s where s.prod_id=p.prod_id GROUP BY prod_category';
- dbms_advisor.tune_mview(v_task,v_sqltext);
- dbms_advisor.create_file(dbms_advisor.get_task_script(v_task),'DIR1','tunemv.sql');
- end;
- /
复制代码- Rem SQL Access Advisor: Version 19.0.0.0.0 - Production
- Rem
- Rem Username: SYS
- Rem Task: TASK_3753
- Rem Execution date:
- Rem
- CREATE MATERIALIZED VIEW LOG ON
- "SH"."SALES"
- WITH ROWID, SEQUENCE("PROD_ID","AMOUNT_SOLD")
- INCLUDING NEW VALUES;
- ALTER MATERIALIZED VIEW LOG FORCE ON
- "SH"."SALES"
- ADD ROWID, SEQUENCE("PROD_ID","AMOUNT_SOLD")
- INCLUDING NEW VALUES;
- CREATE MATERIALIZED VIEW LOG ON
- "SH"."PRODUCTS"
- WITH ROWID, SEQUENCE("PROD_ID","PROD_CATEGORY","PROD_LIST_PRICE","PROD_MIN_PRICE")
- INCLUDING NEW VALUES;
- ALTER MATERIALIZED VIEW LOG FORCE ON
- "SH"."PRODUCTS"
- ADD ROWID, SEQUENCE("PROD_ID","PROD_CATEGORY","PROD_LIST_PRICE","PROD_MIN_PRICE")
- INCLUDING NEW VALUES;
- CREATE MATERIALIZED VIEW "SH"."MV1"
- REFRESH FAST WITH ROWID
- DISABLE QUERY REWRITE
- AS SELECT "SH"."PRODUCTS"."PROD_CATEGORY" C1, COUNT("SH"."PRODUCTS"."PROD_CATEGORY")
- M1, SUM("SH"."PRODUCTS"."PROD_LIST_PRICE"-"SH"."PRODUCTS"."PROD_MIN_PRICE")
- M2, COUNT("SH"."PRODUCTS"."PROD_LIST_PRICE"-"SH"."PRODUCTS"."PROD_MIN_PRICE")
- M3, SUM("SH"."SALES"."AMOUNT_SOLD") M4, COUNT("SH"."SALES"."AMOUNT_SOLD")
- M5, COUNT(*) M6 FROM "SH"."PRODUCTS", "SH"."SALES" WHERE "SH"."SALES"."PROD_ID"
- = "SH"."PRODUCTS"."PROD_ID" GROUP BY "SH"."PRODUCTS"."PROD_CATEGORY";
复制代码
- begin
- dbms_mview.explain_mview('MV1');
- end;
- /
复制代码- select * from mv_capabilities_table;
复制代码- truncate table mv_capabilities_table;
- SH MV1 PCT N 1
- SH MV1 REFRESH_COMPLETE Y 1002
- SH MV1 REFRESH_FAST Y 2003
- SH MV1 REWRITE N 3004
- SH MV1 PCT_TABLE N SH.PRODUCTS 359 2068 relation is not a partitioned table 4005
- SH MV1 PCT_TABLE N SH.SALES 376 2067 no partition key or PMARKER or join dependent expression in select list 4006
- SH MV1 REFRESH_FAST_AFTER_INSERT Y 5007
- SH MV1 REFRESH_FAST_AFTER_ONETAB_DML Y 6008
- SH MV1 REFRESH_FAST_AFTER_ANY_DML Y 7009
- SH MV1 REFRESH_FAST_PCT N 2157 PCT is not possible on any of the detail tables in the materialized view 8010
- SH MV1 REWRITE_FULL_TEXT_MATCH N 2159 query rewrite is disabled on the materialized view 9011
- SH MV1 REWRITE_PARTIAL_TEXT_MATCH N 2159 query rewrite is disabled on the materialized view 10012
- SH MV1 REWRITE_GENERAL N 2159 query rewrite is disabled on the materialized view 11013
- SH MV1 REWRITE_PCT N 2158 general rewrite is not possible or PCT is not possible on any of the detail tables 12014
- SH MV1 PCT_TABLE_REWRITE N SH.PRODUCTS 359 2068 relation is not a partitioned table 13015
- SH MV1 PCT_TABLE_REWRITE N SH.SALES 376 2185 no partition key or PMARKER in select list 13016
复制代码
|
|