【发布时间】:2022-11-24 19:23:58
【问题描述】:
我正在使用 Oracle 10g 企业版,我写了这个查询:
Select dc.codetypecl, dc.libtypecl, sum(ft.nbtransactions) as nb_transactions
from ftransaction ft, dclient dc
where (ft.codecl=dc.codecl)
and dc.libtypecl='Entreprise'
group by dc.codetypecl, dc.libtypecl, ft.nbtransactions;
然后创建这个物化视图来第二次执行第一个查询:
CREATE MATERIALIZED VIEW VMTCL
BUILD IMMEDIATE
REFRESH COMPLETE ON DEMAND
enable query rewrite
AS
select dc.codetypecl, dc.libtypecl, sum(ft.nbtransactions) as nb_transactions
from ftransaction ft, dclient dc
where (ft.codecl=dc.codecl)
group by dc.codetypecl, dc.libtypecl, ft.nbtransactions;
Execute DBMS_MVIEW.REFRESH('VMTCL');
alter system flush shared_pool;
alter system flush buffer_cache;
Select dc.codetypecl, dc.libtypecl, sum(ft.nbtransactions) as nb_transactions
from ftransaction ft, dclient dc
where (ft.codecl=dc.codecl)
and dc.libtypecl='Entreprise'
group by dc.codetypecl, dc.libtypecl, ft.nbtransactions;
一切都已正确执行,没有任何错误,问题是第二个查询没有使用物化视图 VMTCL,这是我得到的计划:
Plan hash value: 1387742792
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 56 | | 11689 (2)| 00:02:21 |
| 1 | HASH GROUP BY | | 2 | 56 | | 11689 (2)| 00:02:21 |
|* 2 | HASH JOIN | | 1374K| 36M| 12M| 11625 (1)| 00:02:20 |
|* 3 | TABLE ACCESS FULL| DCLIENT | 400K| 7815K| | 1821 (1)| 00:00:22 |
| 4 | TABLE ACCESS FULL| FTRANSACTION | 2665K| 20M| | 6648 (1)| 00:01:20 |
--------------------------------------------------------------------------------------------
在名称列中没有 VMTCL,我不明白为什么或如何解决这个问题。 谢谢您的帮助。
我尝试在创建物化视图后执行查询,但在执行计划的名称列中没有找到该物化视图的名称,即使一切都正确无误地执行,查询执行也没有使用该视图。
【问题讨论】:
标签: oracle oracle10g materialized-views