-
Notifications
You must be signed in to change notification settings - Fork 0
test(bench): cover GROUP BY / JOIN / DISTINCT on encrypted columns #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coderdan
wants to merge
3
commits into
main
Choose a base branch
from
test/bench-group-by-join-distinct
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
411ec59
test(bench): cover GROUP BY / JOIN / DISTINCT plan and timing on encr…
coderdan 7326fc2
test(bench): correct hash-strategy regression numbers — fast-path, no…
coderdan 02b539e
test(bench): cover GROUP BY on JSON field extracted from encrypted co…
coderdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| -- Fixture: bench_json_data.sql | ||
| -- | ||
| -- Builds the bench_json table by overlaying the existing `bench` rows | ||
| -- (loaded by the bench_data.sql fixture, which must run first) and adding | ||
| -- `hm` to the $.hello sv element of each row. This mirrors what | ||
| -- `@cipherstash/protect` would produce for a JSONB column where the | ||
| -- $.hello path is configured with a `unique` index — without that, the | ||
| -- field-level sv element carries only OPE terms (`ocv`) and field-level | ||
| -- GROUP BY / DISTINCT / hash joins on the extracted value raise: | ||
| -- | ||
| -- ERROR: Cannot hash eql_v2_encrypted value: no hmac_256 index term | ||
| -- found. Configure a `unique` index on the column for hash | ||
| -- operations (GROUP BY, DISTINCT, hash joins). | ||
| -- | ||
| -- The synthesised `hm` is the field's existing `ocv` hex string (already | ||
| -- deterministic over the plaintext at that selector) so it serves as a | ||
| -- valid equality token without us inventing a separate one. The shape | ||
| -- matches production: `c`, `s`, `ocv`, `hm` at the sv element level. | ||
| -- | ||
| -- Selector cheatsheet (matches Selectors:: in tests/sqlx/src/selectors.rs): | ||
| -- bca213de9ccce676fa849ff9c4807963 → $ (root, has b3 here today) | ||
| -- a7cea93975ed8c01f861ccb6bd082784 → $.hello (we add `hm` here) | ||
| -- 2517068c0d1f9d4d41d2c666211f785e → $.n (left alone) | ||
|
|
||
| CREATE TABLE IF NOT EXISTS bench_json ( | ||
| id bigserial PRIMARY KEY, | ||
| e eql_v2_encrypted | ||
| ); | ||
|
|
||
| INSERT INTO bench_json (e) | ||
| SELECT (jsonb_build_object( | ||
| 'c', (encrypted_text).data ->> 'c', | ||
| 'i', (encrypted_text).data -> 'i', | ||
| 'v', 2, | ||
| 'hm', (encrypted_text).data ->> 'hm', | ||
| 'sv', ( | ||
| SELECT jsonb_agg( | ||
| CASE | ||
| WHEN elem ->> 's' = 'a7cea93975ed8c01f861ccb6bd082784' | ||
| THEN elem || jsonb_build_object('hm', elem ->> 'ocv') | ||
| ELSE elem | ||
| END | ||
| ) | ||
| FROM jsonb_array_elements((encrypted_text).data -> 'sv') elem | ||
| ) | ||
| )) :: eql_v2_encrypted | ||
| FROM bench; | ||
|
|
||
| ANALYZE bench_json; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join assertion currently rejects a documented acceptable
Hash JoinplanThe test description allows either
Hash Joinor index-driven nested-loop plans, but the assertion only accepts index usage. This can fail valid plans.Suggested patch
async fn join_on_encrypted_uses_hmac_index(pool: PgPool) -> Result<()> { let sql = "SELECT count(*) FROM bench a JOIN bench b \ ON a.encrypted_text = b.encrypted_text"; - assert_uses_index(&pool, sql, BENCH_TEXT_HMAC_IDX).await?; + let plan = explain_query(&pool, sql).await?; + assert!( + plan.contains("Hash Join") || plan.contains(BENCH_TEXT_HMAC_IDX), + "Expected JOIN to use Hash Join or {}. EXPLAIN output:\n{}", + BENCH_TEXT_HMAC_IDX, + plan + ); Ok(()) }📝 Committable suggestion
🤖 Prompt for AI Agents