The syntax for creating a spatial index in OceanBase Database is different from that in Oracle Database. You must specify the SRID of a spatial index column when you create a table.
Notice
Creating a spatial index in OceanBase Database is not compatible with Oracle Database. In Oracle Database, you must manually maintain the mapping between spatial index columns and index information in the `USER_SDO_GEOM_METADATA` system table. OceanBase Database is compatible with Oracle Database in MySQL mode. Therefore, it does not maintain the `USER_SDO_GEOM_METADATA` table. As a result, the syntax for creating a spatial index in OceanBase Database is different from that in Oracle Database.
Considerations
- You must specify the SRID when you create a spatial index.
- You can create a local partitioned spatial index for a partitioned table. You must explicitly specify the
LOCALkeyword. Global partitioned spatial indexes are not supported.
Prerequisites
Before you use the GIS feature, you must configure GIS meta data 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 a 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 a 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 delete a spatial index:
DROP INDEX g;
References
- For more information about SRID, see Spatial reference system (SRS).
- For more information about error handling during GIS data import, see ERROR 3548.
- For more information about index queries, see Query calculation functions.