Oracle英文版培訓(xùn)課件之SQL Tuning:Les07-RW_第1頁(yè)
Oracle英文版培訓(xùn)課件之SQL Tuning:Les07-RW_第2頁(yè)
Oracle英文版培訓(xùn)課件之SQL Tuning:Les07-RW_第3頁(yè)
Oracle英文版培訓(xùn)課件之SQL Tuning:Les07-RW_第4頁(yè)
Oracle英文版培訓(xùn)課件之SQL Tuning:Les07-RW_第5頁(yè)
已閱讀5頁(yè),還剩32頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

GatheringStatisticsObjectivesAftercompletingthislesson,youshouldbeabletodothefollowing:Identifytable,index,andcolumnstatisticsDescribetheAutomaticStatisticsGatheringmechanismUsetheDBMS_STATSpackagetocollectstatisticsmanuallyIdentifypredicateselectivitycalculationsWhatAreOptimizerStatistics?CollectionofdatathatdescribesthedatabaseandtheobjectsinthedatabaseInformationusedbyqueryoptimizertoestimate:SelectivityofpredicatesCostofeachexecutionplanAccessmethodandjoinmethodCPUandI/OcostsTypesofOptimizerStatisticsObjectstatisticsTablestatisticsColumnstatisticsIndexstatisticsSystemstatisticsI/OperformanceandutilizationCPUperformanceandutilizationFullNotesPageHowStatisticsAreGatheredAutomaticstatisticsgatheringGATHER_STATS_JOBManualstatisticsgatheringDBMS_STATSpackageDynamicsamplingAutomaticStatisticsGatheringOracleDatabase10gautomatesoptimizerstatisticscollection:Statisticsaregatheredautomaticallyonalldatabaseobjects.GATHER_STATS_JOBisusedforstatisticscollectionandmaintenance.Schedulerinterfaceisusedforschedulingthemaintenancejob.Automatedstatisticscollection:EliminatesneedformanualstatisticscollectionSignificantlyreducesthechancesofgettingpoorexecutionplansManualStatisticsGathering YoucanusetheDBMS_STATSpackageto:GenerateandmanagestatisticsforusebytheoptimizerGather,modify,view,export,import,anddeletestatisticsIdentifyornamestatisticsthataregatheredGatherstatisticson:Indexes,tables,columns,andpartitionsAllschemaobjectsinaschemaordatabaseGatherstatisticseitherseriallyorinparallelManagingAutomaticStatisticsCollectionJobconfigurationoptionsStatistics-collectionconfigurationoptionsJobConfigurationOptionsSettingstatus:ENABLEDorDISABLEDMaintainingschedule:maintenancewindowManagingtheJobSchedulerVerifyingAutomaticStatisticsGathering:SELECTowner,job_name,enabled

FROMDBA_SCHEDULER_JOBS

