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_NAME | INDEX_TYPE | STATUS | TABLE_NAME |
| <INDEX_NAME>_PK | NORMAL | UNUSABLE | <TABLE_NAME1> |
| <INDEX_NAME>_PK | NORMAL | VALID | <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.
相关推荐
java_logo29 分钟前
Docker 部署 FalkorDB:轻松搭建属性图数据库与知识图谱平台
数据库·docker·知识图谱·falkordb·轩辕镜像·falkordb部署教程·falkordb部署文档
小白说大模型1 小时前
Spring AI 框架中集成 MCP 的完整指南:从服务端到客户端的全流程实践
大数据·数据库·人工智能·安全·spring·chatgpt·开源
计算机魔术师1 小时前
第二届世界人形机器人运动会开幕:2056 台机器人齐聚“冰丝带“,666 支队伍竞技 51 赛项
数据库·人工智能·机器人
@insist1231 小时前
系统集成项目管理工程师-配置管理角色与活动
数据库·软考·系统集成项目管理工程师·软考中项·软件水平考试
巨大八爪鱼2 小时前
XP系统运行IoTDB 2.0.10数据库服务器
数据库·iotdb·xp
卓怡学长2 小时前
w181springboot机场乘客服务系统
java·数据库·spring boot·spring·intellij-idea
阮胜昌2 小时前
MySQL 9.7.0 LTS 现已发布:扩展了社区功能,并为企业级应用增加了动态数据脱敏功能
数据库·mysql
晓子文集2 小时前
Tushare接口文档:每日涨跌停价格(stk_limit)
大数据·数据库·金融数据·量化投资
l1t3 小时前
测试DuckDB luajit插件读取本地通达信文件
开发语言·数据库·duckdb