Skip to content

Commit f4ea5ec

Browse files
tobyhedeclaude
andcommitted
docs(operators): complete Phase 2 - document JSONB and support functions
Add comprehensive Doxygen documentation to remaining operator files: JSONB field accessor operators: - -> (field accessor, 3 overloads: text, encrypted, integer) - ->> (text-returning accessor, 2 overloads) - @> (contains operator for ste_vec) - <@ (contained-by operator, reverse of @>) Comparison support functions: - compare.sql: Core comparison with ORE priority cascade - order_by.sql: ORE term extraction for ORDER BY clauses - operator_class.sql: Btree operator family/class definitions All files now include: - @brief descriptions explaining operator purpose - @param/@return type documentation - @example usage demonstrations - @note for important implementation details - @see cross-references to related functions Phase 2 (Core Modules - Operators) now complete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9f75204 commit f4ea5ec

File tree

7 files changed

+158
-52
lines changed

7 files changed

+158
-52
lines changed

src/operators/->.sql

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
21
-- REQUIRE: src/schema.sql
32
-- REQUIRE: src/encrypted/types.sql
43
-- REQUIRE: src/encrypted/functions.sql
54

6-
7-
--
8-
-- The -> operator returns an encrypted matching the provided selector
9-
--
10-
-- Encyprted JSON is represented as an array of `eql_v2_encrypted`.
11-
-- Each `eql_v2_encrypted` value has a selector, ciphertext, and an index term
12-
--
13-
-- {
14-
-- "sv": [ {"c": "", "s": "", "b3": "" } ]
15-
-- }
16-
--
17-
-- Note on oeprator resolution:
18-
-- Assignment casts are considered for operator resolution (see PostgreSQL docs),
19-
-- the system may pick the "more specific" one, which is the one with both arguments of the same type.
20-
--
21-
-- This means that to use the text operator, the parameter will need to be cast to text
22-
--
5+
--! @brief JSONB field accessor operator for encrypted values (->)
6+
--!
7+
--! Implements the -> operator to access fields/elements from encrypted JSONB data.
8+
--! Returns encrypted value matching the provided selector without decryption.
9+
--!
10+
--! Encrypted JSON is represented as an array of eql_v2_encrypted values in the ste_vec format.
11+
--! Each element has a selector, ciphertext, and index terms:
12+
--! {"sv": [{"c": "", "s": "", "b3": ""}]}
13+
--!
14+
--! Provides three overloads:
15+
--! - (eql_v2_encrypted, text) - Field name selector
16+
--! - (eql_v2_encrypted, eql_v2_encrypted) - Encrypted selector
17+
--! - (eql_v2_encrypted, integer) - Array index selector (0-based)
18+
--!
19+
--! @note Operator resolution: Assignment casts are considered (PostgreSQL standard behavior).
20+
--! To use text selector, parameter may need explicit cast to text.
21+
--!
22+
--! @see eql_v2.ste_vec
23+
--! @see eql_v2.selector
24+
--! @see eql_v2."->>"
25+
26+
--! @brief -> operator with text selector
27+
--! @param e eql_v2_encrypted Encrypted JSONB data
28+
--! @param selector text Field name to extract
29+
--! @return eql_v2_encrypted Encrypted value at selector
30+
--! @example
31+
--! SELECT encrypted_json -> 'field_name' FROM table;
2332
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector text)
2433
RETURNS eql_v2_encrypted
2534
IMMUTABLE STRICT PARALLEL SAFE
@@ -58,7 +67,11 @@ CREATE OPERATOR ->(
5867

5968
---------------------------------------------------
6069

61-
70+
--! @brief -> operator with encrypted selector
71+
--! @param e eql_v2_encrypted Encrypted JSONB data
72+
--! @param selector eql_v2_encrypted Encrypted field selector
73+
--! @return eql_v2_encrypted Encrypted value at selector
74+
--! @see eql_v2."->"(eql_v2_encrypted, text)
6275
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector eql_v2_encrypted)
6376
RETURNS eql_v2_encrypted
6477
IMMUTABLE STRICT PARALLEL SAFE
@@ -79,7 +92,14 @@ CREATE OPERATOR ->(
7992

8093
---------------------------------------------------
8194

82-
95+
--! @brief -> operator with integer array index
96+
--! @param e eql_v2_encrypted Encrypted array data
97+
--! @param selector integer Array index (0-based, JSONB convention)
98+
--! @return eql_v2_encrypted Encrypted value at array index
99+
--! @note Array index is 0-based (JSONB standard) despite PostgreSQL arrays being 1-based
100+
--! @example
101+
--! SELECT encrypted_array -> 0 FROM table;
102+
--! @see eql_v2.is_ste_vec_array
83103
CREATE FUNCTION eql_v2."->"(e eql_v2_encrypted, selector integer)
84104
RETURNS eql_v2_encrypted
85105
IMMUTABLE STRICT PARALLEL SAFE

src/operators/->>.sql

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
-- REQUIRE: src/encrypted/types.sql
33
-- REQUIRE: src/encrypted/functions.sql
44

5+
--! @brief JSONB field accessor operator returning text (->>)
6+
--!
7+
--! Implements the ->> operator to access fields/elements from encrypted JSONB data,
8+
--! returning the result as text (still encrypted). Text-returning version of -> operator.
9+
--!
10+
--! Provides two overloads:
11+
--! - (eql_v2_encrypted, text) - Field name selector
12+
--! - (eql_v2_encrypted, eql_v2_encrypted) - Encrypted selector
13+
--!
14+
--! @see eql_v2."->"
15+
--! @see eql_v2.selector
516

6-
17+
--! @brief ->> operator with text selector
18+
--! @param e eql_v2_encrypted Encrypted JSONB data
19+
--! @param selector text Field name to extract
20+
--! @return text Encrypted value at selector as text
21+
--! @example
22+
--! SELECT encrypted_json ->> 'field_name' FROM table;
723
CREATE FUNCTION eql_v2."->>"(e eql_v2_encrypted, selector text)
824
RETURNS text
925
IMMUTABLE STRICT PARALLEL SAFE
@@ -28,7 +44,11 @@ CREATE OPERATOR ->> (
2844

2945
---------------------------------------------------
3046

31-
47+
--! @brief ->> operator with encrypted selector
48+
--! @param e eql_v2_encrypted Encrypted JSONB data
49+
--! @param selector eql_v2_encrypted Encrypted field selector
50+
--! @return text Encrypted value at selector as text
51+
--! @see eql_v2."->>"(eql_v2_encrypted, text)
3252
CREATE FUNCTION eql_v2."->>"(e eql_v2_encrypted, selector eql_v2_encrypted)
3353
RETURNS text
3454
IMMUTABLE STRICT PARALLEL SAFE

src/operators/<@.sql

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@
22
-- REQUIRE: src/encrypted/types.sql
33
-- REQUIRE: src/ste_vec/functions.sql
44

5-
5+
--! @brief Contained-by operator for encrypted values (<@)
6+
--!
7+
--! Implements the <@ (contained-by) operator for testing if left encrypted value
8+
--! is contained by the right encrypted value. Uses ste_vec (secure tree encoding vector)
9+
--! index terms for containment testing without decryption. Reverse of @> operator.
10+
--!
11+
--! Primarily used for encrypted array or set containment queries.
12+
--!
13+
--! @param a eql_v2_encrypted Left operand (contained value)
14+
--! @param b eql_v2_encrypted Right operand (container)
15+
--! @return Boolean True if a is contained by b
16+
--!
17+
--! @example
18+
--! -- Check if value is contained in encrypted array
19+
--! SELECT * FROM documents
20+
--! WHERE '["security"]'::jsonb::eql_v2_encrypted <@ encrypted_tags;
21+
--!
22+
--! @note Requires ste_vec index configuration
23+
--! @see eql_v2.ste_vec_contains
24+
--! @see eql_v2.\"@>\"
25+
--! @see eql_v2.add_search_config
626

727
CREATE FUNCTION eql_v2."<@"(a eql_v2_encrypted, b eql_v2_encrypted)
828
RETURNS boolean AS $$

src/operators/@>.sql

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,26 @@
22
-- REQUIRE: src/encrypted/types.sql
33
-- REQUIRE: src/ste_vec/functions.sql
44

5-
6-
5+
--! @brief Contains operator for encrypted values (@>)
6+
--!
7+
--! Implements the @> (contains) operator for testing if left encrypted value
8+
--! contains the right encrypted value. Uses ste_vec (secure tree encoding vector)
9+
--! index terms for containment testing without decryption.
10+
--!
11+
--! Primarily used for encrypted array or set containment queries.
12+
--!
13+
--! @param a eql_v2_encrypted Left operand (container)
14+
--! @param b eql_v2_encrypted Right operand (contained value)
15+
--! @return Boolean True if a contains b
16+
--!
17+
--! @example
18+
--! -- Check if encrypted array contains value
19+
--! SELECT * FROM documents
20+
--! WHERE encrypted_tags @> '["security"]'::jsonb::eql_v2_encrypted;
21+
--!
22+
--! @note Requires ste_vec index configuration
23+
--! @see eql_v2.ste_vec_contains
24+
--! @see eql_v2.add_search_config
725
CREATE FUNCTION eql_v2."@>"(a eql_v2_encrypted, b eql_v2_encrypted)
826
RETURNS boolean AS $$
927
SELECT eql_v2.ste_vec_contains(a, b)

src/operators/compare.sql

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,31 @@
1717
-- REQUIRE: src/ore_cllw_var_8/types.sql
1818
-- REQUIRE: src/ore_cllw_var_8/functions.sql
1919

20-
21-
--
22-
-- Compare two eql_v2_encrypted values
23-
--
24-
-- Function is used to implement all operators required for btree indexing"
25-
-- - `<`
26-
-- - `<=`
27-
-- - `=`
28-
-- - `>=`
29-
-- - `>`
30-
--
31-
--
32-
-- Index terms are checked in the following order:
33-
-- - `ore_block_u64_8_256`
34-
-- - `ore_cllw_u64_8`
35-
-- - `ore_cllw_var_8`
36-
-- - `hmac_256`
37-
-- - `blake3`
38-
--
39-
-- The first index term present for both values is used for comparsion.
40-
--
41-
-- If no index terms are found, the encrypted data is compared as a jsonb literal.
42-
-- Btree index must have a consistent ordering for a given state, without this text fallback, database errors with "lock BufferContent is not held"
43-
--
20+
--! @brief Core comparison function for encrypted values
21+
--!
22+
--! Compares two encrypted values using their index terms without decryption.
23+
--! This function implements all comparison operators required for btree indexing
24+
--! (<, <=, =, >=, >).
25+
--!
26+
--! Index terms are checked in the following priority order:
27+
--! 1. ore_block_u64_8_256 (Order-Revealing Encryption)
28+
--! 2. ore_cllw_u64_8 (Order-Revealing Encryption)
29+
--! 3. ore_cllw_var_8 (Order-Revealing Encryption)
30+
--! 4. hmac_256 (Hash-based equality)
31+
--! 5. blake3 (Hash-based equality)
32+
--!
33+
--! The first index term type present in both values is used for comparison.
34+
--! If no matching index terms are found, falls back to JSONB literal comparison
35+
--! to ensure consistent ordering (required for btree correctness).
36+
--!
37+
--! @param a eql_v2_encrypted First encrypted value
38+
--! @param b eql_v2_encrypted Second encrypted value
39+
--! @return integer -1 if a < b, 0 if a = b, 1 if a > b
40+
--!
41+
--! @note Literal fallback prevents "lock BufferContent is not held" errors
42+
--! @see eql_v2.compare_ore_block_u64_8_256
43+
--! @see eql_v2.compare_blake3
44+
--! @see eql_v2.compare_hmac_256
4445
CREATE FUNCTION eql_v2.compare(a eql_v2_encrypted, b eql_v2_encrypted)
4546
RETURNS integer
4647
IMMUTABLE STRICT PARALLEL SAFE

src/operators/operator_class.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
-- REQUIRE: src/operators/>=.sql
99
-- REQUIRE: src/operators/>.sql
1010

11+
--! @brief PostgreSQL operator class definitions for encrypted value indexing
12+
--!
13+
--! Defines the operator family and operator class required for btree indexing
14+
--! of encrypted values. This enables PostgreSQL to use encrypted columns in:
15+
--! - CREATE INDEX statements
16+
--! - ORDER BY clauses
17+
--! - Range queries
18+
--! - Primary key constraints
19+
--!
20+
--! The operator class maps the five comparison operators (<, <=, =, >=, >)
21+
--! to the eql_v2.compare() support function for btree index operations.
22+
--!
23+
--! @note This is the default operator class for eql_v2_encrypted type
24+
--! @see eql_v2.compare
25+
--! @see PostgreSQL documentation on operator classes
1126

1227
--------------------
1328

src/operators/order_by.sql

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
-- REQUIRE: src/ore_cllw_u64_8/types.sql
55
-- REQUIRE: src/ore_cllw_u64_8/functions.sql
66

7-
-- order_by function for ordering when operators are not available.
8-
--
9-
--
7+
--! @brief Extract ORE index term for ordering encrypted values
8+
--!
9+
--! Helper function that extracts the ore_block_u64_8_256 index term from an encrypted value
10+
--! for use in ORDER BY clauses when comparison operators are not appropriate or available.
11+
--!
12+
--! @param a eql_v2_encrypted Encrypted value to extract order term from
13+
--! @return eql_v2.ore_block_u64_8_256 ORE index term for ordering
14+
--!
15+
--! @example
16+
--! -- Order encrypted values without using comparison operators
17+
--! SELECT * FROM users ORDER BY eql_v2.order_by(encrypted_age);
18+
--!
19+
--! @note Requires 'ore' index configuration on the column
20+
--! @see eql_v2.ore_block_u64_8_256
21+
--! @see eql_v2.add_search_config
1022
CREATE FUNCTION eql_v2.order_by(a eql_v2_encrypted)
1123
RETURNS eql_v2.ore_block_u64_8_256
1224
IMMUTABLE STRICT PARALLEL SAFE

0 commit comments

Comments
 (0)