-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
perf: Cache dbTables FuzzySet per schema #4472
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
mkleczek
wants to merge
1
commit into
PostgREST:main
Choose a base branch
from
mkleczek:dbtables-fuzzyset-cache
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.
+73
−25
Open
Changes from all commits
Commits
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
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
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
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.
I noticed something strange on my system. When I run the test with get endpoint changed to
/table-with-a-weird-name, the test fails with an exception.Uh oh!
There was an error while loading. Please reload this page.
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.
@taimoorzaeem I'm afraid the same thing happens when running this test against
main.This is expected as this PR only makes sure the FuzzySet is created once instead of every time hint is calculated. Hint calculation logic and the data structures stay the same.
IMHO it looks like the library we use for fuzzy search has reliability issues and we should look for other solutions.
Uh oh!
There was an error while loading. Please reload this page.
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.
@taimoorzaeem I found https://hackage-content.haskell.org/package/fuzzily-0.2.1.0/docs/Text-Fuzzily.html and https://hackage.haskell.org/package/fuzzyfind-3.0.2/docs/Text-FuzzyFind.html but they both implement online fuzzy search. For us means that hint calculation time is at least linear in the number of tables (which I don't think is a good idea as it will almost certainly fail with timeout for large schemas).
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.
I think the most scalable solution would be to implement the
SymSpellalgorithm. See: ref1, ref2, ref3.I think a haskell package for this would be great for the entire haskell community.
Uh oh!
There was an error while loading. Please reload this page.
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.
The problem with SymSpell is that it is memory hungry (ie. for 100,000 words and edit distance of 2 it requires 1,500,000 entries in the dictionary). Building the index is also very costly.
You can minimize memory requirements with perfect hashing but it makes building the index even more costly.
In general, this is a tough problem. It is even tougher if the spelling dictionary is dynamic (relation names in the schema cache can be reloaded and require index rebuilding).
Undoubtedly. You can read about SOTA techniques for example here: https://towardsdatascience.com/spelling-correction-how-to-make-an-accurate-and-fast-corrector-dc6d0bcbba5f/
Implementing this in Haskell would be a very interesting task.
Having said that, when you think about the whole architecture from the high level, PostgREST does not seem to be the right place to implement in-memory text search engine. Especially that it is a component that is supposed to be scaled easily (ie. start new instances quickly). In such scenarios you want to externalize state, ie. have a separate component implementing text search algorithms. But you already have such a component: PostgreSQL itself!
IMHO these are possible paths for PostgREST:
It just seems to me we've just hit the wall with our current architecture here and the only thing we can do is to admit it and live with deficiency in spell checking or re-architect and rewrite PostgREST.
One mitigation would be to work on
fuzzysetlibrary and try to optimize it as much as possible (I've taken a quick look at the source and found some minor optimization opportunities). The question is really: what schema sizes are "normal" for PostgREST and what sizes are outside of what PostgREST supports?@taimoorzaeem @steve-chavez does the above make sense?