简体   繁体   English

重新创建用于批量加载的非唯一索引

[英]Recreate nonunique index for bulk load

I have simple table with foreign key (for single column) and nonunique index for column involved in a FK . 我有一个简单的表,带有foreign key (对于单列),对于FK涉及的列具有nonunique index I disable FK before bulk load (before bulk load I truncate table), and enable it after. 我在大bulk load之前禁用FK (在大容量加载之前我truncate表),然后在启用它。 I know that in Oracle when you disable a UNIQUE or PRIMARY KEY constraint an associated index is dropped. 我知道在Oracle中,当您禁用UNIQUEPRIMARY KEY constraint将删除关联的索引。 And when you enable a UNIQUE or PRIMARY KEY constraint an associated index is created. 并且当启用UNIQUEPRIMARY KEY约束时,将创建关联的索引。 But what about disabling/enabling FK ? 但是禁用/启用FK呢? Should I manually drop nonunique index for FK before bulk load and also manually create nonunique index after? 我应该在批量加载之前手动删除FK nonunique index ,然后在之后手动创建nonunique index吗? Or I can keep that index (I mean would this index be valid if I kept him)? 或者我可以保留该索引(我的意思是,如果保留他,该索引将有效)?

You need to first disable the INDEX 您需要先禁用INDEX

ALTER INDEX idx_fk_column UNUSABLE;

then after your DML operations re-build it. 然后在您的DML操作之后重新构建它。

ALTER INDEX idx_fk_column REBUILD;

If you keep the index it is still valid. 如果保留索引,它仍然有效。 But it may be an overhead during the load. 但这可能是加载期间的开销。 So, some sites prefer to disable (using UNUSABLE) and reenable (using REBUILD) such non-unique indexes (Note : If it is a Unique index, setting UNUSABLE would prevent INSERTs, so you'd have to actually DROP and CREATE). 因此,某些站点倾向于禁用(使用UNUSABLE)并重新启用(使用REBUILD)这样的非唯一索引(注意:如果它是唯一索引,则设置UNUSABLE会阻止INSERT,因此您实际上必须DROP和CREATE)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM