Skip to content

Conversation

@tobyhede
Copy link
Contributor

Summary

  • Add overloaded variants of jsonb_contains and jsonb_contained_by that accept mixed types (eql_v2_encrypted, jsonb)
  • Enables queries where one operand is an encrypted column and the other is plain JSONB
  • All existing tests pass

New Functions

Function Parameters
jsonb_contains (eql_v2_encrypted, jsonb)
jsonb_contains (jsonb, eql_v2_encrypted)
jsonb_contained_by (eql_v2_encrypted, jsonb)
jsonb_contained_by (jsonb, eql_v2_encrypted)

Test plan

  • Build succeeds
  • All existing SQLx tests pass (262 tests)

tobyhede and others added 30 commits June 24, 2025 17:08
Enable indexing on eql_v2_encrypted columns without needing function helpers
…on-workflow

EQL: remove zero-downtime migration workflow
…data

jsonb accessors return with metadata
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
PR_BYPASS: out of date docs with new customer onboardings beginning
Co-authored-by: Lindsay Holmwood <[email protected]>
tobyhede and others added 28 commits December 11, 2025 18:57
Verify that containment queries use Seq Scan before index creation
and switch to using the GIN index after creation. Exports explain_query
and assert_uses_seq_scan helpers to support this test pattern.
SQL examples using undefined 'search_value' variable would cause
"column does not exist" errors if copied verbatim. Changed to $1
placeholder to indicate query parameter usage.

Fixes common issue identified by dual-verification review.
Documentation fixes (from cross-checked verification):
- E1-1: Add integer -> operator documentation for array indexing
- E1-2: Clarify sv/ste_vec is a storage field, not an index term type
- E1-3: Correct ->> return type from "ciphertext" to "encrypted value as text"
- E1-4: Document ste_vec(jsonb) overload alongside ste_vec(eql_v2_encrypted)
- E1-5: Add note about -> vs ->> operator asymmetry (integer index support)

Rust lint fixes:
- Apply cargo fmt formatting to lib.rs and containment_with_index_tests.rs
feat(ste_vec): add GIN-indexable containment using jsonb arrays
Add overloaded variants of jsonb_contains and jsonb_contained_by
that accept mixed types (eql_v2_encrypted, jsonb) to support queries
where one operand is an encrypted column and the other is plain JSONB.

New functions:
- jsonb_contains(eql_v2_encrypted, jsonb)
- jsonb_contains(jsonb, eql_v2_encrypted)
- jsonb_contained_by(eql_v2_encrypted, jsonb)
- jsonb_contained_by(jsonb, eql_v2_encrypted)
Update get_ste_vec_encrypted and add get_ste_vec_sv_element to return
serde_json::Value instead of String. This:
- Aligns Postgres jsonb type with Rust serde_json::Value
- Avoids double-quoting issues with embedded apostrophes
- Allows programmatic JSON inspection without extra parsing
- Callers use .to_string() when a literal is needed

Updated existing tests to use ::jsonb cast instead of ::eql_v2_encrypted
since the helper now returns just the .data field (JSONB portion).
These tests expose a bug in jsonb_contains - partial containment
(searching for a single sv element) doesn't work correctly.
Tests verify:
- Single sv element should be found in its parent row
- GIN index should be used for partial containment queries
- Element should match exactly one row
Tests verify that containment works with prepared statements using
sqlx .bind() in addition to literal string substitution.
Tests verify jsonb_contains(encrypted, jsonb) and
jsonb_contained_by(jsonb, encrypted) work with partial
containment (single sv elements).
Replace with simpler literal-based tests that don't use subqueries.
The new tests are clearer and test with both literal values and
parameterized statements.
Consolidate from 17 tests to 4 base tests. Removes 13 redundant
jsonb_contains(encrypted, jsonb) variations. Next commit will
add focused tests covering all 6 operator/type combinations.
Enables encrypted-to-encrypted containment tests by providing
a helper to fetch two distinct encrypted values from the same table.
Final cleanup: 10 focused tests covering all 6 operator/type
combinations plus 2 sanity tests and 2 helper validation tests.

Coverage matrix complete:
- jsonb_contains(encrypted, jsonb_param) ✓
- jsonb_contains(encrypted, encrypted) ✓
- jsonb_contains(jsonb_param, encrypted) ✓
- jsonb_contained_by(encrypted, jsonb_param) ✓
- jsonb_contained_by(encrypted, encrypted) ✓
- jsonb_contained_by(jsonb_param, encrypted) ✓
- Remove unnecessary .to_string() calls in format args
- Remove redundant serde_json import
@tobyhede tobyhede closed this Dec 12, 2025
@tobyhede tobyhede force-pushed the jsonb-contains-variants branch from eb02139 to 66fad9f Compare December 12, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants