Skip to content

Commit 7b7d74c

Browse files
authored
Merge pull request #154 from cipherstash/calvinbrewer-patch-1
Update searchable-encryption-postgres.md
2 parents 99aea91 + dab1070 commit 7b7d74c

File tree

1 file changed

+2
-70
lines changed

1 file changed

+2
-70
lines changed

docs/reference/searchable-encryption-postgres.md

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -257,77 +257,9 @@ For Supabase users, we provide a specific implementation guide. [Read more about
257257
- Handle encryption errors aggressively
258258
- Handle decryption errors gracefully
259259

260-
## Common use cases
260+
## Performance optimization
261261

262-
### Combining multiple search conditions
263-
264-
```typescript
265-
// Search for users with specific email domain and age range
266-
const terms = await protectClient.createSearchTerms([
267-
{
268-
value: 'example.com',
269-
column: schema.email,
270-
table: schema,
271-
returnType: 'composite-literal'
272-
},
273-
{
274-
value: '18',
275-
column: schema.age,
276-
table: schema,
277-
returnType: 'composite-literal'
278-
}
279-
])
280-
281-
if (terms.failure) {
282-
// Handle the error
283-
}
284-
285-
const result = await client.query(
286-
'SELECT * FROM users WHERE email_encrypted LIKE $1 AND eql_v2.ore_block_u64_8_256(age_encrypted) > $2',
287-
[terms.data[0], terms.data[1]]
288-
)
289-
```
290-
291-
### Performance optimization
292-
293-
1. **Use appropriate indexes**
294-
```sql
295-
CREATE INDEX idx_users_email ON users USING btree (email_encrypted);
296-
CREATE INDEX idx_users_age ON users USING btree (eql_v2.ore_block_u64_8_256(age_encrypted));
297-
```
298-
299-
2. **Cache frequently accessed data**
300-
```typescript
301-
// Example using Redis
302-
const cacheKey = `user:${userId}`
303-
let user = await redis.get(cacheKey)
304-
305-
if (!user) {
306-
const result = await client.query('SELECT * FROM users WHERE id = $1', [userId])
307-
user = result.rows[0]
308-
await redis.set(cacheKey, JSON.stringify(user), 'EX', 3600)
309-
}
310-
```
311-
312-
### Common pitfalls to avoid
313-
314-
1. **Don't mix encrypted and unencrypted data when data is encrypted**
315-
```sql
316-
-- ❌ Wrong
317-
SELECT * FROM users WHERE email = 'user@example.com'
318-
319-
-- ✅ Correct
320-
SELECT * FROM users WHERE email_encrypted = $1
321-
```
322-
323-
2. **Don't use ORDER BY directly on encrypted columns**
324-
```sql
325-
-- ❌ Wrong
326-
SELECT * FROM users ORDER BY email_encrypted
327-
328-
-- ✅ Correct
329-
SELECT * FROM users ORDER BY eql_v2.ore_block_u64_8_256(age_encrypted)
330-
```
262+
TODO: make docs for creating Postgres Indexes on columns that require searches. At the moment EQL v2 doesn't support creating indexes while also using the out-of-the-box operator and operator families. The solution is to create an index using the EQL functions and then using the EQL functions directly in your SQL statments, which isn't the best experience.
331263

332264
### Didn't find what you wanted?
333265

0 commit comments

Comments
 (0)