HOW TO
Working with a partitioned table in Oracle with a st_geometry attribute and spatial index requires going beyond the steps of just creating the partitioned table and local spatial indexes in the database. To provide the Oracle optimizer the ability to leverage the partitioning schema and each partition's local index, the application working with the data must set the partition key as a predicate filter in the SQL statement. By doing so, the optimizer can perform partition pruning and only access the relevant partitions based on the specified predicate filters. When only accessing the relevant partitions during the query, performance can be improved by performing less I/O operations.
Instructions provided describe how to use Oracle partitioning by demonstrating how to create a partitioned table, create local spatial indexes for each partition, create a system context and view, and how to set the context predicate values to leverage the table's partitions, by way of the context and view, in ArcGIS.
Code:
D:\>sdedbtune -o export -f dbtune.txt -u sde -p sde -i 5151
ArcSDE 9.2 for Oracle10g Build 508 Thu Apr 17 12:23:18 2008
Attribute Administration Utility
-----------------------------------------------------
Successfully exported to file "dbtune.txt"
from server ALEX
Code:
##PARTITION
B_STORAGE "PARTITION BY RANGE (location_date)
(PARTITION jan VALUES LESS THAN ( to_date('02-01-2008','MM-DD-YYYY') )
STORAGE (INITIAL 128K) TABLESPACE january,
PARTITION feb VALUES LESS THAN ( to_date('03-01-2008','MM-DD-YYYY') )
STORAGE (INITIAL 128K) TABLESPACE february,
PARTITION mar VALUES LESS THAN ( to_date('04-01-2008','MM-DD-YYYY') )
STORAGE (INITIAL 128K) TABLESPACE march,
PARTITION apr VALUES LESS THAN ( to_date('05-01-2008','MM-DD-YYYY') )
STORAGE (INITIAL 128K) TABLESPACE april,
PARTITION may VALUES LESS THAN ( to_date('06-01-2008','MM-DD-YYYY') )
STORAGE (INITIAL 128K) TABLESPACE may)
ENABLE ROW MOVEMENT"
GEOMETRY_STORAGE "ST_GEOMETRY"
UI_TEXT "User Interface text description for Partition"
END
Code:
D:\>sdedbtune -o import -f dbtune.txt -u sde -p sde -i 5151 -N
ArcSDE 9.2 for Oracle10g Build 508 Thu Apr 17 12:23:18 2008
Attribute Administration Utility
-----------------------------------------------------
Successfully imported from file "dbtune.txt"
Note:
Prior to creating the feature class, each tablespace specified in the dbtune keyword must exist.
Code:
SQL> CREATE TABLE service_vehicles
2 (objectid NUMBER(38) NOT NULL,
3 vehicle_id NUMBER(38),
4 location_date DATE NOT NULL,
5 shape sde.st_geometry)
6 PARTITION BY RANGE (location_date)
7 (PARTITION jan VALUES LESS THAN ( to_date('02-01-2008','MM-DD-YYYY') )
8 STORAGE (INITIAL 128K) TABLESPACE january,
9 PARTITION feb VALUES LESS THAN ( to_date('03-01-2008','MM-DD-YYYY') )
10 STORAGE (INITIAL 128K) TABLESPACE february,
11 PARTITION mar VALUES LESS THAN ( to_date('04-01-2008','MM-DD-YYYY') )
12 STORAGE (INITIAL 128K) TABLESPACE march,
13 PARTITION apr VALUES LESS THAN ( to_date('05-01-2008','MM-DD-YYYY') )
14 STORAGE (INITIAL 128K) TABLESPACE april,
15 PARTITION may VALUES LESS THAN ( to_date('06-01-2008','MM-DD-YYYY') )
16 STORAGE (INITIAL 128K) TABLESPACE may)
17 ENABLE ROW MOVEMENT;
Table created.
Code:
SQL> CREATE INDEX shape_idx ON service_vehicles (shape)
2 INDEXTYPE IS sde.st_spatial_index
3 PARAMETERS('st_srid=1 st_grids=1000')
4 LOCAL;
Index created.
Note:
When creating the spatial index, a valid spatial reference st_srid value must be set in the parameters clause.
For the following example, rows are inserted into the table using SQL. The rows are written to the various partitions based on the value for location_date (the partition key).
Code:
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('01-12-2008','MM-DD-YYYY'), sde.st_geometry('point (10 10)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('01-20-2008','MM-DD-YYYY'), sde.st_geometry('point (10 12)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('02-03-2008','MM-DD-YYYY'), sde.st_geometry('point (8 14)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('03-10-2008','MM-DD-YYYY'), sde.st_geometry('point (10 12)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('04-01-2008','MM-DD-YYYY'), sde.st_geometry('point (10 12)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('05-25-2008','MM-DD-YYYY'), sde.st_geometry('point (10 12)', 1));
1 row created.
SQL> INSERT INTO service_vehicles VALUES
2 (1, 99, TO_DATE('05-25-2008','MM-DD-YYYY'), sde.st_geometry('point (10 14)', 1));
1 row created.
SQL> COMMIT;
Commit complete.
Code:
SQL> CREATE OR REPLACE PACKAGE date_ctx_pkg
2 AS
3
4 PROCEDURE set_val (ctx_name IN VARCHAR2, p_name IN VARCHAR2, p_val IN VARCHAR2);
5
6 FUNCTION sys_ctx_string (ctx_name IN VARCHAR2, p_name IN VARCHAR2) RETURN VARCHAR2;
7
8 END date_ctx_pkg;
9 /
Package created.
Code:
SQL> CREATE OR REPLACE PACKAGE BODY date_ctx_pkg
2 IS
3
4 PROCEDURE set_val (ctx_name IN VARCHAR2, p_name IN VARCHAR2, p_val IN VARCHAR2)
5 IS
6
7 BEGIN
8 dbms_session.set_context (ctx_name, p_name, p_val);
9 END;
10
11 FUNCTION sys_ctx_string (ctx_name IN VARCHAR2, p_name IN VARCHAR2) RETURN VARCHAR2
12 IS
13
14 BEGIN
15 RETURN 'sys_context ( ''' || ctx_name || ''', ''' || p_name || ''' )';
16 END;
17
18 END date_ctx_pkg;
19 /
Package body created.
Code:
SQL> GRANT EXECUTE ON date_ctx_pkg TO PUBLIC;
Grant succeeded.
Code:
SQL> CREATE OR REPLACE CONTEXT start_time_ctx USING date_ctx_pkg;
Context created.
SQL> CREATE OR REPLACE CONTEXT end_time_ctx USING date_ctx_pkg;
Context created.
Code:
D:\>sdelayer -o register -l service_vehicles,shape -e p -R 1 -C objectid,sde -t
st_geometry -u tomb -p tomb -i 5151
ArcSDE 9.2 for Oracle10g Build 508 Thu Apr 17 12:23:18 2008
Layer Administration Utility
-----------------------------------------------------
Successfully Created Layer.
Code:
D:\>sdetable -o create_view -T service_vehicle_view -t service_vehicles
-c objectid,vehicle_id,location_date,shape
-w "location_date >= to_date(sys_context ('start_time_ctx', 'ID'),'MM-DD-YYYY')
AND location_date <= to_date(sys_context ('end_time_ctx', 'ID'),'MM-DD-YYYY')"
-u tomb -p tomb -i 5151
ArcSDE 9.2 for Oracle10g Build 508 Thu Apr 17 12:23:18 2008
Attribute Administration Utility
-----------------------------------------------------
Successfully created view service_vehicle_view.
Note:
When executing an ArcSDE administration command, there are no carriage returns between arguments. The carriage returns are added in this example for ease of reading.
Optionally, a view can be created with SQL containing the same WHERE clause definition.
Code:
SQL> CREATE OR REPLACE VIEW ser_veh_view AS
2 SELECT *
3 FROM service_vehicles
4 WHERE location_date >= TO_DATE(sys_context('start_time_ctx', 'ID'),'MM-DD-YYYY')
5 AND location_date <= TO_DATE(sys_context ('end_time_ctx', 'ID'),'MM-DD-YYYY');
View created.
Code:
SQL> SELECT objectid FROM ser_veh_view;
no rows selected
Code:
SQL> EXECUTE sde.date_ctx_pkg.set_val('start_time_ctx','id','01-01-2008');
PL/SQL procedure successfully completed.
SQL> EXECUTE sde.date_ctx_pkg.set_val('end_time_ctx','id','01-31-2008');
PL/SQL procedure successfully completed.
Code:
SQL> SELECT objectid FROM ser_veh_view;
OBJECTID
----------
1
2
Code:
SQL> SELECT sys_context('start_time_ctx','id') start_time FROM dual;
START_TIME
----------
01-01-2008
Code:
BEGIN sde.date_ctx_pkg.set_val('start_time_ctx','id','01-01-2008'); END;
Code:
BEGIN sde.date_ctx_pkg.set_val('end_time_ctx','id','01-31-2008'); END;
Get help from ArcGIS experts
Download the Esri Support App