Oracle英文版培训课件之SQL Tuning:Les07-RW_第1页
Oracle英文版培训课件之SQL Tuning:Les07-RW_第2页
Oracle英文版培训课件之SQL Tuning:Les07-RW_第3页
Oracle英文版培训课件之SQL Tuning:Les07-RW_第4页
Oracle英文版培训课件之SQL Tuning:Les07-RW_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论