The syntax for creating a spatial index in OceanBase Database is different from that in Oracle. The SRID of a spatial index column is specified when the table is created.
Notice
OceanBase Database is not compatible with Oracle in creating spatial indexes. In Oracle, you must manually maintain the mapping between spatial index columns and index information in the `USER_SDO_GEOM_METADATA` system table. However, OceanBase Database uses the MySQL style to be compatible with Oracle-compatible mode and does not maintain the `USER_SDO_GEOM_METADATA` table. Therefore, the syntax is different from that in Oracle.
Considerations
- When you create a spatial index, you must specify the SRID.
- For partitioned tables, you can create only local partition indexes (you must explicitly specify the
LOCALkeyword). Global partition indexes are not supported.
Prerequisites
Before you use the GIS features, you must configure the GIS meta data for the business tenant. After you connect to the server, execute the following command to import the default_srs_data_mysql.sql file into the database:
## $password must be replaced with the password for logging in to the database.
## $localhost must be replaced with the IP address for logging in to the database.
## $tenant_name must be replaced with the tenant name for logging in to the database.
## $port must be replaced with the port number of the database.
$python /home/admin/oceanbase/bin/import_srs_data.py -p'$password' -h $localhost -P $port -t $tenant_name -f /home/admin/oceanbase/etc/default_srs_data_mysql.sql
If the following result is returned, the data file is imported:
INFO: succeed to import srs data
INFO: oceanbase.__all_spatial_reference_systems old result rows -- 1
INFO: oceanbase.__all_spatial_reference_systems new result rows -- 5152
Examples
The following example shows how to create a spatial index:
-- Specify the SRID of the index column when you create the table.
CREATE TABLE geom (id NUMBER PRIMARY KEY,
name VARCHAR2(32),
shape SDO_GEOMETRY SRID 4326);
-- Insert two test records.
INSERT INTO geom VALUES(1,'a',SDO_GEOMETRY(2003,4326,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY(0,0, 0,1, 1,1, 1,0, 0,0)));
INSERT INTO geom VALUES(2,'a',SDO_GEOMETRY(2001,4326, sdo_point_type(0, 0, NULL), NULL, NULL));
-- Create an index.
CREATE INDEX g ON geom(shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
The following example shows how to create a spatial index for a partitioned table:
-- Specify the SRID of the index column when you create the partitioned table.
CREATE TABLE geom_par (id NUMBER PRIMARY KEY,
name VARCHAR2(32),
shape SDO_GEOMETRY SRID 4326)
PARTITION BY HASH(id) PARTITIONS 2;
-- Insert two test records.
INSERT INTO geom_par VALUES(1,'a',SDO_GEOMETRY(2003,4326,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY(0,0, 0,1, 1,1, 1,0, 0,0)));
INSERT INTO geom_par VALUES(2,'a',SDO_GEOMETRY(2001,4326, sdo_point_type(0, 0, NULL), NULL, NULL));
-- Create a local partition index (add the LOCAL keyword).
CREATE INDEX g ON geom_par(shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX LOCAL;
The following example shows how to drop a spatial index:
DROP INDEX g;
References
- For more information about SRID, see Spatial reference system (SRS).
- For more information about error handling when you import GIS data, see ERROR 3548 occurs when you run GIS type fields and related functions in the GIS feature.
- For more information about index queries, see Query calculation functions.