### Multi-dimensional information and queries

• Review of the indexes studied so far....

• So far, we have studied the following 3 index structures:

• Sorted indexes:

We studied the commonly used representative of sorted index -- the B+-tree index:

• Hashing-based indexes:

• Common property of these indexes:

 The search key values are values taken from a one-dimensional space/set

Example:

• If we index the search keys that are names, the search key values can be ordered on a one-dimensional space:

 ``` Search keys: AAAA < AAAB < .... < KLM < .... < ZZZZ ```

• Multi-dimensional Information

• There are information that are naturally multi-dimensional

Examples:

• Geographic information:

• Circuit board:

• Multi-dimensional queries

• Queries can be formulated on multi-dimensional data.

Example 1: Nearest point query

• Suppose we have a relation containing points on a map

• Each point is stored in the following relation:

 ``` Point( x, y ) ```

• Given a point p0(10, 20)

Query:

 Find the point that is closest to point p0(10, 20)

In SQL:

 ``` select * from Point P /* P is the closest point to p0 */ where not exists (select * from Point Q /* A closer point Q cannot exist ! */ where "distance(Q, p0) < distance(P, p0)") select * from Point P /* P is the closest point to p0 */ where not exists (select * from Point Q /* A closer point Q cannot exist ! */ where (Q.x-10)2 + (Q.y-20)2 < (P.x-10)2 + (P.y-20)2 ) ```

• Example 2: containment query

• Suppose we have a relation that define rectanglar objects:

 ``` Rectangle( id, xll, yll, xur, yur ) ```

A rectangle can be represented (= defined) by the coordinates of the Lower Left and Upper Right points.

Example of representation of a rectangle:

• Given a point P(10,20)

Query:

 Find all rectangles that contains the point P(10,20)

 ``` select id from rectangle where xll ≤ 10 AND yll ≤ 20 AND 10 ≤ xur AND 20 ≤ yur ```

Graphically:

• "Commonly used" (or "formulated") multi-dimensional queries

• Partial Match queries

 The query specifies conditions on some dimensions but not on all dimensions

Example:

• Find all points/objects that intersects with y = 50

• Range queries

 Find objects that are located either partial or wholly within a certain range

Example:

• Find all objects that have an overlap with the green area (= a range specification):

The green area can be specified as:

 ``` x1 ≤ x ≤ x2 y1 ≤ y ≤ y2 ```

• Nearest neighbor queries:

• Find object(s) that is located closest (nearest) to a given point:

• Where-am-I queries:

• Given a location (i.e., coordinate)

Find the object(s) that contains the location:

• Multi-dimensional indexes

• Multi-dimensional index:

 Multi-dimensional index = an index on the multi-dimensional data that help us answer a (commonly used) multi-dimensional query (more) efficiently (= speedier)

• Before we develop such multi-dimensional index, we answer this question first:

 Can we use a one-dimensional index to help us answer (commonly used) multi-dimensional queries (more) efficiently (= speedier) ??? (If so, we don't need to do anything !!!!)