Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix push down tests #95

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ docker build -t vchord:pg16-latest --build-arg PG_VERSION=16 -f ./docker/Dockerf

```shell
docker run --name vchord -e POSTGRES_PASSWORD=123 -p 5432:5432 -d vchord:pg16-latest

PGPASSWORD=123 psql -h 127.0.0.1 -U postgres -c "CREATE USER bench WITH PASSWORD '123';"
PGPASSWORD=123 psql -h 127.0.0.1 -U postgres -c "ALTER ROLE bench SUPERUSER;"
```

## Run External Index Precomputation Toolkit
Expand Down
1 change: 0 additions & 1 deletion tests/logic/index.slt
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10)
10

statement ok
----
DROP TABLE t;
139 changes: 0 additions & 139 deletions tests/logic/pushdown_plan.fail

This file was deleted.

141 changes: 141 additions & 0 deletions tests/logic/pushdown_plan.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# TODO: Some tests are disabled due to unimplemented types: sparse vector and f16 vector

statement ok
CREATE TABLE t (val0 vector(3));

statement ok
INSERT INTO t (val0)
SELECT
ARRAY[random(), random(), random()]::real[]::vector
FROM generate_series(1, 10000);

statement ok
CREATE INDEX ind0 ON t USING vchordrq (val0 vector_l2_ops);

# statement ok
# CREATE INDEX ind1 ON t USING vchordrq (val1 halfvec_dot_ops);

# 1 vector key + 1 corresponding order_by key + sphere style
query I
EXPLAIN (COSTS FALSE, TIMING FALSE)
SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1) ORDER BY val0 <-> '[0, 0, 0]';
----
Index Scan using ind0 on t
Index Cond: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)
Order By: (val0 <-> '[0,0,0]'::vector)

# 1 vector key + 0 order_by key + original style
query I
EXPLAIN (COSTS FALSE, TIMING FALSE)
SELECT val0 FROM t WHERE val0 <-> '[0, 0, 0]' < 1;
----
Seq Scan on t
Filter: ((val0 <-> '[0,0,0]'::vector) < '1'::double precision)

# 1 vector key + 0 order_by key + sphere style
query I
EXPLAIN (COSTS FALSE, TIMING FALSE)
SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1);
----
Index Scan using ind0 on t
Index Cond: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)

# 0 vector key + 1 order_by key
query I
EXPLAIN (COSTS FALSE, TIMING FALSE)
SELECT val0 FROM t ORDER BY val0 <-> '[0, 0, 0]';
----
Index Scan using ind0 on t
Order By: (val0 <-> '[0,0,0]'::vector)

# 2 vector key(1 of them is corresponding) + 1 order_by key + original style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <-> '[0, 0, 0]' < 1
# AND val1 <#> '[0, 0, 0]' < 1
# ORDER BY val0 <-> '[0, 0, 0]';
# ----
# Index Scan using ind0 on t
# Order By: (val0 <-> '[0,0,0]'::vector)
# Filter: (((val0 <-> '[0,0,0]'::vector) < '1'::double precision) AND ((val1 <#> '[0,0,0]'::halfvec) < '1'::double precision))

# 2 vector key(1 of them is corresponding) + 1 order_by key + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1)
# AND val1 <<#>> sphere('[0, 0, 0]'::halfvec, 1)
# ORDER BY val0 <-> '[0, 0, 0]';
# ----
# Index Scan using ind0 on t
# Index Cond: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)
# Order By: (val0 <-> '[0,0,0]'::vector)
# Filter: (val1 <<#>> '("[0,0,0]",1)'::sphere_vecf16)

# 2 vector key(none of them is corresponding) + 1 order_by key + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val2 <<->> sphere('{}/3'::svector, 1)
# AND val1 <<#>> sphere('[0, 0, 0]'::halfvec, 1)
# ORDER BY val0 <-> '[0, 0, 0]';
# ----
# Index Scan using ind0 on t
# Order By: (val0 <-> '[0,0,0]'::vector)
# Filter: ((val2 <<->> '({}/3,1)'::sphere_svector) AND (val1 <<#>> '("[0,0,0]",1)'::sphere_vecf16))

# 2 vector keys(both indexed) + 0 order_by key + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1)
# AND val1 <<#>> sphere('[0, 0, 0]'::halfvec, 1);
# ----
# Index Scan using ind1 on t
# Index Cond: (val1 <<#>> '("[0,0,0]",1)'::sphere_vecf16)
# Filter: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)

