版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
MaterializedViewsObjectivesAftercompletingthislesson,youshouldbeabletodothefollowing:DescribehowsummariescanbeusedtoimproveperformanceDifferentiatematerializedviewtypesExplainmaterializedviewintegrityCreateamaterializedviewListglobalizationimplicationsformaterializedviewsTheNeedforSummaryManagementHowcanyouimprovequeryresponsetime?Useindexes.Partitionyourdata.Implementparallelexecution.Whataboutprecomputingqueryresults?Createsummaries:MaterializedviewsAutomaticallyrewriteSQLapplications.Automaticallyrefreshdata.FullNotesPageUsingSummariestoImprovePerformanceSpecialtypesofaggregateviewsImprovequeryexecutiontimebyprecalculatingexpensivejoinsandaggregationoperationsbeforeexecutionandstoringresultsinadatabasetableCreatedusingaschemaobjectcalledamaterializedviewUsingSummariesOriginalquerybyuser:DBAcreatessummarytable:Newquerybyuserusingsummarytable:SELECT*FROMcust_sales_sum;SELECTc.cust_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id;CREATETABLEcust_sales_sumASSELECTc.cust_id,SUM(amount_sold)ASamountFROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id;UsingMaterializedViewsfor
SummaryManagementDBAcreatesmaterializedview:Userissuesoriginalquery:QueryisrewrittenbytheOracleserver:SELECT*FROMcust_sales_mv;CREATEMATERIALIZEDVIEWcust_sales_mvENABLEQUERYREWRITEASSELECTc.cust_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id;SELECTc.cust_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id;UsingMaterializedViewsfor
SummaryManagementDBAcreatesmaterializedview.Enduserqueriestablesandviews.Oracleserver
rewritesSQLquerytousematerializedview.123SummaryManagementComponentsMechanismstodefinematerializedviewsanddimensionsRefreshmechanismtoensurethatmaterializedviewscontainthelatestdataQueryrewritecapabilitytotransparentlyrewriteaquerytouseamaterializedviewSQLAccessAdvisor:RecommendsmaterializedviewsandindexestobecreatedDBMS_ADVISOR.TUNE_MVIEWprocedure:ShowsyouhowtomakeyourmaterializedviewfastrefreshableandusegeneralqueryrewriteUsingSummaryManagement1. UsetheSQLAccessAdvisortodeterminehowyouwillusematerializedviews.2. Creatematerializedviewsanddesignhowquerieswillberewritten.3. UseDBMS_ADVISOR.TUNE_MVIEWtoobtainanoptimizedmaterializedviewasnecessary.HowManyMaterializedViews?Queryrewritechooseswhichmaterializedviewtouse.Onematerializedviewperquery:IdealforqueryperformanceConsumestoomuchdiskspaceNotrecommendedOnematerializedviewformultiplequeries:OnematerializedviewcanbeusedtosatisfymultiplequeriesLessdiskspaceneededLesstimeneededtomaintainmaterializedviewsOneMaterializedViewforMultipleQueriesCREATEMATERIALIZEDVIEWcust_sales_mv2ENABLEQUERYREWRITEASSELECTcust_last_name,channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_last_name,s.channel_id;SELECTcust_last_name,channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_last_name,s.channel_id;SELECT*FROMcust_sales_mv2;QueryrewriteOneMaterializedViewforMultipleQueriesCREATEMATERIALIZEDVIEWcust_sales_mv2ENABLEQUERYREWRITEASSELECTcust_last_name,channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_last_name,s.channel_id;SELECTcust_last_name,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYcust_last_name;SELECTcust_last_name,SUM(amount)FROMcust_sales_mv2GROUPBYcust_id;QueryrewriteOneMaterializedViewforMultipleQueriesCREATEMATERIALIZEDVIEWcust_sales_mv2ENABLEQUERYREWRITEASSELECTcust_last_name,channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_last_name,s.channel_id;SELECTchannel_id,SUM(amount_sold)FROMsalesGROUPBYchannel_id;SELECTchannel_id,SUM(amount)FROMcust_sales_mv2GROUPBYchannel_id;QueryrewriteDeterminingWhichMaterialized
ViewtoCreateOnematerializedviewcanbeusedtosatisfymultiplequeries.Multiplematerializedviewscansatisfythesamequery.Abalancebetweenperformanceandspaceusagemustbefound.Whichmaterializedviewshouldyoucreate?Analyzeyourworkload.UsetheSQLAccessAdvisor.UseDBMS_MVIEW.EXPLAIN_REWRITEtoseewhyamaterializedviewisusedorignored.TypesofMaterializedViewsMaterializedviewswithaggregates:Materializedviewscontainingonlyjoins:CREATEMATERIALIZEDVIEWcust_sales_mvASENABLEQUERYREWRITEASSELECTc.cust_id,s.channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id,s.channel_id;CREATEMATERIALIZEDVIEWsales_products_mvASENABLEQUERYREWRITEASSELECTs.time_id,d_nameFROMsaless,productspWHEREd_id=d_id(+);TheNeedforNestedMaterializedViews
Typicaldatawarehouseneed:Createaggregatematerializedviewsusingdifferentgroupingcolumnsonasinglejoin.Maintainingthematerializedviewsistimeconsumingbecausetheunderlyingjoinisperformedmultipletimes.SALES_TIME_PROD_MVPRODUCTSSALESTIMESSALES_PROD_TIME_MVSametablesjoinedDifferentgroupingcolumnsPRODUCTSSALESTIMESUsingNestedMaterializedViews
Definitionisbasedonanothermaterializedview.Definitioncanalsoreferencenormaltables.PRODUCTSSALESTIMESSALES_PROD_TIME_JOINSALES_TIME_PROD_MVSALES_PROD_TIME_MVTablesarejoinedonetime.NestedMaterializedViews:RestrictionsAnestedmaterializedviewcannotbeaparentandagrandparentasshown:SALESTIMESSALES_TIMES_JOINPRODUCTSSALES_TIME_PROD_SUMParentofPRODUCTSGrandparentofPRODUCTSMaterializedView:ExampleCREATEMATERIALIZEDVIEWcust_sales_mv
PCTFREE0TABLESPACEexampleSTORAGE(INITIAL1MNEXT1MPCTINCREASE0)BUILDDEFERREDREFRESHCOMPLETEENABLEQUERYREWRITE ASSELECTc.cust_id,s.channel_id,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYc.cust_id,s.channel_idORDERBYc.cust_id,s.channel_id;NameStorageoptionsWhentobuilditHowtorefreshthedataUsethisforqueryrewriteDetail
queryDetailtablesMVkeysMaterializedViewsStorageWhenamaterializedviewiscreated,thefollowingobjectsarecreated:AcontainertabletostorethematerializedviewrowsThematerializedviewitselfOneindexformaterializedviewswithaggregatesonlyTheOBJECT_TYPEcolumnofDBA_OBJECTScontainsMATERIALIZED
VIEWfortheobject.Thecontainertablehasthesamenameasthematerializedviewobject.Acontainertablecanbeprebuilt.EstimatingMaterializedViewSize>VARIABLEnum_rowsNUMBER;>VARIABLEmv_sizeNUMBER;EXECDBMS_MVIEW.ESTIMATE_MVIEW_SIZE(-'simple_store',-'SELECTc.cust_state_province,'||-'SUM(amount_sold)'||-'FROMsaless,customersc'||-'WHEREs.cust_id=c.cust_id'||-'GROUPBYc.cust_state_province',-:num_rows,:mv_size);EstimatedrowsEstimatedstorageinbytesStatementIDforEXPLAINPLANSpecifyingBuildMethodsTwobuildmethodsareavailablewhencreatingthematerializedview:BUILDDEFERRED:CreatedbutnotpopulatedBUILDIMMEDIATE:CreatedandpopulatedTheBUILD_MODEcolumninDBA_MVIEWScontainsthemethodused.SpecifyingRefreshOptionsSpecifyhowthematerializedviewshouldberefreshedfromthedetailtables:COMPLETEFASTFORCENEVERTheREFRESH_METHODcolumninDBA_MVIEWScontainstheoptionvalue.SpecifyingRefreshExecutionModesTworefreshexecutionmodes:ONDEMAND:ManualONCOMMIT:Refreshdoneattransactioncommit;onlypossibleforfast-refreshablematerializedviews.Incaseoffailure,subsequentrefreshesaremanual.Schedule:AtregularintervalsTheREFRESH_MODEcolumninDBA_MVIEWScontainstherefreshexecutionmodevalue.UsingColumnAliases
inMaterializedViewsCREATEMATERIALIZEDVIEWsales_mvENABLEQUERYREWRITEASSELECTs.time_idsales_tid,c.time_idcosts_tidFROMsaless,productsp,costscWHEREd_id=d_idANDd_id=d_idANDd_nameIN(SELECTprod_name
FROMproducts);SELECTs.time_id,c.time_idFROMsaless,productsp,costscWHEREd_id=d_idANDd_id=d_idANDd_nameIN(SELECTprod_nameFROMproducts);QueryrewriteCREATEMATERIALIZEDVIEWsales_mv(sales_tid,costs_tid)ENABLEQUERYREWRITEASSELECTs.time_id,c.time_idFROMsaless,productsp,costscWHEREd_id=d_idANDd_id=d_idANDd_nameIN(SELECTprod_nameFROMproducts);SELECTs.time_id,c.time_idFROMsaless,productsp,costscWHEREd_id=d_idANDd_id=d_idANDd_nameIN(SELECTprod_nameFROMproducts);UsingMaterializedView
ColumnAliasListsQueryrewriteRegisteringUser-Defined
MaterializedViewTablesRegisterexistingmaterializedviewtableswithONPREBUILTTABLE.Theregisteredmaterializedviewcanbeusedforqueryrewrites.Itcanbemaintainedbyrefreshmethods.Requirements:Tableandmaterializedviewhavethesamename.Columnaliasesindetailquerymustcorrespond.Columndatatypesmustmatch;canusetheWITHREDUCED
PRECISIONclause.Tablecolumnsnotreferencedinthedefiningquery
areunmanagedcolumns.Tableremainsafterthematerializedviewisdropped.PartitioningandMaterializedViewsPartitioningthefacttables:ImprovestheopportunityoffastrefreshingthematerializedviewMayenablePartitionChangeTracking(PCT)refreshonthematerializedviewPartitioningthematerializedview:Partitionpruningcanbeusedforqueryrewrite.PartitionedMaterializedView:ExampleCREATEMATERIALIZEDVIEWpart_sales_mvPARALLELPARTITIONBYLIST(gid)(PARTITIONg1VALUES(0),PARTITIONg2VALUES(1),PARTITIONg3VALUES(3))BUILDIMMEDIATEREFRESHCOMPLETEENABLEQUERYREWRITEASSELECTprod_id,cust_id,time_id,GROUPING_ID(prod_id,cust_id,time_id)ASgid,sum(amount_sold)ASsum_salesFROMsalesGROUPBYGROUPINGSETS((prod_id,cust_id,time_id),(prod_id,cust_id),(prod_id));UsingEnterpriseManagerto
CreateMaterializedViewscr_mv_gen.gifPrivilegesRequiredto
CreateMaterializedViewsMustbegranteddirectly,notthroughrolesTocreateamaterializedviewinyourschema:CREATE
MATERIALIZED
VIEW,andCREATE
[ANY]
TABLE,andSELECTprivilegeoneachdetailtablenotownedTocreateamaterializedviewinanotherschema:CREATE
ANY
MATERIALIZED
VIEW,andMaterializedviewownermusthaveCREATE
[ANY]
TABLE,andSELECTprivilegeoneachdetailtablenotownedAdditionalPrivilegesRequiredto
CreateMaterializedViewsTocreateamaterializedviewrefreshedatcommittime:ON
COMMIT
REFRESHobjectprivilegeoneachdetailtablenotowned,orON
COMMIT
REFRESHsystemprivilegeToenablequeryrewrite:DetailtableownermusthaveQUERY
REWRITEsystemprivilegeIfyoudonotowndetailtables:GLOBAL
QUERY
REWRITEsystemprivilegeorQUERY
REWRITEoneachdetailtablenotownedSELECT
WITH
GRANT
OPTIONifmaterializedviewisdefinedonaprebuilttableGlobalizationandMaterializedViewsMaterializedviewsusethesettingsineffectduringmaterializedviewcreation.Alwaysspecifyglobalizationparameterstoensurethatcorrectresultsarereturned.WHEREvarchar_col=TO_DATE('01-FEB-02')TO_DATE('01-FEB-2002','DD-MON-YYYY','NLS_DATE_LANGUAGE=AMERICAN')GlobalizationParametersSignificantforMaterializedViewsNLS_LANGUAGENLS_TIMESTAMP_TZ_FORMATNLS_ISO_CURRENCYNLS_TIMESTAMP_FORMATNLS_DUAL_CURRENCYNLS_TIME_TZ_FORMATNLS_DATE_LANGUAGENLS_TIME_FORMATNLS_DATE_FORMATNLS_NUMERIC_CHARACTERSNLS_CALENDARNLS_TERRITORYNLS_CURRENCYNLS_SORTNLS_COMPAddingCommentstoMaterializedViewsAddingacommentforanexistingmaterializedview:Viewingcomments:COMMENTONMATERIALIZEDVIEWcust_sales_mvIS'salesmaterializedview';SELECTmview_name,commentsFROMuser_mview_commentsWHEREmview_name='CUST_SALES_MV';AlteringMaterializedViewsALTERMATERIALIZEDVIEWcust_sales_mvDISABLEQUERYREWRITE;Changingtherefreshoptionandrefreshmode:Recompilingthematerializedview:Enablingordisablingitsuseforqueryrewrite:ALTERMATERIALIZEDVIEWcust_sales_mvREFRESHFASTONCOMMIT;ALTERMATERIALIZEDVIEWcust_sales_mvCOMPILE;AlteringMaterializedViewsAllocatinganextent:Modifyingtheloggingattribute:ALTERMATERIALIZEDVIEWcust_sales_mvALLOCATEEXTENT;ALTERMATERIALIZEDVIEWcust_sales_mvNOLOGGING;MaintainingPartitionsof
aMaterializedViewALTERMATERIALIZEDVIEWsales_mv
TRUNCATEPARTITIONyear_1995;ALTERMATERIALIZEDVIEWsales_mv
DROPPARTITIONyear_1994;ALTERMATERIALIZEDVIEWfact_mv
EXCHANGEPARTITIONyear_2001
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度新型環(huán)保瓷磚批發(fā)合作協(xié)議3篇
- 供水系統(tǒng)施工方案
- 二零二五版城市綠化工程廢舊物資承包協(xié)議3篇
- 2025年度電腦硬件采購與維護服務(wù)合同2篇
- 二零二五年股權(quán)轉(zhuǎn)讓合同涉及的優(yōu)先購買權(quán)條款2篇
- 金屬擋板施工方案
- 2025年建筑項目合同備案2篇
- 事業(yè)單位2024年度協(xié)議管理策略與執(zhí)行方案版B版
- 2024年網(wǎng)絡(luò)云服務(wù)提供商技術(shù)支持合同
- 二零二五版公共衛(wèi)生安全風(fēng)險評估合同2篇
- 大數(shù)據(jù)與人工智能ppt
- 中醫(yī)科特色診療規(guī)范
- 建筑工程一切險條款版
- PEP小學(xué)六年級英語上冊選詞填空專題訓(xùn)練
- 古建筑修繕項目施工規(guī)程(試行)
- GA 844-2018防砸透明材料
- 化學(xué)元素周期表記憶與讀音 元素周期表口訣順口溜
- 非人力資源經(jīng)理的人力資源管理培訓(xùn)(新版)課件
- 鉬氧化物還原過程中的物相轉(zhuǎn)變規(guī)律及其動力學(xué)機理研究
- (完整word)2019注冊消防工程師繼續(xù)教育三科試習(xí)題及答案
- 《調(diào)試件現(xiàn)場管理制度》
評論
0/150
提交評論