I am looking for a way to do fast KNN queries on a dataset of 10+ million 3D points (and growing). I was hoping PostGIS would do the trick with its new <-> and <#> operators, but they don't seem to work in three dimensions. Does anyone know any workarounds that would extend the KNN GiST index to 3D? Right now I'm using a "normal" spatial index with the &&& operator, but that creates all the issues that led to the addition of the KNN index in the first place.
A "patch that introduces kNN search for cubes with euclidean, taxicab and chebyshev distances" was recently offered on the pgsql-hackers list.
Note that the
I haven't yet used it, and note that one of the replies suggests it may currently break some regression tests. But, it seems to add the necessary <-> operator and "OPERATOR CLASS gist_cube_ops" changes for a gist index on cube distances to work.