Repository navigation
fix(databases): allow trigram index type for Postgres string matching - #14108
Conversation
🟢 Tier S · Ready to mergeAdds trigram as an index type for Databases and TablesDB direct and inline index creation, exposes it in the SDK enums, and relies on the database library validator for adapter, attribute, and option restrictions. Documents the PostgreSQL-only string-matching use case and adds E2E coverage for successful creation and rejection cases. The latest changes also expose adapter trigram support through Console Variables and use that capability in the E2E test instead of checking the configured adapter name. Latest changes: The newest commits add
📂 Walkthrough · 11
Merged |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
PostgreSQL builds a trigram index through the index endpoint and inline on create, and refuses one on a non-string attribute or with orders. Other adapters reject the type as unsupported on both paths.
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
The create-index references for Databases and TablesDB now list every type the endpoints accept, and note that trigram is PostgreSQL only and serves contains, startsWith and endsWith on string attributes.
Expose supportForTrigramIndex in the console variables and read it through a getSupportForTrigramIndex() scope getter instead of checking _APP_DB_ADAPTER directly.
Fixes #14088
On Postgres,
startsWith,containsandendsWithcompile toILIKE, which none of the index types the API allows can serve, so these queries always scan the whole table. utopia-php/database already supportsDatabase::INDEX_TRIGRAM(GIN withgin_trgm_ops). This change addstrigramto the index type whitelist (and SDK enum) of the Databases and TablesDB index create endpoints and to the inline index validator used when creating a collection or table.Adapter support and column type are still checked by the library index validator that already runs in these endpoints. It uses
getSupportForTrigramIndex(), which is true only on Postgres, and allows string attributes only, without orders or lengths. On MariaDB/MySQL and Mongo the request is rejected with "Trigram indexes are not supported". The worker already passes the type through tocreateIndex(). DocumentsDB (Mongo) is unchanged.Verification, 300k rows on
appwrite/postgres:typeparam rejectstrigram(allowed: key, fulltext, unique, spatial). With only the B-tree key index,name ILIKE 'Zimmer 99%'andnote ILIKE '%Schimmel%'run as a Parallel Seq Scan (~95-110 ms).trigramis accepted. The library validator accepts it on a string attribute and rejects it on$createdAt. The index it creates (USING gin (name gin_trgm_ops)) turns both queries into a Bitmap Index Scan (~1 ms).