# 2 vector keys(both not indexed) + 0 order_by key + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <<#>> sphere('[0, 0, 0]'::vector, 1)
# AND val1 <<->> sphere('[0, 0, 0]'::halfvec, 1);
# ----
# Seq Scan on t
# Filter: ((val0 <<#>> '("[0,0,0]",1)'::sphere_vector) AND (val1 <<->> '("[0,0,0]",1)'::sphere_vecf16))

# 2 vector key(1 indexed) + 0 order_by key + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1)
# AND val1 <<->> sphere('[0, 0, 0]'::halfvec, 1);
# ----
# Index Scan using ind0 on t
# Index Cond: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)
# Filter: (val1 <<->> '("[0,0,0]",1)'::sphere_vecf16)

# 1 vector key + 1 not corresponding order_by key(operator) + sphere style
query I
EXPLAIN (COSTS FALSE, TIMING FALSE)
SELECT val0 FROM t WHERE val0 <<#>> sphere('[0, 0, 0]'::vector, 1)
ORDER BY val0 <-> '[0, 0, 0]';
----
Index Scan using ind0 on t
Order By: (val0 <-> '[0,0,0]'::vector)
Filter: (val0 <<#>> '("[0,0,0]",1)'::sphere_vector)

# 1 vector key + 1 not corresponding order_by key(variable) + sphere style
# query I
# EXPLAIN (COSTS FALSE, TIMING FALSE)
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0, 0, 0]'::vector, 1)
# ORDER BY val1 <#> '[1, 1, 1]';
# ----
# Index Scan using ind1 on t
# Order By: (val1 <#> '[1,1,1]'::halfvec)
# Filter: (val0 <<->> '("[0,0,0]",1)'::sphere_vector)

# 0 vector key + 0 order_by key(variable)
query I
EXPLAIN (COSTS FALSE, TIMING FALSE) SELECT val0 FROM t;
----
Seq Scan on t

statement ok
DROP TABLE t;
37 changes: 19 additions & 18 deletions tests/logic/pushdown_range.fail → tests/logic/pushdown_range.slt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: Some tests are disabled due to unimplemented types: sparse vector and f16 vector

statement ok
CREATE TABLE t (val0 vector(3));

Expand All @@ -15,32 +17,31 @@ CREATE INDEX ON t USING vchordrq (val0 vector_l2_ops);
query I
SELECT val0 FROM t WHERE val0 <-> '[0.24, 0.24, 0.24]' < 0.12 ORDER BY val0 <-> '[0.24, 0.24, 0.24]';
----
[0.2, 0.2, 0.2]
[0.3, 0.3, 0.3]
[0.2,0.2,0.2]
[0.3,0.3,0.3]

# sphere style
query I
SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.012) ORDER BY val0 <-> '[0.24, 0.24, 0.24]';
SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.12) ORDER BY val0 <-> '[0.24, 0.24, 0.24]';
----
[0.2, 0.2, 0.2]
[0.3, 0.3, 0.3]
[0.2,0.2,0.2]
[0.3,0.3,0.3]

statement ok
# sphere style: multiple vector keys and no order-by key
query I
SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.012)
AND val1 <<#>> sphere('[0.24, -0.24, 0.24]'::halfvec, 0.05)
ORDER BY val0 <-> '[0.24, 0.24, 0.24]';
----
[0.2, 0.2, 0.2]
# query I
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.012)
# AND val1 <<#>> sphere('[0.24, -0.24, 0.24]'::halfvec, 0.05)
# ORDER BY val0 <-> '[0.24, 0.24, 0.24]';
# ----
# [0.2,0.2,0.2]

# sphere style: vectors in key and order-by key are different
query I
SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.012)
ORDER BY val1 <#> '[1, 1, -1]';
----
[0.3, 0.3, 0.3]
[0.2, 0.2, 0.2]
# query I
# SELECT val0 FROM t WHERE val0 <<->> sphere('[0.24, 0.24, 0.24]'::vector, 0.012)
# ORDER BY val1 <#> '[1, 1, -1]';
# ----
# [0.3,0.3,0.3]
# [0.2,0.2,0.2]

statement ok
DROP TABLE t;
1 change: 0 additions & 1 deletion tests/logic/vector.slt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10)
10

statement ok
----
DROP TABLE t;