Skip to content

fix(eql-bindings): TextMatch stores the empty filter for text that cuts no token - #2054

Draft
coderdan wants to merge 2 commits into
nextfrom
fix/text-match-empty-filter
Draft

coderdan wants to merge 2 commits into
nextfrom
fix/text-match-empty-filter

Conversation

@coderdan

@coderdan coderdan commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

EQL (Encrypt Query Language) is the SQL library that stores and queries encrypted values in PostgreSQL. Its TextMatch type stores a match filter, the bf term. 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, TextMatch refused to store such text. TextSearch and TextSearchOre stored 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-bindings builds finds a stored empty filter.

Changes

eql-bindings

  • MatchVisitor no longer refuses match terms with no positions. It builds the empty filter.
  • QueryMatchVisitor now refuses a query with no positions itself. It used to get that refusal from MatchVisitor.
  • v4::terms::SearchBloomFilter and SearchMatchVisitor are removed. TextSearch and TextSearchOre store a BloomFilter, as TextMatch does.

eql-codegen

  • stored_term_newtype is removed. Every stored filter is BloomFilter.
  • v4/text.rs is regenerated.

Go SDK

  • A TextMatch field stores such text. Before, Encrypt returned ErrTerm. The changelog has an entry under "Breaking" in [Unreleased].
  • One new test: TestV4TextMatchStoresTextThatCutsNoToken.

Docs

  • The eql-bindings README and changelog, the Go READMEs, and ADR 0002 state the one rule.
  • Two pending changesets described the old rule. They now describe the new one.

Verification

Run locally on this branch:

  • Three checks over eql-bindings, eql-codegen and the encryption test crate are clean: cargo fmt --check, clippy with -D warnings and rustdoc with -D warnings.
  • eql-codegen tests: 206 passed. They include the drift check of the generated Rust.
  • eql-bindings tests with all features: 222 passed. Doc tests: 18 passed, 3 ignored.
  • Encryption test crate: 186 passed, 63 skipped. The skipped tests need PostgreSQL.
  • The generated TypeScript types and JSON Schemas were regenerated and compared with the committed files: no difference.
  • Go: all four guests rebuilt, then go test ./... over the module and its nested modules: all passed. The new test passed.

Not run locally:

  • The PostgreSQL tests. postgres_finds_two_letter_surnames now also inserts "A" and an empty string into an eql_v4_text_match column, and checks that no query finds them. CI is its first run.
  • The TypeScript suites. No TypeScript changes.

Related

Refs #2040.

Review notes

  • SearchBloomFilter is removed, not deprecated. No release of eql-bindings has the v4 module, so no released code names the type. Its only purpose was to allow an empty filter.
  • No new changeset. The change is to EQL v4 types that are not released yet. The two pending changesets that describe those types are corrected in place. The Go SDK has released the refusal, so the Go changelog has a new entry.
  • A hand-built query with an empty filter. An eql_v4.query_text_match operand with "bf": [] finds the TextMatch values that store the empty filter, and no other value. The search query domains raise on such an operand, and query_text_match does not. The docs now say this. Making query_text_match raise too is a change to the SQL bundle, so it is not in this pull request.
  • Where the refusal was. Stack Encrypt already stores the empty filter for such text (packages/stack-encrypt/src/sem/mod.rs, match_term). Only eql-bindings refused it.
  • What the empty filter reveals. It tells anyone who can read the column that the value cuts no token. That was already true of TextSearch. The README and the Go changelog say so.
  • A stored value against a stored value. @@ 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 for TextSearch.

…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
@changeset-bot

changeset-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6845026

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 12 packages
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

@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

coderdan added a commit that referenced this pull request Dec 5, 2026
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 coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, SearchMatchVisitor or stored_term_newtype remains.
  • The EQL v3 types derive no EncryptTarget, so the change to MatchVisitor does 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`]).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bf is present (packages/eql/src/v3/scalars/text/query_text_types.sql:42).
  • matches returns 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:

  1. Narrow the claim in the rustdoc, the README and the changeset to queries that eql-bindings builds, and say what a hand-built operand finds.
  2. Make the v4 query_text_match path raise on an empty bf, 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6845026. Line 108 now says that an EQL TextMatch field follows the same rule.

Comment thread languages/golang/CHANGELOG.md Outdated

### Changed

- **A `TextMatch` field stores text that cuts no token.** Such text is an

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
coderdan added a commit that referenced this pull request Dec 5, 2026
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.

This branch has not been deployed

No deployments
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.

1 participant