索引监控 在某个OLTP系统中某张表上建立了10个索引,由于不确定索引是否有在各程序中被使用,不能随意删除,因此,需要监控已有的索引是否在使用, 官方文档描述: Monitoring Index Usage Oracle Database provides a means of monitoring indexes to deter
索引监控
在某个OLTP系统中某张表上建立了10个索引,由于不确定索引是否有在各程序中被使用,不能随意删除,因此,需要监控已有的索引是否在使用,
官方文档描述:
Monitoring Index Usage
Oracle Database provides a means of monitoring indexes to determine whether they are being used. If an index is not being used, then it can be dropped, eliminating unnecessary statement overhead.
To start monitoring the usage of an index, issue this statement:
ALTER INDEX index MONITORING USAGE; //开启索引监控
Later, issue the following statement to stop the monitoring:
ALTER INDEX index NOMONITORING USAGE; //关闭索引监控
The view V$OBJECT_USAGE can be queried for the index being monitored to see if the index has been used. The view contains a USED column whose value is YES or NO, depending upon if the index has been used within the time period being monitored. The view also contains the start and stop times of the monitoring period, and a MONITORING column (YES/NO) to indicate if usage monitoring is currently active.
Each time that you specify MONITORING USAGE, the V$OBJECT_USAGE view is reset for the specified index. The previous usage information is cleared or reset, and a new start time is recorded. When you specify NOMONITORING USAGE, no further monitoring is performed, and the end time is recorded for the monitoring period. Until the next ALTER INDEX...MONITORING USAGE statement is issued, the view information is left unchanged.
开启索引监控后,可以从v$object_usage中查询到数据(即使索引还没有被使用),START_MONITORING 字段会写入开始监控的时间;当某条SQL使用了相关的索引以后,其“USED”字段就会更新为’YES‘。监控索引结束后最好关闭监控,以提高效率。
注意:v$object_usage 要去每个USERS 中查询,即使用SYS权限开启的其他USER索引的监控,也无法从SYS用户的V$OBJECT_USAGE 中插到相关的记录。 下面有验证
实验: 测试一个索引
[oracle@tyger ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Mar 28 16:19:01 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@ORCL>create user tyger identified by tyger; // 创建测试用户 tyger
User created.
SYS@ORCL>grant connect,resource to tyger; // 赋予tyger connect,resource 权限
Grant succeeded.
SYS@ORCL>grant select on dba_objects to tyger; // 授予 dba_objects 查询权限给 tyger
Grant succeeded.
SYS@ORCL>conn tyger/tyger
Connected.
TYGER@ORCL>create table test_monitor as select * from dba_objects; // 创建测试表
Table created.
TYGER@ORCL>select * from user_indexes; // 查看当前用户下的索引
no rows selected
TYGER@ORCL>create index test_monitor_idx on test_monitor(object_id); // 基于 object_id 字段创建索引
Index created.
TYGER@ORCL>col INDEX_NAME for a20
TYGER@ORCL>col TABLE_NAME for a20
TYGER@ORCL>col TABLE_OWNER for a20
TYGER@ORCL>l
1 select index_name,table_name,table_owner
2* from user_indexes
TYGER@ORCL>/ // 查看当前用户下的索引
INDEX_NAME TABLE_NAME TABLE_OWNER
-------------------- -------------------- --------------------
TEST_MONITOR_IDX TEST_MONITOR TYGER
TYGER@ORCL>
TYGER@ORCL>alter index TEST_MONITOR_IDX monitoring usage; // 开启索引监控
Index altered.
TYGER@ORCL>select * from v$object_usage; // 查看视图 object_usage 索引监控和使用情况
INDEX_NAME TABLE_NAME MON USE START_MONITORING
-------------------- -------------------- --- --- -------------------
END_MONITORING
-------------------
TEST_MONITOR_IDX TEST_MONITOR YES NO 03/28/2014 16:22:46 // MONITORING 为 'YES' 代表已经监控
// USAGE 为 ’NO‘ 代表索引未被使用
TYGER@ORCL>conn / as sysdba
Connected.
SYS@ORCL>
SYS@ORCL>select * from v$object_usage; // 无法从SYS用户的V$OBJECT_USAGE 中插到相关的记录
no rows selected
TYGER@ORCL>set autotrace on // 开启自动跟踪
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled // 出现这个错误,暂时可以略过,不影响接下来的实验
SP2-0611: Error enabling STATISTICS report
TYGER@ORCL>select * from TEST_MONITOR where object_id=111;
OWNER
------------------------------
OBJECT_NAME
--------------------------------------------------------------------------------
SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE
------------------------------ ---------- -------------- -------------------
CREATED LAST_DDL_ TIMESTAMP STATUS T G S
--------- --------- ------------------- ------- - - -
SYS
I_ARGUMENT1
111 111 INDEX
30-JUN-05 30-JUN-05 2005-06-30:19:10:18 VALID N N N
Execution Plan
----------------------------------------------------------
Plan hash value: 2240611133
--------------------------------------------------------------------------------
----------------
| Id | Operation | Name | Rows | Bytes | Cost (%
CPU)| Time |
--------------------------------------------------------------------------------
----------------
| 0 | SELECT STATEMENT | | 1 | 177 | 2
(0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST_MONITOR | 1 | 177 | 2
(0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TEST_MONITOR_IDX | 1 | | 1 // 上面执行的语句 走的是索引 TEST_MONITOR_IDX
(0)| 00:00:01 |
--------------------------------------------------------------------------------
----------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=111)
Note
-----
- dynamic sampling used for this statement
TYGER@ORCL>select * from v$object_usage;
INDEX_NAME TABLE_NAME MON USE START_MONITORING
-------------------- -------------------- --- --- -------------------
END_MONITORING
-------------------
TEST_MONITOR_IDX TEST_MONITOR YES YES 03/28/2014 16:22:46 // MONITORING 为 'YES' 代表已经监控
// USAGE 为 ’YES‘ 代表索引已经被使用
Execution Plan
----------------------------------------------------------
ERROR:
ORA-01039: insufficient privileges on underlying objects of the view
SP2-0612: Error generating AUTOTRACE EXPLAIN report
TYGER@ORCL>set autotrace off;
TYGER@ORCL>

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment