You are on page 1of 26

3

Spatial Tuning

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


Objectives

After completing this lesson, you should


be able to do the following:
• Determine the appropriate quadtree
indexing level for a layer
• Look at quadtree index structures and
determine their efficiency
• Verify the validity of geometries, or of an
entire layer

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -2
Tuning and Administration Tools

• The SDO_TUNE package


– Spatial data analysis
– Tune spatial indexes
• The SDO_GEOM package
– Validating geometries
• Manual analysis
• Enterprise Manager
– Spatial Index Advisor
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -3
What type of index should I use?
• Fixed indexing is very good in nearly all
cases, but requires tuning knowledge.
• R-tree indexes are very effective for nearest
neighbor queries, and are also generally
very good.
• R-trees may be less effective for some data
sets.
• In 9i, some features may only be supported
via R-trees (incremental nearest neighbor,
whole earth indexing).
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -4
Tuning Assistants
The SDO_TUNE package
(Quadtree Indexes)

• SDO_TUNE.ESTIMATE_TILING_LEVEL
– Gives a starting point to help determine an
appropriate tiling level (SDO_LEVEL) for
creating fixed-size index tiles.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -5
Tuning Assistants
The SDO_TUNE package
(Quadtree Indexes)

• SDO_TUNE.AVERAGE_MBR
– Calculates the average minimum bounding
rectangle for geometries in a layer.
• SDO_TUNE.EXTENT_OF
– Determines the minimum bounding rectangle
of the data in a layer.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -6
ESTIMATE_TILING_LEVEL

level := MDSYS.SDO_TUNE.ESTIMATE_TILING_LEVEL
( <table-name>, <column-name>,
<number-tiles>,
<type-of-estimate> )
• <table-name> and <column-name> identify
the spatial layer.
• <number-tiles> is the number of tiles
desired
• <type-of-estimate> defines the type of
estimation to perform
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -7
Type of estimation

• Extent of the entire LAYER_EXTENT


layer

• Extent surrounding all ALL_GID_EXTENT


geometries

• Extent surrounding AVG_GID_EXTENT


the average size
geometry

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -8
ESTIMATE_TILING_LEVEL
Example

select mdsys.sdo_tune.estimate_tiling_level (
'STATES', 'GEOM', 10000, 'LAYER_EXTENT')
from dual;

select mdsys.sdo_tune.estimate_tiling_level (
'STATES', 'GEOM', 10000, 'ALL_GID_EXTENT')
from dual;

select mdsys.sdo_tune.estimate_tiling_level (
'STATES', 'GEOM', 4, 'AVG_GID_EXTENT')
from dual;

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -9
Primary and Secondary Filter Concept

B B B

B I I B B

B I I I I B
B I I I I B

B I I I I B

B I I I B

B I B B B

B B B

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -10
Oracle Enterprise Manager (OEM)
Spatial Index Advisor
• Oracle 8.1.7 spatial tuning utility ships with OEM
• An Oracle EE typical install will install the spatial
index advisor
• To start the application, type: oemapp sdoadvisor
• To use the Spatial Index Advisor, must first create
the OEM_DEVELOPER_ROLE under the SYS Oracle
user.
• Must grant OEM_DEVELOPER_ROLE to any user
that plans to run Spatial Index Advisor

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -11
Oracle Enterprise Manager (OEM)
Spatial Index Advisor

DEMO

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -12
Oracle Enterprise Manager (OEM)
Spatial Index Advisor
• Remember to ANALYZE your quadtree spatial index
tables. This is required for optimal performance.Here
is some SQL that generates SQL to compute statistics.
SQL> select ‘ANALYZE TABLE ‘ || SDO_INDEX_TABLE ||
2 ‘ compute statistics; ‘
3 from user_sdo_index_metadata;

• For very large quadtree spatial index tables, you can


estimate 1 percent (if you don’t have the time to
compute statistics).
SQL> select ‘ANALYZE TABLE ‘ || SDO_INDEX_TABLE ||
2 ‘ estimate statistics sample 1 percent; ‘
3 from user_sdo_index_metadata;

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -13
Oracle Enterprise Manager (OEM)
Spatial Index Advisor (cont.)

• Iterative Process (for quadtree indexes)


