使用优化器性能视图获取SQL语句执行环境
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语句调整,反之整个数据库性能急剧下降也可能是因为实例级别参数设置不当所致。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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.

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.

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.

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.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.
