Skip to content

Commit

Permalink
remove comment, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezra-varady committed Oct 2, 2023
1 parent 2ef47c6 commit e944421
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/hooks/op_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ static Node *operator_rewriting_mutator(Node *node, void *ctx)
return (Node *)seqscan;
}

// todo:: there is a function called query_or_expression_tree_mutator that might be able to replace the custom plan
// tree handling
if(is_plan_node(node)) {
return (Node *)plan_tree_mutator((Plan *)node, ctx);
} else {
Expand Down
40 changes: 40 additions & 0 deletions test/expected/hnsw_select.out
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,45 @@ SELECT has_index_scan('EXPLAIN WITH t AS (SELECT id FROM test1 ORDER BY v <-> ''
t
(1 row)

-- Validate <-> is replaced with the matching function when an index is present
set enable_seqscan = true;
EXPLAIN (COSTS false) SELECT * from small_world ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> Seq Scan on small_world
(3 rows)

SELECT * from small_world ORDER BY v <-> '{1,1,1}';
id | b | v
-----+---+---------
111 | t | {1,1,1}
101 | f | {1,0,1}
110 | f | {1,1,0}
011 | t | {0,1,1}
100 | f | {1,0,0}
001 | t | {0,0,1}
010 | f | {0,1,0}
000 | t | {0,0,0}
(8 rows)

begin;
INSERT INTO test2 (v) VALUES ('{1,4}');
INSERT INTO test2 (v) VALUES ('{2,4}');
CREATE INDEX test2_cos ON test2 USING hnsw(v dist_cos_ops);
INFO: done init usearch index
INFO: inserted 3 elements
INFO: done saving 3 vectors
EXPLAIN (COSTS false) SELECT * from test2 ORDER BY v <-> '{1,4}';
QUERY PLAN
--------------------------------------------
Sort
Sort Key: (cos_dist(v, '{1,4}'::real[]))
-> Seq Scan on test2
(3 rows)

rollback;
set enable_seqscan = false;
-- todo:: Verify joins work and still use index
-- todo:: Verify incremental sorts work
12 changes: 12 additions & 0 deletions test/sql/hnsw_select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,17 @@ SELECT has_index_scan('EXPLAIN (SELECT id FROM test1 ORDER BY v <-> ''{1,4}'') U
-- Validate CTEs work and still use index
SELECT has_index_scan('EXPLAIN WITH t AS (SELECT id FROM test1 ORDER BY v <-> ''{1,4}'') SELECT id FROM t UNION SELECT id FROM t');

-- Validate <-> is replaced with the matching function when an index is present
set enable_seqscan = true;
EXPLAIN (COSTS false) SELECT * from small_world ORDER BY v <-> '{1,1,1}';
SELECT * from small_world ORDER BY v <-> '{1,1,1}';
begin;
INSERT INTO test2 (v) VALUES ('{1,4}');
INSERT INTO test2 (v) VALUES ('{2,4}');
CREATE INDEX test2_cos ON test2 USING hnsw(v dist_cos_ops);
EXPLAIN (COSTS false) SELECT * from test2 ORDER BY v <-> '{1,4}';
rollback;
set enable_seqscan = false;

-- todo:: Verify joins work and still use index
-- todo:: Verify incremental sorts work

0 comments on commit e944421

Please sign in to comment.