Oracle英文版培訓(xùn)課件之Data Warehouse:Les12_第1頁
Oracle英文版培訓(xùn)課件之Data Warehouse:Les12_第2頁
Oracle英文版培訓(xùn)課件之Data Warehouse:Les12_第3頁
Oracle英文版培訓(xùn)課件之Data Warehouse:Les12_第4頁
Oracle英文版培訓(xùn)課件之Data Warehouse:Les12_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論