Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezra-varady committed Oct 5, 2023
1 parent 3a1940d commit 6653d0c
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
96 changes: 96 additions & 0 deletions test/expected/hnsw_select.out
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,102 @@ EXPLAIN (COSTS false) SELECT * from test2 ORDER BY v <-> '{1,4}';
-> Seq Scan on test2
(3 rows)

-- Some additional cases that trigger operator rewriting
-- SampleScan
EXPLAIN (COSTS false) SELECT * FROM small_world TABLESAMPLE BERNOULLI (20) ORDER BY v <-> '{1,1,1}' ASC;
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> Sample Scan on small_world
Sampling: bernoulli ('20'::real)
(4 rows)

-- SetOpt/HashSetOp
EXPLAIN (COSTS false) (SELECT * FROM small_world ORDER BY v<-> '{1,0,1}' ASC )EXCEPT (SELECT * FROM small_world ORDER by v <-> '{1,1,1}' ASC LIMIT 5);
QUERY PLAN
-------------------------------------------------------------------------------------
HashSetOp Except
-> Append
-> Subquery Scan on "*SELECT* 1"
-> Sort
Sort Key: (l2sq_dist(small_world.v, '{1,0,1}'::real[]))
-> Seq Scan on small_world
-> Subquery Scan on "*SELECT* 2"
-> Limit
-> Sort
Sort Key: (l2sq_dist(small_world_1.v, '{1,1,1}'::real[]))
-> Seq Scan on small_world small_world_1
(11 rows)

-- HashAggregate
EXPLAIN (COSTS false) SELECT v, COUNT(*) FROM small_world GROUP BY v ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> HashAggregate
Group Key: v
-> Seq Scan on small_world
(5 rows)

-- GroupBy this
EXPLAIN (COSTS false) SELECT * FROM small_world GROUP BY id, v, b ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> HashAggregate
Group Key: id, v, b
-> Seq Scan on small_world
(5 rows)

-- HashJoin/Hash
CREATE TABLE small_world_2 AS (SELECT * FROM small_world);
EXPLAIN (COSTS false) SELECT * FROM small_world JOIN small_world_2 using (v) ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------------------
Sort
Sort Key: (l2sq_dist(small_world.v, '{1,1,1}'::real[]))
-> Hash Join
Hash Cond: (small_world_2.v = small_world.v)
-> Seq Scan on small_world_2
-> Hash
-> Seq Scan on small_world
(7 rows)

-- MixedAggregate (this doesn't require additional logic, but I include it here as an example of generating the path)
EXPLAIN (COSTS false) SELECT v FROM small_world GROUP BY ROLLUP(v) ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> MixedAggregate
Hash Key: v
Group Key: ()
-> Seq Scan on small_world
(6 rows)

-- WindowAgg
EXPLAIN (COSTS false) SELECT v, EVERY(b) OVER () FROM small_world ORDER BY v <-> '{1,1,1}';
QUERY PLAN
-----------------------------------------------
Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> WindowAgg
-> Seq Scan on small_world
(4 rows)

-- LockRows
EXPLAIN (COSTS false) SELECT * FROM small_world ORDER BY v <-> '{1,1,1}' ASC FOR UPDATE;
QUERY PLAN
-----------------------------------------------------
LockRows
-> Sort
Sort Key: (l2sq_dist(v, '{1,1,1}'::real[]))
-> Seq Scan on small_world
(4 rows)

rollback;
set enable_seqscan = false;
-- todo:: Verify joins work and still use index
Expand Down
4 changes: 2 additions & 2 deletions test/sql/hnsw_select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ EXPLAIN (COSTS false) SELECT v, COUNT(*) FROM small_world GROUP BY v ORDER BY v
-- GroupBy this
EXPLAIN (COSTS false) SELECT * FROM small_world GROUP BY id, v, b ORDER BY v <-> '{1,1,1}';
-- HashJoin/Hash
CREATE small_world_2 AS (SELECT * FROM small_world);
CREATE TABLE small_world_2 AS (SELECT * FROM small_world);
EXPLAIN (COSTS false) SELECT * FROM small_world JOIN small_world_2 using (v) ORDER BY v <-> '{1,1,1}';
-- MixedAggregate (this doesn't require additional logic, but I include it here as an example of generating the path)
EXPLAIN (COSTS false) SELECT v FROM small_world GROUP BY ROLLUP(v) ORDER BY v <-> '{1,1,1}';
-- WindowAgg
EXPLAIN (COSTS false) SELECT v, SUM(id) OVER () FROM small_world ORDER BY v <-> '{1,1,1}';
EXPLAIN (COSTS false) SELECT v, EVERY(b) OVER () FROM small_world ORDER BY v <-> '{1,1,1}';
-- LockRows
EXPLAIN (COSTS false) SELECT * FROM small_world ORDER BY v <-> '{1,1,1}' ASC FOR UPDATE;

Expand Down

0 comments on commit 6653d0c

Please sign in to comment.