– Create quadtree index
– View data at dense location
– Zoom to reasonable size
– If too large an area, choose a higher
number SDO_LEVEL (smaller tiles)
– If too small an area, choose a lower
number SDO_LEVEL (larger tiles)

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -14
AVERAGE_MBR

MDSYS.SDO_TUNE.AVERAGE_MBR
( <table-name>, <column-name>,
<width>, <height> )

• <table-name> and <column-name> identify


the spatial layer.
• <width> and <height> return the width and
height of the average geometry

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -15
AVERAGE_MBR
Example
SQL> set serveroutput on;
SQL> declare
2 width number;
3 height number;
4 begin
5 mdsys.sdo_tune.average_mbr
6 ('STATES', 'GEOM', width, height);
7 dbms_output.put_line ('Avg MBR: '|| width
7 ||'x'|| height);
8 end;
9 /
Avg MBR: 12.124x4.2268

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -16
EXTENT_OF

<geometry> := MDSYS.SDO_TUNE.EXTENT_OF
( <table-name>, <column-name> )

• <table-name> and <column-name> identify


the spatial layer.
• <geometry> returns a rectangle that
defines the extent of the layer.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -17
EXTENT_OF
Example

SELECT
mdsys.sdo_tune.extent_of('STATES','GEOM')
FROM dual;

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -18
Validating Geometries

• SDO_GEOM.VALIDATE_GEOMETRY
– Determines if a geometry is valid.
• SDO_GEOM.VALIDATE_LAYER
– Determines if all the geometries stored in a
column are valid.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -19
The VALIDATE_GEOMETRY function
error := MDSYS.SDO_GEOM.VALIDATE_GEOMETRY
( <geometry>,
<diminfo> )

• <geometry> = SDO_GEOMETRY that holds


the object to verify
– can be a variable or table column
• <diminfo> = dimensions array
• returns = an Oracle error number or TRUE
if valid, or FALSE if invalid for unknown
reason
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -20
VALIDATE_GEOMETRY
Example
SQL> SELECT mdsys.sdo_geom.validate_geometry
2 (s.geom,
3 (SELECT diminfo
4 FROM user_sdo_geom_metadata
5 WHERE table_name = 'STATES'
6 AND column_name = 'GEOM')) status
7 FROM states s
8 WHERE s.state = 'New Jersey';
STATUS
------
TRUE
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -21
The VALIDATE_LAYER function

MDSYS.SDO_GEOM.VALIDATE_LAYER
( <table-name>, <column-name>
<key-column>, <result-table>)

• <table-name> and <column-name> identify


the layer to verify
• <key-column> is the name of the primary
key of that table
– Must be a NUMBER!
• <result-table> is the name of a table that
will receive the results of the validation
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -22
The Results Table

• Must be manually created prior to using the


function

CREATE TABLE VALIDATION_RESULTS (


OBJECT_ID NUMBER,
OBJECT_STATE VARCHAR2(10)
);

• You define column names

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -23
VALIDATE_LAYER
Example
SQL> begin
2 mdsys.sdo_geom.validate_layer
3 ('RIVERS','GEOM','GID',’VALIDATION_RESULTS');
3 end;
4 /
SQL> SELECT * FROM validation_results
2 WHERE object_state <> 'TRUE';
OBJECT_ID OBJECT_STA
--------- ----------
2 13340
1005 13349
1009 13349
1010 13349
1011 13349

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -24
VALIDATE_GEOMETRY Example
Similar to Validate Layer

CREATE TABLE validation_results as (


SELECT mdsys.sdo_geom.validate_geometry
(s.geom,
(SELECT diminfo
FROM user_sdo_geom_metadata
WHERE table_name = 'STATES'
AND column_name = 'GEOM')) status,
STATE
FROM states s);

SELECT * FROM validation_results


WHERE status <> 'TRUE';

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -25
Summary
In this lesson, your should have learned
how to:
• Determine the appropriate tiling level when
building a quadtree index on a spatial layer
• Look at quadtree index structures and
determine their efficiency
• Use the OEM tool Spatial Index Advisor to
create and tune spatial indexes
• Verify the validity of individual geometries, or
of an entire layer
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -26

You might also like