版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年装箱单在应对外贸出口贸易救济措施中的策略合同3篇
- 二零二五版国际贸易特许经营合同主体欺诈风险管理与合同解除合同3篇
- 二零二五年电子显示屏广告租赁合同样本3篇
- 二零二五版代办房地产前期开发手续与建筑工程质量检测服务合同3篇
- 二零二五年采棉机驾驶员职业素养提升与劳动合同3篇
- 二零二五版能源行业冻库租赁合同含能源物资储备协议3篇
- 二零二五年酒店客房部服务员劳动合同书3篇
- 天津事业单位2025年度合同制聘用人员管理规范3篇
- 二零二五年度装修合同范本:环保装修保障您的生活品质6篇
- 二零二五版地产经纪居间合同纠纷处理指南3篇
- 【公开课】同一直线上二力的合成+课件+2024-2025学年+人教版(2024)初中物理八年级下册+
- 高职组全国职业院校技能大赛(婴幼儿照护赛项)备赛试题库(含答案)
- 2024年公安部直属事业单位招聘笔试参考题库附带答案详解
- 健康教育工作考核记录表
- 装饰工程施工技术ppt课件(完整版)
- SJG 05-2020 基坑支护技术标准-高清现行
- 汽车维修价格表
- 司炉岗位应急处置卡(燃气)参考
- 10KV供配电工程施工组织设计
- 终端拦截攻略
- 药物外渗处理及预防【病房护士安全警示教育培训课件】--ppt课件
评论
0/150
提交评论