-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support expression-based index operator checks (#179)
Add create expression test and make error messages distinct, support functions in post parse
- Loading branch information
Showing
9 changed files
with
109 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE OR REPLACE FUNCTION int_to_fixed_binary_real_array(n INT) RETURNS REAL[] AS $$ | ||
DECLARE | ||
binary_string TEXT; | ||
real_array REAL[] := '{}'; | ||
i INT; | ||
BEGIN | ||
binary_string := lpad(CAST(n::BIT(3) AS TEXT), 3, '0'); | ||
FOR i IN 1..length(binary_string) | ||
LOOP | ||
real_array := array_append(real_array, CAST(substring(binary_string, i, 1) AS REAL)); | ||
END LOOP; | ||
RETURN real_array; | ||
END; | ||
$$ LANGUAGE plpgsql IMMUTABLE; | ||
CREATE TABLE test_table (id INTEGER); | ||
INSERT INTO test_table VALUES (0), (1), (7); | ||
\set enable_seqscan = off; | ||
CREATE INDEX ON test_table USING hnsw (int_to_fixed_binary_real_array(id)) WITH (M=2, dim=3); | ||
INFO: done init usearch index | ||
INFO: inserted 3 elements | ||
INFO: done saving 3 vectors | ||
SELECT id FROM test_table ORDER BY int_to_fixed_binary_real_array(id) <-> int_to_fixed_binary_real_array(0) LIMIT 2; | ||
ERROR: Operator <-> can only be used inside of an index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE OR REPLACE FUNCTION int_to_fixed_binary_real_array(n INT) RETURNS REAL[] AS $$ | ||
DECLARE | ||
binary_string TEXT; | ||
real_array REAL[] := '{}'; | ||
i INT; | ||
BEGIN | ||
binary_string := lpad(CAST(n::BIT(3) AS TEXT), 3, '0'); | ||
FOR i IN 1..length(binary_string) | ||
LOOP | ||
real_array := array_append(real_array, CAST(substring(binary_string, i, 1) AS REAL)); | ||
END LOOP; | ||
RETURN real_array; | ||
END; | ||
$$ LANGUAGE plpgsql IMMUTABLE; | ||
|
||
CREATE TABLE test_table (id INTEGER); | ||
INSERT INTO test_table VALUES (0), (1), (7); | ||
\set enable_seqscan = off; | ||
CREATE INDEX ON test_table USING hnsw (int_to_fixed_binary_real_array(id)) WITH (M=2, dim=3); | ||
|
||
SELECT id FROM test_table ORDER BY int_to_fixed_binary_real_array(id) <-> int_to_fixed_binary_real_array(0) LIMIT 2; |