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

Add test to catch crash when creating extension in transaction and using operator in the same tx #237

Closed
wants to merge 2 commits into from
Closed
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
45 changes: 45 additions & 0 deletions test/expected/hnsw_op_rewrite.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---------------------------------------------------------------------
-- Test Database Crashes which were caused by operator rewriting logic
---------------------------------------------------------------------
-- This case were causing Segfault from
-- post_parse_analyze_hook_with_operator_check() -> ldb_get_operator_oids() -> ... LookupOperName() ... -> GetRealCmin()
BEGIN;
DROP EXTENSION IF EXISTS lantern CASCADE;
CREATE EXTENSION lantern;
\set ON_ERROR_STOP off
SELECT ARRAY[1,1] <-> ARRAY[1,1];
ROLLBACK;
-- This case were causing: ERROR: unrecognized node type: 233
-- And sometimes Segfault as well
-- This is caused when trying to call expression_tree_mutator with OidList_T node
BEGIN;
\set ON_ERROR_STOP off
DROP TABLE IF EXISTS t1 CASCADE;
NOTICE: table "t1" does not exist, skipping
CREATE TABLE t1 (
id TEXT PRIMARY KEY,
v REAL[]
);
DROP TABLE IF EXISTS t2 CASCADE;
NOTICE: table "t2" does not exist, skipping
CREATE TABLE t2 (
id SERIAL PRIMARY KEY,
t1_id TEXT,
CONSTRAINT fk_t1 FOREIGN KEY(t1_id) REFERENCES t1(id)
);
INSERT INTO t1 (id, v) VALUES ('1', ARRAY[0,0,0]);
CREATE INDEX ON t1 USING hnsw(v dist_cos_ops) WITH (m=32, ef_construction=128, ef=64);
INFO: done init usearch index
INFO: inserted 1 elements
INFO: done saving 1 vectors
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
END;
2 changes: 1 addition & 1 deletion test/schedule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# - every test that needs to be run iff pgvector is installed appears in a 'test_pgvector:' line
# - 'test' lines may have multiple space-separated tests. All tests in a single 'test' line will be run in parallel

test: hnsw_config hnsw_correct hnsw_create hnsw_create_expr hnsw_dist_func hnsw_insert hnsw_select hnsw_todo hnsw_index_from_file hnsw_cost_estimate ext_relocation hnsw_ef_search hnsw_failure_point
test: hnsw_config hnsw_correct hnsw_create hnsw_create_expr hnsw_dist_func hnsw_insert hnsw_select hnsw_todo hnsw_index_from_file hnsw_cost_estimate ext_relocation hnsw_ef_search hnsw_failure_point hnsw_op_rewrite
test_pgvector: hnsw_vector
46 changes: 46 additions & 0 deletions test/sql/hnsw_op_rewrite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---------------------------------------------------------------------
-- Test Database Crashes which were caused by operator rewriting logic
---------------------------------------------------------------------
-- This case were causing Segfault from
-- post_parse_analyze_hook_with_operator_check() -> ldb_get_operator_oids() -> ... LookupOperName() ... -> GetRealCmin()
BEGIN;
DROP EXTENSION IF EXISTS lantern CASCADE;
CREATE EXTENSION lantern;
\set ON_ERROR_STOP off
SELECT ARRAY[1,1] <-> ARRAY[1,1];
ROLLBACK;

-- This case were causing: ERROR: unrecognized node type: 233
-- And sometimes Segfault as well
-- This is caused when trying to call expression_tree_mutator with OidList_T node
BEGIN;
\set ON_ERROR_STOP off
DROP TABLE IF EXISTS t1 CASCADE;
CREATE TABLE t1 (
id TEXT PRIMARY KEY,
v REAL[]
);

DROP TABLE IF EXISTS t2 CASCADE;
CREATE TABLE t2 (
id SERIAL PRIMARY KEY,
t1_id TEXT,
CONSTRAINT fk_t1 FOREIGN KEY(t1_id) REFERENCES t1(id)
);

INSERT INTO t1 (id, v) VALUES ('1', ARRAY[0,0,0]);

CREATE INDEX ON t1 USING hnsw(v dist_cos_ops) WITH (m=32, ef_construction=128, ef=64);

INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
INSERT INTO t2 (t1_id) VALUES ('1');
END;

Loading