Oracle数据库统计信息:揭秘统计信息收集和利用,提升查询优化,加速数据检索

发布时间: 2024-08-03 09:40:30 阅读量: 21 订阅数: 15
![Oracle数据库统计信息:揭秘统计信息收集和利用,提升查询优化,加速数据检索](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/observer-enterprise/V4.2.1/manage/histogram.png) # 1. Oracle数据库统计信息概述** 统计信息是Oracle数据库中收集的关于表、索引和列的数据分布和访问模式的信息。这些信息对于查询优化器至关重要,因为它使用这些信息来估计查询执行成本并生成执行计划。 统计信息包括诸如行数、块数、平均行长度、唯一值数和直方图等信息。这些信息可以帮助优化器了解表中数据的分布,并预测访问模式。 维护准确的统计信息对于查询性能至关重要。过时的或不准确的统计信息会导致优化器生成低效的执行计划,从而导致查询性能下降。 # 2. 统计信息收集与维护** **2.1 自动统计收集机制** Oracle数据库提供了自动统计收集机制,在以下情况下自动收集统计信息: * **DDL操作:**创建、修改或删除表、索引、分区或约束时。 * **DML操作:**插入、更新或删除大量数据时。 * **定期任务:**数据库会定期运行自动统计收集作业,默认间隔为7天。 **2.1.1 GATHER_STATS_JOB** 自动统计收集作业由名为GATHER_STATS_JOB的数据库作业执行。该作业使用以下参数: | 参数 | 说明 | |---|---| | METHOD_OPT | 指定统计收集方法,默认值为FOR ALL COLUMNS SIZE AUTO。 | | DEGREE | 指定用于收集统计信息的并行度,默认值为0(串行)。 | | ESTIMATE_PERCENT | 指定收集统计信息的表数据百分比,默认值为100。 | **2.1.2 统计收集方法** 自动统计收集作业可以使用以下方法收集统计信息: * **FOR ALL COLUMNS SIZE AUTO:**为所有列收集精确的统计信息,包括表大小。 * **FOR ALL COLUMNS SIZE SKEWONLY:**为所有列收集精确的统计信息,但仅为偏斜列收集大小统计信息。 * **FOR ALL INDEXED COLUMNS:**仅为索引列收集精确的统计信息。 * **FOR RANGE COLUMNS:**仅为范围列收集精确的统计信息。 **2.2 手动统计收集方法** 除了自动统计收集机制外,还可以使用以下方法手动收集统计信息: * **GATHER_TABLE_STATS:**收集指定表的统计信息。 * **GATHER_INDEX_STATS:**收集指定索引的统计信息。 * **GATHER_DICTIONARY_STATS:**收集字典统计信息,用于优化基于哈希的连接。 **2.2.1 GATHER_TABLE_STATS** ```sql GATHER TABLE_STATS TABLE schema.table_name [METHOD_OPT => FOR ALL COLUMNS SIZE AUTO] [ESTIMATE_PERCENT => 100] [GRANULARITY => ALL] [CASCADE => TRUE]; ``` * **METHOD_OPT:**指定统计收集方法,默认为FOR ALL COLUMNS SIZE AUTO。 * **ESTIMATE_PERCENT:**指定收集统计信息的表数据百分比,默认为100。 * **GRANULARITY:**指定统计收集粒度,默认为ALL(收集所有列的统计信息)。 * **CASCADE:**指定是否级联收集子分区或子表的统计信息,默认为TRUE。 **2.2.2 GATHER_INDEX_STATS** ```sql GATHER INDEX_STATS INDEX schema.index_name [METHOD_OPT => FOR ALL COLUMNS SIZE AUTO] [ESTIMATE_PERCENT => 100]; ``` * **METHOD_OPT:**指定统计收集方法,默认为FOR ALL COLUMNS SIZE AUTO。 * **ESTIMATE_PERCENT:**指定收集统计信息的索引数据百分比,默认为1
corwn 最低0.47元/天 解锁专栏
送3个月
profit 百万级 高质量VIP文章无限畅学
profit 千万级 优质资源任意下载
profit C知道 免费提问 ( 生成式Al产品 )

相关推荐

LI_李波

