版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
QueryRewriteObjectivesAftercompletingthislesson,youshouldbeabletodothefollowing:DefinequeryrewriteEnablequeryrewriteDeterminewhetherqueryrewriteoccurredExplainthevariousmethodsusedtorewritequeriesListqueryrewriterestrictionsTriestousematerializedviewsinsteadofbasetablestoreturnqueryresultsCansaveordersofmagnitudeofCPUandelapsedtimetoreturnresultsasqueriesareprecomputedCansignificantlyreduceI/ONotnecessaryforquerytobeintheexactformofthematerializedviewquerytorewriteVariousrequirementsforqueryrewritetotakeplaceQueryRewrite:OverviewCost-BasedQueryRewriteProcessPickthebestGenerateplanCompareplancostsQueryrewriteGenerateplanWhatCanBeRewritten?QueriesandsubqueriesinthefollowingtypesofSQLstatements:SELECTCREATETABLE…ASSELECTINSERTINTO…SELECTSubqueriesinDMLstatements:INSERTUPDATEDELETESubqueriesinthesetoperators:UNIONUNIONALLINTERSECTMINUSSettingInitializationParametersfor
QueryRewriteQUERY_REWRITE_ENABLED:SetatinstanceandsessionlevelTRUE:DefaultFORCEQUERY_REWRITE_INTEGRITY:SetatinstanceandsessionlevelENFORCED:DefaultTRUSTEDSTALE_TOLERATEDFullNotesPageUsingTrustedConstraintsTRUSTEDCONSTRAINTS:AllowsuseofnonvalidatedRELYconstraintsandrewriteagainstmaterializedviewsinUNKNOWNorFRESHstateduringrefreshRefreshcanusetrustedconstraints.QUERY_REWRITE_INTEGRITY
=
TRUSTEDduringrefreshENFORCEDCONSTRAINTS:Allowsuseofonlyvalidated,enforcedconstraintsandrewriteagainstmaterializedviewsinFRESHstateduringrefreshRefreshcanusevalidatedconstraints.QUERY_REWRITE_INTEGRITY
=
ENFORCEDduringrefreshEnablingQueryRewriteSpecifyENABLE
QUERY
REWRITEwhenthematerializedviewiscreated.EnablequeryrewriteaftercreationofthematerializedviewwithALTER
MATERIALIZED
VIEW.QueryRewriteRequirementsEitherallorpartoftheresultrequestedby
thequerymustbeobtainablefromthematerializedview.Constraintsordimensionsaredefined.QueryRewriteHintsREWRITEandNOREWRITEREWRITE[(mv1,mv2,…)]:Forcestheoptimizertouseamaterializedview(ifanyexist)torewritethequeryregardlessofthecostNOREWRITE:PreventstheoptimizerfromrewritingREWRITE_OR_ERROR:GeneratesanORA-30393errorifthequeryfailedtorewriteDidQueryRewriteOccur?1. Executethequery:2. Examinetheexecutionplan:SELECTs.zip,duct_type,sum(s.amount)FROMsaless,productpWHEREd_id=d_idGROUPBYs.zip,d_type;OPERATIONNAME
MAT_VIEWREWRITEACCESSFULLSALES_SUMMARYVerifyingThatQueryRewriteOccurredGoalistounderstand:Ifrewriteispossible,whichmaterializedviewisused?Whywasthequerynotrewritten?UsetheDBMS_MVIEW.EXPLAIN_REWRITEprocedurewiththefollowingparameters:SQLstatement(neverexecuted)OptionalmaterializedviewnameResultsarestoredintheREWRITE_TABLEtableorinaVARRAY.utlxrw.sqlmustbeexecutedinthecurrentschematocreateREWRITE_TABLE.UsingDBMS_MVIEW.EXPLAIN_REWRITEDECLAREqrytextVARCHAR2(2000):='SELECTcust_last_name,SUM(amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYcust_last_name';BEGINdbms_mview.explain_rewrite(qrytext,'smv','124');END;SELECTmessageFROMrewrite_tableWHEREstatement_id='124'
ORDERBYsequence;MESSAGEQSM-01001:queryrewritenotenabledFullNotesPageQueryRewriteMethodsTwocategoriesofqueryrewritemethods:TextmatchGeneralrewriteTextMatchRewriteMethodsTheoptimizerusestwomethods:Exacttextmatch:Entiretextofqueryiscomparedwithentiretextofmaterializedviewdetailquery.Partialtextmatch:OnlytextstartingfromtheFROMclauseofthequeryandmaterializedviewarecompared.Whitespacesareignored.Acomplexmaterializedviewisoneforwhich:Rewritecapabilityislimitedtotextmatchrewrite(exactorpartial)REWRITE_CAPABILITY=TEXTMATCHinDBA_MVIEWSExpressionMatchingQueryRewriteRewritebasedonequivalentmatchingof:ExpressionsSubexpressionsExpressionsshouldbestoredinthematerializedview’sSELECTlist.Ifaquery’sexpressiondoesnotmatchmaterializedview’sexpression,subexpressionsmatchingistried.Canonicalexpressionstakenintoaccount:CommutativityAssociativityDistributivityIfmultiplequeriesshareacommonsubexpression,storeitinthematerializedviewtoavoidfuturecomputations.ExpressionMatching:ExampleCREATEMATERIALIZEDVIEWsales_by_age_mv(age_bracket,sum_amount_sold)ENABLEQUERYREWRITEASSELECTTO_CHAR((2000-c.cust_year_of_birth)/10-0.5,999),SUM(s.amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYTO_CHAR((2000-c.cust_year_of_birth)/10-0.5,999);ExpressionMatching:ExampleSELECTTO_CHAR(((2000-c.cust_year_of_birth)/10)-0.5,999),SUM(s.amount_sold)FROMsaless,customerscWHEREs.cust_id=c.cust_idGROUPBYTO_CHAR((2000-c.cust_year_of_birth)/10-0.5,999);SELECTage_bracket,sum_amount_soldFROMsales_by_age_mv;QueryrewrittenGeneralQueryRewriteMethodsSelectioncompatibility(filtered)Joincompatibility(joinback)Datasufficiency(rollup)GroupingcompatibilityAggregatecomputabilityPartitionChangeTracking(PCT)and
QueryRewriteUsesmetadatatomaintainstalenessatafinergranularity:Onlyspecificsectionsofthematerializedviewareconsideredstale.QueryrewritecanuseamaterializedviewinENFORCED(orTRUSTED)modeforrowsconsideredfreshonly.Amaterializedview’sfreshrowsareidentifiedbyaddingselectionpredicatestothematerializedview’sdefinition.Amaterializedview’sfreshrowsareidentifiedbyusingpartitionsmarkersinthematerializedviewdefinition.PCTandQueryRewrite:ExampleCREATETABLEsales(time_idDATENOTNULL,prod_idNUMBERNOTNULL,cust_idNUMBERNOTNULL,channel_idCHAR(1)NOTNULL,promo_idNUMBERNOTNULL,quanty_soldNUMBERNOTNULL,amount_soldNUMBERNOTNULL)PARTITIONBYRANGE(time_id)(PARTITIONq1VALUESLESSTHAN('1-APR-2001'),PARTITIONq2VALUESLESSTHAN('1-JUL-2001'),PARTITIONq3VALUESLESSTHAN('1-OCT-2001'),PARTITIONq4VALUESLESSTHAN('1-JAN-2002'));PCTandQueryRewrite:Example1. CreatetheSSP_MVmaterializedview:2. InsertdataintothesecondpartitionoftheSALEStable: 3. Materializedviewqueryreflectingfreshrows:CREATEMATERIALIZEDVIEWssp_mvENABLEQUERYREWRITEASSELECTtime_id,prod_name,SUM(amount_sold)ASsamtFROMproductsp,salessWHEREd_id=d_idGROUPBYtime_id,prod_name;WHEREd_id=s.store_idANDtime_id<'1-JUL-2001'ORtime_id>='1-OCT-2001'INSERT…('1-JUL-2001'<=time_id<'1-OCT-2001')…PCTandQuery
Rewrite:ExampleThefollowingquery:Canberewritten:SELECTtime_id,SUM(amount_sold)ASsamtFROMproductsp,salessWHEREd_id=d_idANDtime_id<'1-JUL-2001'GROUPBYtime_id;SELECTtime_id,SUM(samt)FROMssp_mvWHEREtime_id<'1-JUL-2001'GROUPBYtime_id;QueryRewriteandBindVariablesConsidertwosituations:Materializedviewdetailqueryhasliterals.Iftheapplicationqueryusesbindvariablesforthoseliterals,thereisnopossiblerewrite.IfCURSOR_SHARINGissettoFORCEorSIMILAR,generalrewritecanoccuriftheapplicationquerydoesnotusebindvariablesforthoseliterals.Materializedviewdetailquerydoesnothaveliterals.Iftheapplicationqueryusesbindvariables,generalrewriteispossible.IfCURSOR_SHARINGissettoFORCEorSIMILAR,generalrewriteispossible.CreatingIndexesforMaterializedViewsRecommendations:Createasingle-columnbitmapindexoneachmaterializedviewkeycolumnforqueryexecutionperformance.CreateindexesoncolumnscontainingrowIDsformaterializedviewscontainingonlyjoins.Que
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 初二學(xué)期學(xué)習(xí)規(guī)劃解析模板
- 少兒美術(shù)課件成語故事繪畫《積少成多》
- 哲學(xué)與思維模板
- 基礎(chǔ)教育工作報(bào)告
- 教育心理學(xué)課件 第五講 學(xué)習(xí)遷移
- 廣東省茂名市區(qū)域2024-2025學(xué)年高三上學(xué)期10月份聯(lián)考 化學(xué)試題
- 【中職專用】備戰(zhàn)中職高考數(shù)學(xué)沖刺模擬卷五答案
- 上海市浦東新區(qū)2023-2024學(xué)年六年級上學(xué)期期中考試英語試題
- 常州廠房保潔方案
- 幫做工程估價課程設(shè)計(jì)
- 國際稅收籌劃課件
- 新教科版四年級科學(xué)上冊第一單元《聲音》單元復(fù)習(xí)教案
- 雙腔支氣管插管
- 北京市生育保險(xiǎn)醫(yī)療費(fèi)用手工報(bào)銷申報(bào)表
- 2022年鎮(zhèn)海煉化校園招聘筆試模擬試題及答案解析
- 學(xué)校崗位廉政風(fēng)險(xiǎn)排查登記表
- 小學(xué)綜合實(shí)踐活動-布貼畫教學(xué)設(shè)計(jì)學(xué)情分析教材分析課后反思
- 迎接等級醫(yī)院評審工作存在的主要問題及對策
- 兒童懸吊訓(xùn)練系統(tǒng)使用手冊(圖)
- 《汽車構(gòu)造與拆裝》期末試卷
- 接力版一年級音樂上冊二《(演唱)升旗》教學(xué)設(shè)計(jì)
評論
0/150
提交評論