




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 法蘭四氟蝶閥行業(yè)深度研究報(bào)告
- 登岳陽樓(教學(xué)設(shè)計(jì))-2024-2025學(xué)年高一語文必修下冊同步備課系列(教學(xué)設(shè)計(jì)+教學(xué)設(shè)計(jì))(統(tǒng)編版2019)
- 《圓的認(rèn)識》(教學(xué)設(shè)計(jì))-2024-2025學(xué)年六年級上冊數(shù)學(xué)人教版
- Unit 4(第4課時 Section B 1a-2b)(教學(xué)設(shè)計(jì))七年級英語上冊同步高效課堂(人教版2024)
- 2025年車輛牌照租賃與車輛租賃公司風(fēng)險(xiǎn)管理合同
- 2024-2025學(xué)年廣東省佛山市順德區(qū)桂洲、文德等校高一化學(xué)11月期中聯(lián)考試卷
- 2025-2030年中國光耦合器金屬陶瓷項(xiàng)目投資可行性研究分析報(bào)告
- 大班飲水環(huán)節(jié)策略組織
- 中國電子胃腸鏡市場評估分析及發(fā)展前景調(diào)查戰(zhàn)略研究報(bào)告
- 果林轉(zhuǎn)讓合同范本
- 海洋鉆井(平臺)
- (完整版)電梯的鋼結(jié)構(gòu)施工方案
- 中國近現(xiàn)代史綱要ppt全共64頁課件
- 腰椎間盤突出癥(腰痹病)中醫(yī)臨床路徑
- 教學(xué)團(tuán)隊(duì)建設(shè)總結(jié)報(bào)告
- 研發(fā)經(jīng)費(fèi)填報(bào)指標(biāo)說明及核算方法
- 裝飾施工進(jìn)度計(jì)劃網(wǎng)絡(luò)圖及橫道圖
- 一年級思維訓(xùn)練(課堂PPT)
- 實(shí)木電腦桌書桌安裝圖
- GB_T 27025-2019 檢測和校準(zhǔn)實(shí)驗(yàn)室能力的通用要求(高清版)
- 俱樂部經(jīng)營俱樂部經(jīng)營
評論
0/150
提交評論