The syntax for creating spatial indexes in OceanBase Database is different from that in Oracle. The SRID of a spatial index column is specified when the table is created.
Notice
Creating spatial indexes in OceanBase Database is not compatible with Oracle. In Oracle, when you create a spatial index, you must manually maintain the mapping between the spatial index column and the index information in the `USER_SDO_GEOM_METADATA` system table. OceanBase Database uses the MySQL style to be compatible with Oracle mode and does not maintain the `USER_SDO_GEOM_METADATA` table. Therefore, the syntax is different from that in Oracle.
Considerations
- You must specify the SRID when you create a spatial index.
- For partitioned tables, you can create only local partitioned spatial indexes (you must explicitly specify the
LOCALkeyword). Global partitioned spatial indexes are not supported.
Prerequisites
Before you use the GIS features, you must configure GIS metadata in the business tenant. After you connect to the server, run 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 partitioned spatial 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 systems (SRS).
- For more information about error handling during spatial data import, see ERROR 3548.
- For more information about index queries, see Query functions.
