Managing Statistics part1

本文介绍如何使用Oracle的DBMS_STATS包来收集表、索引及整个数据库的统计信息,这些统计信息有助于查询优化器选择最佳执行计划。文章还讨论了在不同场景下更新统计信息的最佳实践。
Managing Statistics


Understanding Statistics
Optimizer statistics are a collection of data that describe more details about the database and the objects in the database.These statistics are used by the query optimizer to choose the best excution plan for each SQL statement.Optimizer statistics include following:
*Table statistics
-Number of rows
-Number of blocks
-Average row length
*Column statistics
-Number of distinct values(NDV)in column
-Number of nulls in column
-Data distribution(histogram)数据分布直方图
-Extended statistics
*Index statistics
-Number of leaf blocks
-Levels
-Clustering factor
*System statistics(相对其他比较容易变化)
-I/O performance and utilization
-CPU performance and utilization


When statistics are updated for a database object,Oracle invalidates(使无效) any currently parsed(已解析) SQL statements that access the object.The next time such a statement executes,the statement is re-parsed and the optimizer automatically chooses a new execution plan based on the new statistics.Distributed statements accessing objects with new statistics on remote database are not invalidated.The new statistics take effect the next time the SQL statement is parsed.


Managing Statistics
Use the dbms_stats package:
gather_table_stats收集某个表的统计信息
gather_index_stats
gather_schema_stats
gather_database_stats
gather_stale_stats收集不新鲜的统计信息


实验一:收集表的统计信息
1.创建一个表t,插入几条记录
2.desc dba_tables
3.select num_rows,blocks from dba_tables owner='HR' and tablename='T';发现没有显示统计信息,因为刚创建完这个表,还没收集统计信息。
4.exec dbms_stats.gather_table_stats('HR','T');收集统计信息
5.再执行第三步,就有统计信息放在dba_tables这个数据字典里了。


When to Gather Statistics
When gathering statistics manually,you not only need to determine how to gather statistics,but also when and how often to gather new statistics.
手动收集信息,需要自己决定何时收集,怎么收集等信息。
For an appliation in which tables are being incrementally modified,you may only need to gather new statistics every week or every month.The simplest way to gather statistics in these enviroment is to use a script or job scheduling tool to regularly run the GATHER_SCHEMA_STATS and GATHER_DATABASE_STATS procedures.The frequency of collection intervals should balance the task of providing accurate statistics for the optimizer against the processing overhead incurred by the statistics collection process.
对于增量的修改,例如对一个几万行的数据,有几十行的增加,你只需要定期用一个脚本或者过程收集新的统计信息,太频繁执行虽然会带来最新的统计信息,但是也会有一定的额外负载,需要权衡这个收集的频率。


For tables which are being substantially modified in batch operations,such as with bulk loads,statistics should be gathered on those tables as part of the batch operation.The DBMS_STATS procedure should be called as soon as the load operation completes.
对于大规模的数据修改,例如批量导入,那在每次这种大批量操作后都应该收集一次统计信息。


For partitioned tables,there are often cases in which only a single partition is modified.In those cases,statistics can be gathered only on those partitions rather than gathering statistics for the entire table.Howerver,gathering global statistics for the partitioned table may still be necessary.
对于分区表,有时候只需要收集改动了的那个分区的统计信息,而不用所有分区都去收集。有时候表的全局的统计信息也是很重要的。














REST API 属性 使用下面的表单启用或禁用REST API并配置身份验证。 REST API 属性已成功编辑。 REST API REST API 可以使用下面定义的共享密钥进行安全保护 或者使用 HTTP 基本身份验证。 此外,为了增加额外的安全性,您可以指定允许使用此服务的 IP 地址列表。 空列表意味着该服务可以从任何位置访问。地址之间用逗号分隔。 已启用 - REST API请求将被处理。 禁用 - REST API请求将被忽略。 HTTP基本认证 - 通过Openfire管理员账户进行REST API认证。 密钥认证 - 通过指定的密钥进行 REST API 认证。 秘密密钥: YkhTa0ePxkFSDHWr 自定义认证过滤器类名 - REST API 认证委托给某个其他插件中实现的自定义过滤器。 注意:在自定义认证过滤器之间来回切换会强制重新加载 REST API 插件 过滤器 类名: 允许的IP地址: 124.71.230.244 附加日志记录 已启用 - 日志记录已启用 已禁用 - 日志记录已禁用 您可以在此找到关于Openfire REST API的详细文档: REST API文档(在新标签页中打开)Swagger UI http://124.71.230.244:9090/plugins/restapi/v1/openapi.yaml Explore Openfire REST API 1.8.0 OAS3 http://124.71.230.244:9090/plugins/restapi/v1/openapi.yaml This is the documentation for a REST API of the Openfire Real-time communication server. Ignite Realtime Foundation - Website Apache 2.0 Servers /plugins Authorize Clustering Reporting the status of Openfire clustering GET /restapi/v1/clustering/nodes/{nodeId} Get a specific cluster node GET /restapi/v1/clustering/nodes Get all cluster nodes GET /restapi/v1/clustering/status Get clustering status User Group Managing Openfire user groupings. GET /restapi/v1/groups Get groups POST /restapi/v1/groups Create group GET /restapi/v1/groups/{groupName} Get group PUT /restapi/v1/groups/{groupName} Update group DELETE /restapi/v1/groups/{groupName} Delete group Chat room Managing Multi-User chat rooms. POST /restapi/v1/chatrooms/{roomName}/admins/{jid} Add room admin DELETE /restapi/v1/chatrooms/{roomName}/admins/{jid} Remove room admin POST /restapi/v1/chatrooms/{roomName}/admins/group/{groupname} Add room admins DELETE /restapi/v1/chatrooms/{roomName}/admins/group/{groupname} Remove room admins POST /restapi/v1/chatrooms/{roomName}/members/{jid} Add room member DELETE /restapi/v1/chatrooms/{roomName}/members/{jid} Remove room member POST /restapi/v1/chatrooms/{roomName}/members/group/{groupname} Add room members DELETE /restapi/v1/chatrooms/{roomName}/members/group/{groupname} Remove room members POST /restapi/v1/chatrooms/{roomName}/outcasts/{jid} Add room outcast DELETE /restapi/v1/chatrooms/{roomName}/outcasts/{jid} Remove room outcast POST /restapi/v1/chatrooms/{roomName}/outcasts/group/{groupname} Add room outcasts DELETE /restapi/v1/chatrooms/{roomName}/outcasts/group/{groupname} Remove room outcasts POST /restapi/v1/chatrooms/{roomName}/owners/{jid} Add room owner DELETE /restapi/v1/chatrooms/{roomName}/owners/{jid} Remove room owner POST /restapi/v1/chatrooms/{roomName}/owners/group/{groupname} Add room owners DELETE /restapi/v1/chatrooms/{roomName}/owners/group/{groupname} Remove room owners GET /restapi/v1/chatrooms Get chat rooms POST /restapi/v1/chatrooms Create chat room GET /restapi/v1/chatrooms/{roomName} Get chat room PUT /restapi/v1/chatrooms/{roomName} Update chat room DELETE /restapi/v1/chatrooms/{roomName} Delete chat room GET /restapi/v1/chatrooms/{roomName}/chathistory Get room history GET /restapi/v1/chatrooms/{roomName}/occupants Get room occupants GET /restapi/v1/chatrooms/{roomName}/participants Get room participants POST /restapi/v1/chatrooms/{roomName}/invite/{jid} Invite user Message Sending (chat) messages to users. POST /restapi/v1/messages/users Broadcast Message Archive Server-sided storage of chat messages. GET /restapi/v1/archive/messages/unread/{jid} Unread message count Security Audit Log Inspecting the security audit log. GET /restapi/v1/logs/security Get log entries Client Sessions Managing live client sessions. GET /restapi/v1/sessions Get all sessions GET /restapi/v1/sessions/{username} Get user sessions DELETE /restapi/v1/sessions/{username} Kick user sessions Statistics Inspecting Openfire statistics. GET /restapi/v1/system/statistics/sessions Get client session counts System Managing Openfire system configuration GET /restapi/v1/system/properties Get system properties POST /restapi/v1/system/properties Create system property GET /restapi/v1/system/properties/{propertyKey} Get system property PUT /restapi/v1/system/properties/{propertyKey} Update system property DELETE /restapi/v1/system/properties/{propertyKey} Remove system property GET /restapi/v1/system/liveness Perform all liveness checks GET /restapi/v1/system/liveness/deadlock Perform 'deadlock' liveness check. GET /restapi/v1/system/liveness/properties Perform 'properties' liveness check. GET /restapi/v1/system/readiness Perform all readiness checks GET /restapi/v1/system/readiness/cluster Perform 'cluster' readiness check GET /restapi/v1/system/readiness/connections Perform 'connections' readiness check GET /restapi/v1/system/readiness/plugins Perform 'plugins' readiness check GET /restapi/v1/system/readiness/server Perform 'server started' readiness check Users Managing Openfire users. POST /restapi/v1/users/{username}/groups/{groupName} Add user to group DELETE /restapi/v1/users/{username}/groups/{groupName} Delete user from group GET /restapi/v1/users/{username}/groups Get user's groups POST /restapi/v1/users/{username}/groups Add user to groups DELETE /restapi/v1/users/{username}/groups Delete user from groups POST /restapi/v1/lockouts/{username} Lock user out DELETE /restapi/v1/lockouts/{username} Unlock user GET /restapi/v1/users/{username}/roster Retrieve user roster POST /restapi/v1/users/{username}/roster Create roster entry PUT /restapi/v1/users/{username}/roster/{rosterJid} Update roster entry DELETE /restapi/v1/users/{username}/roster/{rosterJid} Remove roster entry GET /restapi/v1/users Get users POST /restapi/v1/users Create user GET /restapi/v1/users/{username} Get user PUT /restapi/v1/users/{username} Update user DELETE /restapi/v1/users/{username} Delete user UserService (deprecated) Undocumented UserService endpoint, retained for backwards compatibility. GET /restapi/v1/userservice POST /restapi/v1/userservice default GET /application.wadl/{path} GET /application.wadl Schemas ClusterNodeEntity ClusterNodeEntities ClusteringEntity GroupEntity GroupEntities MUCRoomEntity MUCRoomMessageEntities MUCRoomMessageEntity OccupantEntities OccupantEntity ParticipantEntities ParticipantEntity MUCRoomEntities MUCInvitationEntity MessageEntity MsgArchiveEntity SecurityAuditLog SecurityAuditLogs SessionEntities SessionEntity SessionsCount SystemProperty SystemProperties UserGroupsEntity RosterItemEntity RosterEntities UserEntity UserProperty UserEntities Error
10-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值