fix(postgres): use the utf8_ci_ai index collation for _uid and _document lookups - #996
Open
HarshMN2345 wants to merge 1 commit into
Open
HarshMN2345 wants to merge 1 commit into
HarshMN2345 wants to merge 1 commit into
Conversation
The _uid and permissions unique indexes are built with the utf8_ci_ai collation, but lookups compared with the column default collation, so Postgres could never use them and every lookup by ID was a sequential scan. Compare with the index collation through adapter hooks that are empty for the other SQL adapters.
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 43 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs appwrite/appwrite#14075
The Postgres
_uidand_permsunique indexes are built withCOLLATE utf8_ci_ai, but lookups compared with the column default collation, so the indexes could never be used and every lookup by ID was a sequential scan.This adds two collation hooks to
SQL(empty by default, so MariaDB/MySQL/SQLite SQL is unchanged) and uses them for_uid/_documentmatches ingetDocument(incl.FOR UPDATE),getSequences,updateDocument(s),upsertDocuments,increaseDocumentAttribute,deleteDocument(s)andQuery::equal('$id', ...). Shared tables build the_permsindex on_documentwithout the collation, so_documentmatches stay as they are there.Side effect: on Postgres,
getDocumentandequal('$id')now match IDs case-insensitively, as on MariaDB and in line with the case-insensitive_uiduniqueness.Verification (PostgreSQL 18.3, 300k rows, plans from
auto_explainon the library's own queries): before, every one of these paths ranSeq Scan/Parallel Seq Scanon the collection,_metadataand (non-shared)_perms. After, they all runIndex Scan using ..._uid/..._ukey, in both shared and non-shared mode. Postgres e2e suites: the failures are the same environment-related ones as onmain, and the tests that only failed in the full run pass when run on their own.