Home Database Mysql Tutorial 使用优化器性能视图获取SQL语句执行环境

使用优化器性能视图获取SQL语句执行环境

Jun 07, 2016 pm 05:29 PM

Oracle SQL语句的运行环境分为多个不同的层次,主要包括实例级别,会话级别,语句级别,其优先级依次递增。即语句级别的执行环境

Oracle SQL语句的运行环境分为多个不同的层次,主要包括实例级别,会话级别,语句级别,其优先级依次递增。即语句级别的执行环境具有最高的优先权,会话级别次之,实例级别最低。反过来,实例级别的环境设置影响全局,而会话级别的则影响当前会话,语句级别的设置当然也就只影响当前语句。由此可知,运行环境中每一个环节的参数都对最终的数据库性能或所执行的SQL语句有直接的影响。因此在对数据库优化或调试SQL时,获得当前SQL语句运行环境显得尤为重要。为此,Oracle提供了三个重要的视图来获取不同级别的参数信息。

一、优化器性能视图名字

--下面的三个性能视图分别对应到不同的级别
scott@ORCL> select table_name from dict where table_name like 'V$%OPTIMIZER_ENV';

TABLE_NAME
------------------------------
V$SYS_OPTIMIZER_ENV
V$SES_OPTIMIZER_ENV
V$SQL_OPTIMIZER_ENV

--注:上述的3个视图实际上是Oracle 10053事件中参数的一个子集

二、实例级别执行环境(视图V$SYS_OPTIMIZER_ENV)

--提供实例级别的环境执行的信息。Oracle 优化器在为SQL语句生成执行计划时,会根据实例级别参数的值来确定,如 optimizer_mode 用于
--确定优化器的模式,optimizer_index_cost_adj用于确定全表扫描与索引扫描之间成本开销的比值等。
--实例级别的参数可以使用下面的方式来设置

alter system set parameter=value scope=memory | both |spfile;

--我们来看看当前实例级别的运行环境

scott@ORCL> select
  2  name,
  3  value,
  4  isdefault
  5  from
  6  v$sys_optimizer_env
  7  order by 3,1;

NAME                              |VALUE          |ISD
-----------------------------------|---------------|---
statistics_level                  |all            |NO    -->非缺省值在此显示为NO
active_instance_count              |1              |YES
bitmap_merge_area_size            |1048576        |YES
cpu_count                          |1              |YES
cursor_sharing                    |exact          |YES
hash_area_size                    |131072        |YES
optimizer_dynamic_sampling        |2              |YES
optimizer_features_enable          |10.2.0.1      |YES
optimizer_index_caching            |0              |YES
optimizer_index_cost_adj          |100            |YES
optimizer_mode                    |all_rows      |YES
optimizer_secure_view_merging      |true          |YES
parallel_ddl_mode                  |enabled        |YES
parallel_dml_mode                  |disabled      |YES
parallel_execution_enabled        |true          |YES
parallel_query_mode                |enabled        |YES
parallel_threads_per_cpu          |2              |YES
pga_aggregate_target              |59392 KB      |YES
query_rewrite_enabled              |true          |YES
query_rewrite_integrity            |enforced      |YES
skip_unusable_indexes              |true          |YES
sort_area_retained_size            |0              |YES
sort_area_size                    |65536          |YES
star_transformation_enabled        |false          |YES
workarea_size_policy              |auto          |YES

--从上面的查询结果可知,当前系统中仅有statistics_level参数使用了非缺省值,statistics_level参数的缺省值为typical,而此处为all。
--对于实例级别任意参数的修改其影响都是全局的,,因此应当慎重。当然,如果某个参数设置的不合理,其影响也是全局的,因此对于实例级别
--参数的合理设置,可以避免成百上千枯燥的SQL语句调整,反之整个数据库性能急剧下降也可能是因为实例级别参数设置不当所致。

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

See all articles