WHEREJOB_NAME='GATHER_STATS_JOB';BEGINDBMS_SCHEDULER.DISABLE('GATHER_STATS_JOB');END;/BEGINDBMS_SCHEDULER.ENABLE('GATHER_STATS_JOB');END;/DisablingandenablingAutomaticStatisticsGathering:ManagingtheMaintenanceWindowWEEKNIGHT_WINDOWWEEKEND_WINDOWEXECUTEDBMS_SCHEDULER.SET_ATTRIBUTE('WEEKNIGHT_WINDOW','repeat_interval','freq=daily;byday=MON,TUE,WED,THU,FRI;

byhour=0;byminute=0;bysecond=0');ChangingtheGATHER_STATS_JOBScheduleStatisticsCollectionConfigurationDMLmonitoringSamplingDegreeofparallelismHistogramsCascadeDMLMonitoringTheDMLmonitoringfacility:TracksDMLstatementsandtruncationoftablesIsusedbytheAutomaticStatisticsGatheringmechanismforidentifyingsegmentswithstalestatisticsIsenabledbydefaultwhenSTATISTICS_LEVELissettoTYPICALorALLYoucan:ViewtheinformationonDMLchangesintheUSER_TAB_MODIFICATIONSviewUseDBMS_STATS.FLUSH_DATABASE_MONITORING_INFOtoupdatetheviewwithcurrentinformationUseGATHER_DATABASE_STATSorGATHER_SCHEMA_STATSformanualstatisticsgatheringfortableswithstalestatisticswhenOPTIONSissettoGATHERSTALEorGATHERAUTOFullNotesPageSamplingStatisticsgatheringreliesonsamplingtominimizeresourceusage.YoucanusetheESTIMATE_PERCENTargumentoftheDBMS_STATSprocedurestochangethesamplingpercentagetoanyvalue.SettoDBMS_STATS.AUTO_SAMPLE_SIZE(default)tomaximizeperformancegains.AUTO_SAMPLE_SIZEenablesthedatabasetodeterminetheappropriatesamplesizeforeachobjectautomatically.EXECUTEDBMS_STATS.GATHER_SCHEMA_STATS('SH',DBMS_STATS.AUTO_SAMPLE_SIZE);FullNotesPageDegreeofParallelismAutomaticStatisticsGatheringoperationscanruneitherseriallyorinparallel.Bydefault,thedegreeofparallelismisdeterminedautomatically.YoucanalsomanuallyspecifythedegreeofparallelismusingtheDEGREEargumentoftheDBMS_STATSprocedures.SettingtheDEGREEparametertoDBMS_STATS.AUTO_DEGREE(default)enablestheOracleDatabasetochooseanappropriatedegreeofparallelismevenwhencollectingstatisticsmanually.HistogramsInfluenceoptimizerdecisionsonselectingtheoptimalexecutionplanProvideimprovedselectivityestimatesinthepresenceofdataskewEnableoptimalexecutionplanswithnonuniformdatadistributionsColumnValueCountofRows10102010503012640567502481050203040Numberofbuckets=501050203040CreatingHistogramsTheAutomaticStatisticsGatheringmechanismcreateshistogramsasneededbydefault.YoucanusetheDBMS_STATSpackagetochangethisdefault.YoucanuseDBMS_STATStocreatehistogramsmanually.Thefollowingexampleshowshowtocreateahistogramwith50bucketsonPROD_LIST_PRICE:EXECUTEdbms_stats.gather_table_stats

('sh','products',

method_opt=>'forcolumnssize50

prod_list_price');FullNotesPageViewingHistogramStatisticsSELECTcolumn_name,num_distinct,num_buckets,histogramFROMUSER_TAB_COL_STATISTICSWHEREhistogram<>'NONE';SELECTcolumn_name,num_distinct,num_buckets,histogramFROMUSER_TAB_COL_STATISTICSWHEREcolumn_name='PROD_LIST_PRICE';12HistogramTipsThedefaultoptionforDBMS_STATSMETHOD_OPTSisFORALLCOLUMNSSIZEAUTO,whichenablesautomaticcreationofhistogramsasneeded.Alternatively,youcancreatehistogramsmanually:OnskewedcolumnsthatareusedfrequentlyinWHEREclausesofqueriesOncolumnsthathaveahighlyskeweddatadistributionDonotusehistogramsunlesstheysubstantiallyimproveperformance.Histogramsallocateadditionalstorage.Histograms,likeallotheroptimizerstatistics,arestatic.Recomputethehistogramwhenthedatadistributionofacolumnchangesfrequently.ForquerieswithbindvariablesFullNotesPageBindVariablePeekingTheoptimizerpeeksatthevaluesofbindvariablesonthefirstinvocationofacursor.Thisisdonetodeterminetheselectivityofthepredicate.Peekingdoesnotoccurforsubsequentinvocationsofthecursor.Cursorisshared,basedonthestandardcursor-sharingcriteriaevenfordifferentbindvalues.CascadingtoIndexesTheAutomaticStatisticsGatheringmechanismisconfiguredbydefaulttogatherindexstatisticswhilegatheringstatisticsontheparenttables.YoucanchangethedefaultbehaviorbymodifyingtheCASCADEoptionoftheDBMS_STATSpackage.SettheCASCADEoptionto:TRUEtogatherindexstatisticsDBMS_STATS.AUTO_CASCADEtohavetheOracleDatabasedeterminewhetherindexstatisticsaretobecollectedornotManagingStatisticsCollection:Exampledbms_stats.gather_table_stats('sh'--schema,'customers'--table,null--partition,20--samplesize(%),false--blocksample?,'forallcolumns'--columnspec,4--degreeofparallelism,'default'--granularity,true);--cascadetoindexesdbms_stats.set_param('CASCADE',

'DBMS_STATS.AUTO_CASCADE');dbms_stats.set_param('ESTIMATE_PERCENT','5');dbms_stats.set_param('DEGREE','NULL');WhentoGatherManualStatisticsRelymostlyonautomaticsstatisticscollectionChangefrequencyofautomaticstatisticscollectiontomeetyourneedsGatherstatisticsmanually:ForobjectsthatarevolatileForobjectsmodifiedinbatchoperationsStatisticsGathering:ManualApproachesDynamicsampling:BEGINDBMS_STATS.DELETE_TABLE_STATS('OE','ORDERS');DBMS_STATS.LOCK_TABLE_STATS('OE','ORDERS');END;BEGINDBMS_STATS.GATHER_TABLE_STATS('OE','ORDERS');DBMS_STATS.LOCK_TABLE_STATS('OE','ORDERS');END;Forobjectsmodifiedinbatchoperations:GatherstatisticsaspartofthebatchoperationFornewobjects:GatherstatisticsimmediatelyafterobjectcreationManualstatisticscollection:DynamicSamplingDynamicsamplingisusedtoautomaticallycollectstatisticswhen:ThecostofcollectingthestatisticsisminimalcomparedtotheexecutiontimeThequeryisexecutedmanytimesLockingStatisticsPreventsautomaticgatheringIsusedprimarilyforvolatiletablesLockwithoutstatisticsimpliesdynamicsampling.Lockwithstatisticsisforrepresentativevalues.EXECUTEDBMS_STATS.LOCK_TABLE_STATS('ownername','tablename');EXECUTEDBMS_STATS.LOCK_SCHEMA_STATS('ownername');SELECTstattype_lockedFROMdba_tab_statistics;VerifyingTableStatisticsSELECTlast_analyzedanalyzed,sample_size,

monitoring,table_nameFROMdba_tables

WHEREtable_name='EMPLOYEES';ANALYZEDSAMPLE_SIZEMONTABLE_NAME09-FEB-042000YESEMPLOYEESVerifyingColumnStatisticsSELECTcolumn_name,num_distinct,histogram,

num_buckets,density,last_analyzedanalyzedFROMdba_tab_col_statistics

WHEREtable_name='SALES'

ORDERBYcolumn_name;COLUMN_NAMENUM_DISTINCTHISTOGRAMNUM_BUCKETSDENSITYANALYZED

AMOUNT_SOLD3586NONE1.00027886209-FEB-04CHANNEL_ID4NONE1.2509-FEB-04CUST_ID7059NONE1.00014166309-FEB-04PROD_ID72FREQUENCY725.4416E-0709-FEB-04PROMO_ID4NONE1.2509-FEB-04QUANTITY_SOLD1NONE1109-FEB-04TIME_ID1460NONE1.00068493209-FEB-047rowsselected.VerifyingIndexStatisticsSELECTindex_namename,num_rowsn_r,

last_analyzedl_a,distinct_keys

d_k,leaf_blocksl_b,

avg_leaf_blocks_per_keya_l,join_indexj_IFROMdba_indexes

WHEREtable_name='EMPLOYEES'

ORDERBYindex_name;FullNotesPageHistoryofOptimizerStatisticsGATHER_STATSIMPORT_STATSSET_STATSDBA_TAB_STATS_HISTORYNew

statisticsOld

statisticsDBA_OPTSTATS_OPERATIONS31

daysRESTORE_TABLE_STATSOperation

dateManagingHistoricalOptimizerStatisti

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論