Oracle数据库索引失效
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;

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

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
