Set collation of some string fields to 'C' #959
Merged
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.
Your checklist for this pull request
What is the current behaviour?
I found in documentation that PostgreSQL B-tree index doesn't work by default for left-anchored LIKE queries for columns that doesn't have 'C' collation set.
Default collation for database is unset so it's got from operating system defaults (in case of our production we have
en_US.UTF8
). In the same time, we don't sort anything by these strings and it's not even needed to have language-specific order as string data stored by MWDB are not even considered as "natural language".Collation "C" is also considered faster as
The C and POSIX collations both specify “traditional C” behavior, in which only the ASCII letters “A” through “Z” are treated as letters, and sorting is done strictly by character code byte values.
What is the new behaviour?
This PR explicitly sets collation of some string columns to "C", especially these columns that may be searched via left-anchored queries like
tag:"ripped:*"
Migration may take a while because B-Tree indexes may be rebuild to use a new ordering.