Skip to content

Commit b5e840f

Browse files
committed
docs(json): add GIN index documentation for JSONB containment
- Add "Indexed Containment Queries" subsection after containment operators - Add "GIN-Indexable Functions" section with jsonb_array, jsonb_contains, and jsonb_contained_by function documentation - Add cross-references to database-indexes.md GIN section
1 parent 1a8fa97 commit b5e840f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/reference/json-support.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ WHERE jsonb_column @> '{"top":{"nested":["a"]}}';
102102

103103
**Note:** The `@>` operator checks if the left value contains the right value. The `<@` operator checks the reverse (if left is contained in right).
104104

105+
#### Indexed Containment Queries
106+
107+
For better performance on large tables, create a GIN index and use the `jsonb_array()` function:
108+
109+
```sql
110+
-- Create GIN index
111+
CREATE INDEX idx_encrypted_jsonb_gin
112+
ON examples USING GIN (eql_v2.jsonb_array(encrypted_json));
113+
ANALYZE examples;
114+
115+
-- Query using the GIN index
116+
SELECT * FROM examples
117+
WHERE eql_v2.jsonb_array(encrypted_json) @>
118+
eql_v2.jsonb_array(search_value::eql_v2_encrypted);
119+
```
120+
121+
See [GIN Indexes for JSONB Containment](./database-indexes.md#gin-indexes-for-jsonb-containment) for complete setup instructions.
122+
105123
### Field extraction (`jsonb_path_query`)
106124

107125
Extract fields from encrypted JSONB using selector hashes. Selectors are generated during encryption and identify specific JSON paths.
@@ -243,6 +261,22 @@ GROUP BY eql_v2.jsonb_path_query_first(encrypted_json, 'color_selector');
243261
- **`eql_v2.selector(val eql_v2_encrypted) RETURNS text`**
244262
- Extracts the selector hash from an encrypted value
245263

264+
### GIN-Indexable Functions
265+
266+
These functions enable efficient GIN-indexed containment queries. See [GIN Indexes for JSONB Containment](./database-indexes.md#gin-indexes-for-jsonb-containment) for index setup.
267+
268+
- **`eql_v2.jsonb_array(val eql_v2_encrypted) RETURNS jsonb[]`**
269+
- Extracts encrypted JSONB as native PostgreSQL jsonb array for GIN indexing
270+
- Create GIN indexes on this function for indexed containment queries
271+
272+
- **`eql_v2.jsonb_contains(a eql_v2_encrypted, b eql_v2_encrypted) RETURNS boolean`**
273+
- GIN-indexed containment check: returns true if a contains b
274+
- Alternative to `jsonb_array(a) @> jsonb_array(b)`
275+
276+
- **`eql_v2.jsonb_contained_by(a eql_v2_encrypted, b eql_v2_encrypted) RETURNS boolean`**
277+
- GIN-indexed reverse containment: returns true if a is contained by b
278+
- Alternative to `jsonb_array(a) <@ jsonb_array(b)`
279+
246280
### Aggregate Functions
247281

248282
- **`eql_v2.grouped_value(jsonb) RETURNS jsonb`**

0 commit comments

Comments
 (0)