SQL load direct path load index 无效的原因

2024-04-20 14:44

本文主要是介绍SQL load direct path load index 无效的原因,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Index (unique) state changing to unusable status after data loading using SQL*Loader. The steps below are executed to load the data:

1/ disable constraint--如果不是单独建的index, 对应index会drop掉的
2/ load data using SQL*Loader
3/ remove duplicate records
4/ enable constraint

The execution of step 3 fails due to an index in unusable state:

\n removing duplicate records from the table ... \n
DELETE FROM <TABLE_NAME1> WHERE rowid not in (SELECT MIN(rowid) FROM <TABLE_NAME1> GROUP BY <COLUMN_NAME>)---rowid在期间不能有table move 操作
*
ERROR at line 1:
ORA-01502: index '<INDEX_NAME>_PK' or partition of such index is
in unusable state

Checking the available indexes and their status from dba_indexes, we have:

INDEX_NAMEINDEX_TYPESTATUSTABLE_NAME
<INDEX_NAME>_PKNORMALUNUSABLE<TABLE_NAME1>
<INDEX_NAME>_PKNORMALVALID<TABLE_NAME2>

CHANGES

CAUSE

Some integrity constraints are automatically disabled During a direct path load. The constraints that remain enabled during a direct path load are:

- NOT NULL
- UNIQUE
- PRIMARY KEY (unique-constraints on not-null columns)--PK自动not null

这么说不就是外键 check disable了


- NOT NULL constraints are checked at column array build time. Any row that violates the NOT NULL constraint is rejected.

Even though UNIQUE constraints remain enabled during direct path loads, any row that violates those constraints is loaded anyway (this is different than in conventional path in which such rows would be rejected).
When indexes are rebuilt at the end of the direct path load, UNIQUE constraints are verified and if a violation is detected, then the index will be left in an unusable state.

不拒绝

Indexes Left in an Unusable State
------------------------------------------------
SQL*Loader leaves indexes in an Index Unusable state when the data segment being loaded becomes more up-to-date than the index segments that index it.
Any SQL statement that tries to use an index that is in an Index Unusable state returns an error. The following conditions cause a direct path load to leave an index or a partition of a partitioned index in an Index Unusable state:

  - SQL*Loader runs out of space for the index and cannot update the index.
  - The data is not in the order specified by the SORTED INDEXES clause.
  - There is an instance failure, or the Oracle shadow process fails while building the index.
  - There are duplicate keys in a unique index.
  - Data savepoints are being used, and the load fails or is terminated by a keyboard interrupt after a data savepoint occurred.

Hence this is a expected behavior as:

- Some duplicate rows are getting loaded and indexes are going to unusable state when unique indexes are used.
  - Or -
- SQL*Loader leaves indexes in an Index Unusable state when the data segment being loaded becomes more up-to-date than the index segments that index it.
 

SOLUTION

To overcome the issue:

  • In few cases using conventional path load has resolved the issue.

          - Or -

  • Using normal index instead of unique index will not affect the index status.
  • 先建立普通index 加unique key 控制

          - Or -

  • One can follow below workaround for unique indexes.
  • 本来是个死局,重复的删不了,index不能rebuild,只有drop,

    - Drop the offending index and load the data.
    - Detect duplicate rows
    - Remove the duplicate rows and recreate the index.

这篇关于SQL load direct path load index 无效的原因的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/920543

相关文章

SQL注入漏洞扫描之sqlmap详解

《SQL注入漏洞扫描之sqlmap详解》SQLMap是一款自动执行SQL注入的审计工具,支持多种SQL注入技术,包括布尔型盲注、时间型盲注、报错型注入、联合查询注入和堆叠查询注入... 目录what支持类型how---less-1为例1.检测网站是否存在sql注入漏洞的注入点2.列举可用数据库3.列举数据库

Mysql虚拟列的使用场景

《Mysql虚拟列的使用场景》MySQL虚拟列是一种在查询时动态生成的特殊列,它不占用存储空间,可以提高查询效率和数据处理便利性,本文给大家介绍Mysql虚拟列的相关知识,感兴趣的朋友一起看看吧... 目录1. 介绍mysql虚拟列1.1 定义和作用1.2 虚拟列与普通列的区别2. MySQL虚拟列的类型2

mysql数据库分区的使用

《mysql数据库分区的使用》MySQL分区技术通过将大表分割成多个较小片段,提高查询性能、管理效率和数据存储效率,本文就来介绍一下mysql数据库分区的使用,感兴趣的可以了解一下... 目录【一】分区的基本概念【1】物理存储与逻辑分割【2】查询性能提升【3】数据管理与维护【4】扩展性与并行处理【二】分区的

MySQL中时区参数time_zone解读

《MySQL中时区参数time_zone解读》MySQL时区参数time_zone用于控制系统函数和字段的DEFAULTCURRENT_TIMESTAMP属性,修改时区可能会影响timestamp类型... 目录前言1.时区参数影响2.如何设置3.字段类型选择总结前言mysql 时区参数 time_zon

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

使用SQL语言查询多个Excel表格的操作方法

《使用SQL语言查询多个Excel表格的操作方法》本文介绍了如何使用SQL语言查询多个Excel表格,通过将所有Excel表格放入一个.xlsx文件中,并使用pandas和pandasql库进行读取和... 目录如何用SQL语言查询多个Excel表格如何使用sql查询excel内容1. 简介2. 实现思路3

Mysql DATETIME 毫秒坑的解决

《MysqlDATETIME毫秒坑的解决》本文主要介绍了MysqlDATETIME毫秒坑的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着... 今天写代码突发一个诡异的 bug,代码逻辑大概如下。1. 新增退款单记录boolean save = s

python中os.stat().st_size、os.path.getsize()获取文件大小

《python中os.stat().st_size、os.path.getsize()获取文件大小》本文介绍了使用os.stat()和os.path.getsize()函数获取文件大小,文中通过示例代... 目录一、os.stat().st_size二、os.path.getsize()三、函数封装一、os

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d

MySQL中的锁和MVCC机制解读

《MySQL中的锁和MVCC机制解读》MySQL事务、锁和MVCC机制是确保数据库操作原子性、一致性和隔离性的关键,事务必须遵循ACID原则,锁的类型包括表级锁、行级锁和意向锁,MVCC通过非锁定读和... 目录mysql的锁和MVCC机制事务的概念与ACID特性锁的类型及其工作机制锁的粒度与性能影响多版本