Skip to content

Commit 1165703

Browse files
committed
fix: add immutable to cast functions
1 parent f8257f2 commit 1165703

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/encrypted/casts.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
--
88

99
CREATE FUNCTION eql_v2.to_encrypted(data jsonb)
10-
RETURNS public.eql_v2_encrypted AS $$
10+
RETURNS public.eql_v2_encrypted
11+
IMMUTABLE STRICT PARALLEL SAFE
12+
AS $$
1113
BEGIN
1214
IF data IS NULL THEN
1315
RETURN NULL;
@@ -17,6 +19,7 @@ BEGIN
1719
END;
1820
$$ LANGUAGE plpgsql;
1921

22+
2023
--
2124
-- Cast jsonb to eql_v2.encrypted
2225
--
@@ -30,16 +33,19 @@ CREATE CAST (jsonb AS public.eql_v2_encrypted)
3033
--
3134

3235
CREATE FUNCTION eql_v2.to_encrypted(data text)
33-
RETURNS public.eql_v2_encrypted AS $$
36+
RETURNS public.eql_v2_encrypted
37+
IMMUTABLE STRICT PARALLEL SAFE
38+
AS $$
3439
BEGIN
3540
IF data IS NULL THEN
3641
RETURN NULL;
3742
END IF;
3843

39-
RETURN ROW(data::jsonb)::public.eql_v2_encrypted;
44+
RETURN eql_v2.to_encrypted(data::jsonb);
4045
END;
4146
$$ LANGUAGE plpgsql;
4247

48+
4349
--
4450
-- Cast text to eql_v2.encrypted
4551
--

src/operators/operator_class_test.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,49 @@ DO $$
152152
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"abc\"}")');
153153
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"def\"}")');
154154
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"ghi\"}")');
155+
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"jkl\"}")');
156+
INSERT INTO encrypted (e) VALUES ('("{\"hm\": \"mno\"}")');
155157

158+
-- Literal row type type thing
156159
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''("{\"hm\": \"abc\"}")'';' into result;
157160

161+
IF position('Index Only Scan using encrypted' in result) > 0 THEN
162+
ASSERT true;
163+
ELSE
164+
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
165+
END IF;
166+
167+
-- Cast to jsonb to eql_v2_encrypted
168+
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''{"hm": "abc"}''::jsonb::eql_v2_encrypted;' into result;
169+
170+
IF position('Index Only Scan using encrypted' in result) > 0 THEN
171+
ASSERT true;
172+
ELSE
173+
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
174+
END IF;
175+
176+
-- Cast to text to eql_v2_encrypted
177+
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = ''{"hm": "abc"}''::text::eql_v2_encrypted;' into result;
178+
179+
IF position('Index Only Scan using encrypted' in result) > 0 THEN
180+
ASSERT true;
181+
ELSE
182+
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
183+
END IF;
184+
185+
-- Use to_encrypted with jsonb
186+
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = eql_v2.to_encrypted(''{"hm": "abc"}''::jsonb);' into result;
187+
188+
IF position('Index Only Scan using encrypted' in result) > 0 THEN
189+
ASSERT true;
190+
ELSE
191+
RAISE EXCEPTION 'Expected Index Only Scan: %', result;
192+
END IF;
193+
194+
-- Use to_encrypted with text
195+
EXECUTE 'EXPLAIN ANALYZE SELECT e::jsonb FROM encrypted WHERE e = eql_v2.to_encrypted(''{"hm": "abc"}'');' into result;
196+
197+
158198
IF position('Index Only Scan using encrypted' in result) > 0 THEN
159199
ASSERT true;
160200
ELSE

src/operators/order_by.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-- REQUIRE: src/encrypted/types.sql
22
-- REQUIRE: src/ore_block_u64_8_256/types.sql
33
-- REQUIRE: src/ore_block_u64_8_256/functions.sql
4-
-- REQUIRE: src/ore_block_u64_8_256/operators.sql
54
-- REQUIRE: src/ore_cllw_u64_8/types.sql
65
-- REQUIRE: src/ore_cllw_u64_8/functions.sql
76

0 commit comments

Comments
 (0)