User's Guide and Reference

The following rules apply if you want to optimize spatial queries using spatial predicates:

Examples of index exploitation

Table 4 shows the correct and incorrect ways of creating spatial queries to exploit the spatial index.


Table 4. Rules for index exploitation
Spatial query Rule violated

SELECT *
FROM customers c
WHERE db2gse.ST_Within(c.location,:BayArea)=1

No condition is violated in this example.

SELECT *
FROM customers c
WHERE db2gse.ST_Distance(c.location,:SanJose)<10

No condition is violated in this example.
SELECT *
FROM customers c
WHERE db2gse.ST_Length(c.location)>10

The predicate must be used in the WHERE clause. (ST_Length is a spatial function, but not a predicate.)
SELECT *
FROM customers c
WHERE 1=db2gse.ST_Within(c.location,:BayArea)

The predicate must be on the left-hand side of the comparison.
SELECT *
FROM customers c
WHERE db2gse.ST_Within(c.location,:BayArea)=2

Equality comparisons must use the integer constant 1.
SELECT *
FROM customers c
WHERE db2gse.ST_Within(:SanJose,:BayArea)=1

There must be a spatial column used in the predicate as the search target, and there must be a spatial index created on that column. (SanJose and BayArea are not spatial columns and therefore, cannot have a spatial index associated with them.)


[ Top of Page | Previous Page | Next Page ]