You are on page 1of 26

3

Spatial Tuning

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


Objectives

After
After completing
completing this this lesson,
lesson, you
you should
should
be
be able
able to
to do
do the
the following:
following:
• Determine
Determine thethe appropriate
appropriate quadtree
quadtree
indexing
indexing level
level for
for aa layer
layer
• Look
Look atat quadtree
quadtree index
index structures
structures and
and
determine
determine their
their efficiency
efficiency
• Verify
Verify the
the validity
validity ofof geometries,
geometries, or
or of
of an
an
entire
entire layer
layer

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -2
Tuning and Administration Tools

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

Oracle Corporation, 2002. All rights reserved.


3 -3
What type of index should I use?
• Fixed
Fixed indexing
indexing is is very
very good
good inin nearly
nearly all
all
cases,
cases, butbut requires
requires tuning
tuning knowledge.
knowledge.
• R-tree
R-tree indexes
indexes are
are very
very effective
effective for
for nearest
nearest
neighbor
neighbor queries,
queries, andand are
are also
also generally
generally
very
very good.
good.
• R-trees
R-trees maymay bebe less
less effective
effective for
for some
some data
data
sets.
sets.
• In
In 9i,
9i, some
some features
features maymay only
only bebe supported
supported
via
via R-trees
R-trees (incremental
(incremental nearest
nearest neighbor,
neighbor,
whole
whole earth
earth indexing).
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
SDO_TUNE.ESTIMATE_TILING_LEVEL
–– Gives
Gives aa starting
starting point
point to
to help
help determine
determine an
an
appropriate
appropriate tiling
tiling level
level (SDO_LEVEL)
(SDO_LEVEL) forfor
creating
creating fixed-size
fixed-size index
index tiles.
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
SDO_TUNE.AVERAGE_MBR
–– Calculates
Calculates the
the average
average minimum
minimum bounding
bounding
rectangle
rectangle for
for geometries
geometries in
in aa layer.
layer.
• SDO_TUNE.EXTENT_OF
SDO_TUNE.EXTENT_OF
–– Determines
Determines the
the minimum
minimum bounding
bounding rectangle
rectangle
of
of the
the data
data in
in aa layer.
layer.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -6
ESTIMATE_TILING_LEVEL

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

Oracle Corporation, 2002. All rights reserved.


3 -7
Type of estimation

•• Extent
Extent of
of the
the entire
entire LAYER_EXTENT
layer
layer

•• Extent
Extent surrounding
surrounding all
all ALL_GID_EXTENT
geometries
geometries

•• Extent
Extent surrounding
surrounding AVG_GID_EXTENT
the
the average
average size
size
geometry
geometry

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -8
ESTIMATE_TILING_LEVEL
Example
Example
select
select mdsys.sdo_tune.estimate_tiling_level
mdsys.sdo_tune.estimate_tiling_level ((
'STATES',
'STATES', 'GEOM',
'GEOM', 10000,
10000, 'LAYER_EXTENT')
'LAYER_EXTENT')
from
from dual;
dual;

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

select
select mdsys.sdo_tune.estimate_tiling_level
mdsys.sdo_tune.estimate_tiling_level ((
'STATES',
'STATES', 'GEOM',
'GEOM', 4,
4, 'AVG_GID_EXTENT')
'AVG_GID_EXTENT')
from
from dual;
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
Oracle 8.1.7
8.1.7 spatial
spatial tuning
tuning utility
utility ships
ships with
with OEM
OEM
•• An
An Oracle
Oracle EE
EE typical
typical install
install will
will install
install the
the spatial
spatial
index
index advisor
advisor
•• To
To start
start the
the application,
application, type:
type: oemapp
oemapp sdoadvisor
sdoadvisor
•• To
To use
use the
the Spatial
Spatial Index
Index Advisor,
Advisor, must
must first
first create
create
the
the OEM_DEVELOPER_ROLE
OEM_DEVELOPER_ROLE under under the
the SYS
SYS Oracle
Oracle
user.
user.
•• Must
Must grant
grant OEM_DEVELOPER_ROLE
OEM_DEVELOPER_ROLE to to any
any user
user
that
that plans
plans to
to run
run Spatial
Spatial Index
Index Advisor
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
Remember to
to ANALYZE
ANALYZE your
your quadtree
quadtree spatial
spatial index
index
tables.
tables. This
This is
is required
required for
for optimal
optimal performance.Here
performance.Here
is
is some
some SQL
SQL that
that generates
generates SQL
SQL to
to compute
compute statistics.
statistics.
SQL>
SQL> select
select ‘ANALYZE
‘ANALYZE TABLE
TABLE ‘‘ ||
|| SDO_INDEX_TABLE
SDO_INDEX_TABLE ||
||
22 ‘‘ compute
compute statistics;
statistics; ‘‘
33 from
from user_sdo_index_metadata;
user_sdo_index_metadata;

•• For
For very
very large
large quadtree
quadtree spatial
spatial index
index tables,
tables, you
you can
can
estimate
estimate 11 percent
percent (if
(if you
you don’t
don’t have
have the
the time
time to
to
compute
compute statistics).
statistics).
SQL>
SQL> select
select ‘ANALYZE
‘ANALYZE TABLE
TABLE ‘‘ ||
|| SDO_INDEX_TABLE
SDO_INDEX_TABLE ||
||
22 ‘‘ estimate
estimate statistics
statistics sample
sample 11 percent;
percent; ‘‘
33 from
from user_sdo_index_metadata;
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
Iterative Process
Process (for
(for quadtree
quadtree indexes)
indexes)
–– Create
Create quadtree
quadtree index
index
–– View
View data
data at
at dense
dense location
location
–– Zoom
Zoom to
to reasonable
reasonable size
size
–– If
If too
too large
large an
an area,
area, choose
choose aa higher
higher
number
number SDO_LEVEL
SDO_LEVEL (smaller
(smaller tiles)
tiles)
–– If
If too
too small
small an
an area,
area, choose
choose aa lower
lower
number
number SDO_LEVEL
SDO_LEVEL (larger
(larger tiles)
tiles)

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -14
AVERAGE_MBR

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

• <table-name>
<table-name> andand <column-name>
<column-name> identify
identify
the
the spatial
spatial layer.
layer.
• <width>
<width> and
and <height>
<height> return
return the
the width
width and
and
height
height of
of the
the average
average geometry
geometry

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -15
AVERAGE_MBR
Example
Example
SQL>
SQL> set
set serveroutput
serveroutput on;
on;
SQL>
SQL> declare
declare
22 width
width number;
number;
33 height
height number;
number;
44 begin
begin
55 mdsys.sdo_tune.average_mbr
mdsys.sdo_tune.average_mbr
66 ('STATES',
('STATES', 'GEOM',
'GEOM', width,
width, height);
height);
77 dbms_output.put_line
dbms_output.put_line ('Avg
('Avg MBR:
MBR: '||
'|| width
width
77 ||'x'||
||'x'|| height);
height);
88 end;
end;
99 //
Avg
Avg MBR:
MBR: 12.124x4.2268
12.124x4.2268

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -16
EXTENT_OF

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

• <table-name>
<table-name> andand <column-name>
<column-name> identify
identify
the
the spatial
spatial layer.
layer.
• <geometry>
<geometry> returns
returns aa rectangle
rectangle that
that
defines
defines the
the extent
extent of
of the
the layer.
layer.

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -17
EXTENT_OF
Example
Example

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

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -18
Validating Geometries

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

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


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

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

Oracle Corporation, 2002. All rights reserved.


3 -20
VALIDATE_GEOMETRY
Example
SQL>
SQL> SELECT
SELECT mdsys.sdo_geom.validate_geometry
mdsys.sdo_geom.validate_geometry
22 (s.geom,
(s.geom,
33 (SELECT
(SELECT diminfo
diminfo
44 FROM
FROM user_sdo_geom_metadata
user_sdo_geom_metadata
55 WHERE
WHERE table_name
table_name == 'STATES'
'STATES'
66 AND
AND column_name
column_name == 'GEOM'))
'GEOM')) status
status
77 FROM
FROM states
states ss
88 WHERE
WHERE s.state
s.state == 'New
'New Jersey';
Jersey';
STATUS
STATUS
------
------
TRUE
TRUE
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -21
The VALIDATE_LAYER function

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

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

Oracle Corporation, 2002. All rights reserved.


3 -22
The Results Table

• Must
Must be
be manually
manually created
created prior
prior to
to using
using the
the
function
function

CREATE
CREATE TABLE
TABLE VALIDATION_RESULTS
VALIDATION_RESULTS ((
OBJECT_ID
OBJECT_ID NUMBER,
NUMBER,
OBJECT_STATE
OBJECT_STATE VARCHAR2(10)
VARCHAR2(10)
);
);

• You
You define
define column
column names
names

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -23
VALIDATE_LAYER
Example
SQL>
SQL> begin
begin
22 mdsys.sdo_geom.validate_layer
mdsys.sdo_geom.validate_layer
33 ('RIVERS','GEOM','GID',’VALIDATION_RESULTS');
('RIVERS','GEOM','GID',’VALIDATION_RESULTS');
33 end;
end;
44 //
SQL>
SQL> SELECT
SELECT ** FROM
FROM validation_results
validation_results
22 WHERE
WHERE object_state
object_state <>
<> 'TRUE';
'TRUE';
OBJECT_ID
OBJECT_ID OBJECT_STA
OBJECT_STA
---------
--------- ----------
----------
22 13340
13340
1005
1005 13349
13349
1009
1009 13349
13349
1010
1010 13349
13349
1011
1011 13349
13349
Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


3 -24
VALIDATE_GEOMETRY Example
Similar to Validate Layer

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

SELECT
SELECT ** FROM
FROM validation_results
validation_results
WHERE
WHERE status
status <>
<> 'TRUE';
'TRUE';

Copyright  Intergraph Hong Kong Limited, ®

Oracle Corporation, 2002. All rights reserved.


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

Oracle Corporation, 2002. All rights reserved.


3 -26

You might also like