Manhattan distance with n dimensions in oracle

I have a table about 5 million rows in size and each row contains 10 columns representing 10 dimensions. I would like to be able, when a new entry is suitable for performing a table search, to return the nearest rows using Manhattan distances. The distance is the sum of abs (Ai-Aj) + abs (Bi-Bj) ... The problem is that at the moment, if I make a request, it performs a full scan of the entire table, calculates the distances from all the rows and sorts them, to find the top X.

Is there a way to speed up the process and make the request more efficient?

I looked at the distance function online for SDO_GEOMETRY, but I could not find it for more than 4 dimensions.

thank

+5
source share
2 answers

If you insert point A and want to search for points that are within the radius r (i.e. less than the distance from any metric), you can make a really simple query:

select x1, x2, ..., xn
from   points
where  x1 between a1 - r and a1 + r
and    x2 between a2 - r and a2 + r
...
and    xn between an - r and an + r

... where A = (a1, a2, ..., an)to find an estimate. If you have an index for all fields x1, ... xn points, then this query does not require a full scan. Now this result may include points outside the neighborhood (i.e. Bits in the corners), but it is easy to win to find a suitable subset: now you can check the entries in this subquery, rather than checking every point in your table.

, , ( 45 ) ! ( 10 .) , , .

+2

. , , .

, . , , . ​​manhanttan, .

@Xophmeister. . sql, . .

5 , k - . , 1000 , . . . - , , , (1) 20 000 ,... (987) 10.000 ...

. , 987. sql, , , 10.000 .

/ , . 5.000.000 , k-, . , .

0

All Articles