如何可靠地列出和删除 Oracle 中的所有空间索引?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4545190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:17:59  来源:igfitidea点击:

How to reliably list and drop all spatial indexes in Oracle?

sqldatabaseoracleoracle-xeoracle-spatial

提问by Axel Fontaine

In my open-source database migration project Flyway, I have a feature that cleans all objects in the current database schema, without dropping the schema itself.

在我的开源数据库迁移项目Flyway 中,我有一个功能可以清除当前数据库架构中的所有对象,而不会删除架构本身。

The typical implementation works as follows:

典型的实现工作如下:

  • List all objects
  • Generate drop statements for these objects
  • 列出所有对象
  • 为这些对象生成 drop 语句

Oracle Spatial Indexeshave been causing me a lot of grief though.

不过,Oracle Spatial Indexes一直让我很伤心。

How can I reliably enumeratethem in order to produce DROP INDEX xyz statements?

如何可靠地枚举它们以生成 DROP INDEX xyz 语句?

Note: This must work on both XE, 10g and 11g. All references in the MDSYS schema must be gone.

注意:这必须适用于XE、10g 和 11g。MDSYS 模式中的所有引用都必须消失。

My current solution looks like this:

我目前的解决方案是这样的:

On XE:

在 XE 上:

  • DELETE FROM mdsys.user_sdo_geom_metadata
  • DELETE FROM mdsys.sdo_index_metadata_table WHERE sdo_index_owner = USER
  • SELECT object_type, object_name FROM user_objects WHERE object_type = 'TABLE'
  • DROP *table_name* CASCADE CONSTRAINTS PURGE /* for all tables */
  • 从 mdsys.user_sdo_geom_metadata 中删除
  • 从 mdsys.sdo_index_metadata_table 中删除 sdo_index_owner = USER
  • SELECT object_type, object_name FROM user_objects WHERE object_type = 'TABLE'
  • DROP *table_name* CASCADE CONSTRAINTS PURGE /* 对于所有表 */

On Oracle 10g:

在 Oracle 10g 上:

  • DELETE FROM mdsys.user_sdo_geom_metadata
  • SELECT object_type, object_name FROM user_objects WHERE object_type = 'TABLE' and object_name not like 'MDRT_%$'
  • DROP *table_name* CASCADE CONSTRAINTS PURGE /* for all tables */
  • 从 mdsys.user_sdo_geom_metadata 中删除
  • SELECT object_type, object_name FROM user_objects WHERE object_type = 'TABLE' and object_name not like 'MDRT_%$'
  • DROP *table_name* CASCADE CONSTRAINTS PURGE /* 对于所有表 */

10g seems to cascade the removal of the metadata in MDSYS.sdo_index_metadata_table and the removal of the spatial index tables (MDRT_1234$ and the like).

10g 似乎级联删除 MDSYS.sdo_index_metadata_table 中的元数据和删除空间索引表(MDRT_1234$ 等)。

XE doesn't.

XE 没有。

Both 10g and XE don't cascade the removal of the metadata in MDSYS.user_sdo_geom_metadata

10g 和 XE 都不会级联删除 MDSYS.user_sdo_geom_metadata 中的元数据

采纳答案by Axel Fontaine

I solved it by enumerating all SPATIAL indexes using

我通过使用枚举所有空间索引来解决它

select INDEX_NAME from USER_SDO_INDEX_INFO

And using INDEX_NAME to generate DROP statements like

并使用 INDEX_NAME 生成 DROP 语句,例如

DROP INDEX my_index

回答by Matt

on 10g, try the xxx_SDO_INDEX_yyyviews or alternatively look for objects with type SPATIAL_INDEX. You could drop each of these first then drop the table. I don't know whether these exist on XE or not.

在 10g 上,尝试xxx_SDO_INDEX_yyy视图或查找类型为 的对象SPATIAL_INDEX。您可以先删除其中的每一个,然后再删除表。我不知道这些是否存在于 XE 上。