资深数据库专家
北理工计算机硕士,曾在一家全球领先的互联网巨头公司担任数据库工程师,负责设计、优化和维护公司核心数据库系统,在大规模数据处理和数据库系统架构设计方面颇有造诣。
专栏简介
Oracle数据库架构专栏全面解析了Oracle数据库的内部结构和管理机制,为优化数据库性能提供了宝贵的指导。从数据库存储结构到表空间管理,从索引优化到备份和恢复策略,再到性能优化技巧和安全最佳实践,该专栏深入探讨了Oracle数据库的方方面面。此外,还涵盖了锁机制、并行处理技术、分区表技术、闪回查询、数据字典、统计信息、诊断工具、性能监控和自动化管理等高级主题。通过对这些关键领域的深入理解,数据库管理员和开发人员可以优化数据库性能,确保数据安全,并提高数据库管理效率。

专栏目录

最低0.47元/天 解锁专栏
送3个月
百万级 高质量VIP文章无限畅学
千万级 优质资源任意下载
C知道 免费提问 ( 生成式Al产品 )

最新推荐

Custom Menus and Macro Scripting in SecureCRT

# 1. Introduction to SecureCRT SecureCRT is a powerful terminal emulation software developed by VanDyke Software that is primarily used for remote access, control, and management of network devices. It is widely utilized by network engineers and system administrators, offering a wealth of features

The Application of Numerical Computation in Artificial Intelligence and Machine Learning

# 1. Fundamentals of Numerical Computation ## 1.1 The Concept of Numerical Computation Numerical computation is a computational method that solves mathematical problems using approximate numerical values instead of exact symbolic methods. It involves the use of computer-based numerical approximati

Zotero Data Recovery Guide: Rescuing Lost Literature Data, Avoiding the Hassle of Lost References

# Zotero Data Recovery Guide: Rescuing Lost Literature Data, Avoiding the Hassle of Lost References ## 1. Causes and Preventive Measures for Zotero Data Loss Zotero is a popular literature management tool, yet data loss can still occur. Causes of data loss in Zotero include: - **Hardware Failure:

Notepad Background Color and Theme Settings Tips

# Tips for Background Color and Theme Customization in Notepad ## Introduction - Overview - The importance of Notepad in daily use In our daily work and study, a text editor is an indispensable tool. Notepad, as the built-in text editor of the Windows system, is simple to use and powerful, playing

Implementation of HTTP Compression and Decompression in LabVIEW

# 1. Introduction to HTTP Compression and Decompression Technology 1.1 What is HTTP Compression and Decompression HTTP compression and decompression refer to the techniques of compressing and decompressing data within the HTTP protocol. By compressing the data transmitted over HTTP, the volume of d

PyCharm Python Code Folding Guide: Organizing Code Structure, Enhancing Readability

# PyCharm Python Code Folding Guide: Organizing Code Structure for Enhanced Readability ## 1. Overview of PyCharm Python Code Folding Code folding is a powerful feature in PyCharm that enables developers to hide unnecessary information by folding code blocks, thereby enhancing code readability and

Expanding Database Capabilities: The Ecosystem of Doris Database

# 1. Introduction to Doris Database Doris is an open-source distributed database designed for interactive analytics, renowned for its high performance, availability, and cost-effectiveness. Utilizing an MPP (Massively Parallel Processing) architecture, Doris distributes data across multiple nodes a

PyCharm and Docker Integration: Effortless Management of Docker Containers, Simplified Development

# 1. Introduction to Docker** Docker is an open-source containerization platform that enables developers to package and deploy applications without the need to worry about the underlying infrastructure. **Advantages of Docker:** - **Isolation:** Docker containers are independent sandbox environme

Remote Server Performance Monitoring with MobaXterm

# 1. **Introduction** In this era, remote server performance monitoring has become crucial. Remote server performance monitoring refers to the surveillance of server operational states, resource utilization, and performance via remote connections, aiming to ensure the server's stable and efficient

Application of MATLAB in Environmental Sciences: Case Analysis and Exploration of Optimization Algorithms

# 1. Overview of MATLAB Applications in Environmental Science Environmental science is a discipline that studies the interactions between the natural environment and human activities. MATLAB, as a high-performance numerical computing and visualization software tool, is widely applied in various fie

专栏目录

最低0.47元/天 解锁专栏
送3个月
百万级 高质量VIP文章无限畅学
千万级 优质资源任意下载
C知道 免费提问 ( 生成式Al产品 )