Repository navigation
Conversation
…ts no token A match filter was built by two rules. For text that cuts no token, such as an empty string or one letter, TextSearch and TextSearchOre stored the empty filter and TextMatch refused the value. The rule depended on which other terms the type had. Now every type stores the empty filter, which is what Stack Encrypt derives for a stored value. A match query of such text is still refused, and no query finds a stored empty filter, so no query changes. SearchBloomFilter existed only to allow the empty filter, and no release has it. It is removed, and the three types store a BloomFilter. The query visitor now makes its own check for a filter with no positions: it relied on the stored visitor's refusal before. A Go program got ErrTerm when it stored such text in a TextMatch field. The value is now stored, and the Go changelog says so. Refs #2040
|
| Name | Type |
|---|---|
| @cipherstash/eql | Minor |
| stash | Patch |
| @cipherstash/stack-prisma | Patch |
| @cipherstash/basic-example | Patch |
| @cipherstash/e2e | Patch |
| @cipherstash/prisma-example | Patch |
| @cipherstash/stack-drizzle | Patch |
| @cipherstash/stack-supabase | Patch |
| @cipherstash/stack | Patch |
| @cipherstash/wizard | Patch |
| @cipherstash/bench | Patch |
| @cipherstash/test-kit | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
Text that cuts no token is stored with the empty filter in TextMatch, as in TextSearch. Open question 32 is answered, and the change to the Rust types is G8 (#2054).
coderdan
left a comment
There was a problem hiding this comment.
Automated review at medium effort, of commit f1b0cd227. It reported three findings. I checked each one against the code, and all three are correct. The inline comments give each finding and what I found.
One finding is important: a claim in the docs is wider than what the SQL does. Two are corrections to the Go docs.
The review also checked these and found no problem:
- No reference to
SearchBloomFilter,SearchMatchVisitororstored_term_newtyperemains. - The EQL v3 types derive no
EncryptTarget, so the change toMatchVisitordoes not reach them. - The two new rows in the PostgreSQL test change no expected result.
| /// shorter than a 3-gram with no two-letter word, such as one letter. Such | ||
| /// text is stored as the empty filter, as Stack Encrypt stores it, in every | ||
| /// type. No `@@` query finds an empty filter, because a query's filter is | ||
| /// never empty ([`QueryMatchVisitor`]). |
There was a problem hiding this comment.
Important. "No @@ query finds an empty filter" is true only of a query this crate builds.
A TextMatch column can now contain "bf": []. A hand-built eql_v4.query_text_match operand with "bf": [] finds exactly those rows:
- The domain's CHECK asks only that
bfis present (packages/eql/src/v3/scalars/text/query_text_types.sql:42). matchesreturns true when the stored filter and the query's filter are both empty (packages/eql/src/v3/scalars/text/query_text_match_functions.sql:23).
The search domains differ. query_text_search raises on an empty bf (require_query_term, packages/eql/src/v3/scalars/functions.sql:92).
I checked the SQL, and the finding is correct. Before this change no producer stored an empty filter in a TextMatch column, so such an operand found no row.
Two fixes are possible:
- Narrow the claim in the rustdoc, the README and the changeset to queries that
eql-bindingsbuilds, and say what a hand-built operand finds. - Make the v4
query_text_matchpath raise on an emptybf, as the search domains do. That changes the generated SQL bundle.
This pull request takes fix 1. Fix 2 is a change to the SQL bundle, so it needs its own decision.
There was a problem hiding this comment.
Fixed in 6845026, with the first fix. The rustdoc, the README and the changeset now say that no query this crate builds finds an empty filter. They also say what a hand-built query_text_match operand with "bf": [] finds: the TextMatch values that store the empty filter, and no other value.
The second fix is not in this pull request. Making query_text_match raise on an empty bf changes the generated SQL bundle, so it needs its own decision. The pull request description records this under "Review notes".
| A `TextMatch` field indexes the 3-grams of its text, and each two-letter word as a whole word. A 3-gram is a run of three characters, such as "mik" in "Mike". So a two-letter surname such as "Ng" is stored, and the query "ng" finds it. A query asks for its two-letter words only when the whole query is one two-letter word. So the query "Mike Ng" asks for its 3-grams alone, and finds "Mike Nguyen" too. | ||
| A `TextMatch` field refuses text that cuts no token, such as an empty string or one letter; its query refuses such text too. | ||
| A `TextSearch` field stores such text with an empty match filter, so its `Eq`, `Lt`, `Lte`, `Gt` and `Gte` queries find it and no `Matches` query does; those queries take such text too, and its `Matches` query refuses it. | ||
| A `TextMatch` field stores text that cuts no token, such as an empty string or one letter, with an empty match filter. No `Matches` query finds that value, and a `Matches` query of such text is refused. |
There was a problem hiding this comment.
Nit. Line 108 of this file still says the opposite.
Line 108, in the section on the match index, reads: "An EQL TextMatch field is stricter: see below." This line now says a TextMatch field stores such text. The matching sentence in languages/golang/encrypt/README.md was updated. Line 108 here was missed.
I checked the file, and the finding is correct. Fix: line 108 says that a TextMatch field follows the same rule.
There was a problem hiding this comment.
Fixed in 6845026. Line 108 now says that an EQL TextMatch field follows the same rule.
|
|
||
| ### Changed | ||
|
|
||
| - **A `TextMatch` field stores text that cuts no token.** Such text is an |
There was a problem hiding this comment.
Nit. This entry describes a break, and it is under "Changed".
The header of this file says "every break is listed under Breaking". The entry says a program that relied on the refusal has to check the text itself. That is a break for such a program. The [Unreleased] section already has a "Breaking" heading.
I checked the file, and the finding is correct. One earlier entry of the same kind is under "Added": in rc.2, "Ng" began to store into a TextMatch field where it was refused before. The header's rule is the stricter one, so the fix moves this entry under "Breaking".
There was a problem hiding this comment.
Fixed in 6845026. The entry is now the first one under "Breaking", and the line about a program that relied on the refusal comes first.
The docs said that no @@ query finds an empty filter. That is true of a query eql-bindings builds, because it refuses a query with no token. A query_text_match operand built by hand with an empty filter does find the TextMatch values that store one: the search query domains raise on such an operand, and query_text_match does not. The stashgen README still called a TextMatch field stricter than a match index. The Go changelog entry describes a break, so it moves under Breaking.
A query that Stack Encrypt builds never has an empty filter. A query_text_match operand built by hand with one finds the TextMatch values that store the empty filter. The review of #2054 found this. Open question 33 asks whether query_text_match raises on such an operand, as the search query domains do.
Summary
EQL (Encrypt Query Language) is the SQL library that stores and queries encrypted values in PostgreSQL. Its
TextMatchtype stores a match filter, thebfterm. The@@operator searches that filter. The filter is built from tokens: each run of three characters in the text, and each two-letter word.Some text cuts no token: an empty string, one letter, or separators alone. Before this change,
TextMatchrefused to store such text.TextSearchandTextSearchOrestored it with an empty filter. So the same filter followed two rules, by type.Now all three types store such text with the empty filter,
"bf": []. A match filter is built the same way in every type. This is groundwork item G8 of the plan in #2040.No query changes. A match query of such text is still refused, so no query that
eql-bindingsbuilds finds a stored empty filter.Changes
eql-bindingsMatchVisitorno longer refuses match terms with no positions. It builds the empty filter.QueryMatchVisitornow refuses a query with no positions itself. It used to get that refusal fromMatchVisitor.v4::terms::SearchBloomFilterandSearchMatchVisitorare removed.TextSearchandTextSearchOrestore aBloomFilter, asTextMatchdoes.eql-codegenstored_term_newtypeis removed. Every stored filter isBloomFilter.v4/text.rsis regenerated.Go SDK
TextMatchfield stores such text. Before,EncryptreturnedErrTerm. The changelog has an entry under "Breaking" in[Unreleased].TestV4TextMatchStoresTextThatCutsNoToken.Docs
eql-bindingsREADME and changelog, the Go READMEs, and ADR 0002 state the one rule.Verification
Run locally on this branch:
eql-bindings,eql-codegenand the encryption test crate are clean:cargo fmt --check, clippy with-D warningsand rustdoc with-D warnings.eql-codegentests: 206 passed. They include the drift check of the generated Rust.eql-bindingstests with all features: 222 passed. Doc tests: 18 passed, 3 ignored.go test ./...over the module and its nested modules: all passed. The new test passed.Not run locally:
postgres_finds_two_letter_surnamesnow also inserts "A" and an empty string into aneql_v4_text_matchcolumn, and checks that no query finds them. CI is its first run.Related
Refs #2040.
Review notes
SearchBloomFilteris removed, not deprecated. No release ofeql-bindingshas thev4module, so no released code names the type. Its only purpose was to allow an empty filter.eql_v4.query_text_matchoperand with"bf": []finds theTextMatchvalues that store the empty filter, and no other value. The search query domains raise on such an operand, andquery_text_matchdoes not. The docs now say this. Makingquery_text_matchraise too is a change to the SQL bundle, so it is not in this pull request.packages/stack-encrypt/src/sem/mod.rs,match_term). Onlyeql-bindingsrefused it.TextSearch. The README and the Go changelog say so.@@between two stored values is not a query, and two stored empty filters match each other there. No producer builds that predicate. ADR 0002 already records this forTextSearch.