Oracle数据库中有一个表,用PL/SQL查看该表的索引没有被DROP掉, 但是表上的数据查询起来很慢(查询时间大概是原来的3倍),后
Oracle数据库中有一个表,用PL/SQL查看该表的索引没有被DROP掉,, 但是表上的数据查询起来很慢(查询时间大概是原来的3倍),后来重建了一下索引就好了, 请问这是为什么, 在什么情况下会出现类似的索引丢失的情况?
可能是你的表经常被更新,碎片太多,索引占用空间太大,优化器觉得没有必要用索引了就直接全表扫描了啊,你重新建立索引,就整理了碎片了啊,当然就又用索引了.
索引失效的情况很多,比如左边使用了函数 ,表没有分析 ,导致索引扫描的cost高于全表扫描,表很小 ,等等。需要具体分析。你可以根据执行计划来判断.
以下情况会导致索引失效:
1) 直接导入:
imp with SKIP_UNUSABLE_INDEXES=Y
or sqlldr with SKIP_INDEX_MAINTENANCE
2) 在索引维护过程中出现ORA-1652/1653错误:
sqlldr DIRECT=Y failes with ORA-1652 or 1653
3) 分区维护导致ROWID发生改变:
ALTER TABLE MOVE PARTITION
ALTER TABLE TRUNCATE PARTITION
ALTER TABLE SPLIT PARTITION
索引失效问题解决方法:
1)导致的原因:
在SQL*LOADER 加载过程中会维护索引,由于数据量比较大,在SQL*LOADER 加载过程中出现异常情况,导致ORACLE 来不及维护索引,导致索引处于失效状态,影响查询和加载。
异常情况主要有:在加载过程中杀掉SQL*LOADER 进程,重启,表空间不够等。
2)解决方法:
重建索引
3)如何重建索引
a) 查看索引类型
select t1.index_name,t1.partitioned from Dba_Indexes t1
where t1.Table_Name=upper('CCB_COGNOS_PROD_BALANCE_AA')
索引名称 是否分区索引
GNOS_PROD_BALANCE_AA_N1 NO
b)非分区索引
重建索引:alter index cin.CCB_COGNOS_PROD_BALANCE_AA_N1 rebuild Nologging
c)分区索引
找出失效的分区索引:
select t.Index_Name, t.Partition_Name, t.Tablespace_Name, t.Status
from Dba_Ind_Partitions t
where t.Index_Name = 'CMZ_LOCAL_IDX_2'
重建所有状态为unusable的索引
ALTER INDEX 索引名
REBUILD PARTITION 分区名
TABLESPACE 表空间名
NOLOGGING
ORACLE索引失效解决方案
最近碰到这样一个问题:在PROD_PARTS表中新添加了一个索引:
create index IDX_PT_DV_ID on PROD_PARTS (DEVICE_ID);
但是在使用DEVICE_ID字段进行查询时,发现该索引并没有被利用到:
SELECT * FROM PROD_PARTS WHERE device_id =122511619;
执行计划:
TABLE ACCESS FULL
之后请教DBA后,发现是数据统计的问题,具体的解决办法是执行下面的语句:
analyze table PROD_PARTS compute statistics;
ANALYZE TABLE PROD_PARTS COMPUTE STATISTICS FOR ALL INDEXED COLUMNS;
analyze table PROD_PARTS compute statistics for table for all indexes for all indexed columns;

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

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

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.