Dienstag, 14. Juni 2016

How to find the shortest distance to a location? (Nearest neighbour problem)

Setup

We have data containing coordinates of points lets say dwellings (about 1.6 millions) and like wise of post offices (1300). To each dwelling we want to know the nearest post office.

Problem

Brute force would be to cross join the sets getting a Cartesian product to calculate the distance of each dwelling with each post office. Thus, the data set comprised of 2.08 * 10^9 records. This probably would be either very slow or the tablespaces would blow to a ORA-01652.

Proposed solution


This solution is a quite able thing. The problem I had with ORA-04036 was due to a counter erroneously not being increased making the square not increase such that recursion never exited... dooo. :-)

Keine Kommentare:

Kommentar veröffentlichen