8000 smoke test of nearest neighbor · jaylevitt/postgres@daa33e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit daa33e3

Browse files
committed
smoke test of nearest neighbor
1 parent 9cae4ea commit daa33e3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

contrib/cube/neighborcube.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
\c postgres
2+
drop database if exists jaytest;
3+
create database jaytest;
4+
\c jaytest
5+
6+
create schema jaytest;
7+
set search_path to jaytest;
8+
9+
\timing
10+
11+
create extension cube;
12+
13+
set work_mem to '1GB';
14+
set maintenance_work_mem to '1GB';
15+
16+
create operator <-> (
17+
procedure = cube_distance,
18+
leftarg = cube,
19+
rightarg = cube,
20+
commutator = <->);
21+
22+
CREATE OR REPLACE FUNCTION g_cube_distance(internal, cube, integer, oid)
23+
returns double precision
24+
language c immutable strict
25+
as '$libdir/cube';
26+
27+
alter operator family gist_cube_ops using gist add
28+
operator 15 <->(cube,cube) for order by float_ops,
29+
function 8 (cube,cube) g_cube_distance(internal,cube,integer,oid);
30+
31+
32+
create table cubetest (
33+
position cube
34+
);
35+
36+
insert into cubetest (position)
37+
select cube(array[random() * 1000, random() * 1000, random() * 1000,random() * 1000, random() * 1000, random() * 1000]) from generate_series(1,10000000);
38+
create index q on cubetest using gist(position);
39+
40+
select *, position <-> cube(array[500,500,500,500,500,500]) as p from cubetest order by p limit 10;
41+
select *, position <-> cube(array[500,500,500,500,500,500]) as p from cubetest order by p limit 10;
42+
select *, cube_distance(position, cube(array[500,500,500,500,500,500])) as p from cubetest order by p limit 10;

0 commit comments

Comments
 (0)
0