perf(postgres): add index for resource ID prefix filter - #3278
perf(postgres): add index for resource ID prefix filter#3278epbensimpson wants to merge 1 commit into
Conversation
remove unnecessary test
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Adding another index will significantly impact both write performance limits and storage requirements - Can we change the existing forward index to support prefixes somehow? |
|
I'm not an expert on postgres so take this with a grain of salt, but it doesn't seem feasible to me. Assuming replacing the existing index with a new one is fine (would require a brief exclusive lock on the table which could be a problem under load), using Using |
|
We've manually deployed this index to our production instance in the meantime, here's some stats about the index creation: DB Type: AWS Aurora Postgres |
If this is a big concern, I think you can get a bigger win there by swapping the I didnt spot any queries that would be negatively impacted by this change as everytime you reference As you'll see from Ben's data above that secondary unique index is almost half the table volume. |
Description
A prefix filter in
ReadRelationshipscannot currently use any of the existing indexes due to using aLIKEin the query, unless the database is configured to useCcollation.This PR adds an index with
object_id varchar_pattern_opswhich allows it to be used forLIKEqueries regardless of collation.Obviously there is some tradeoff in terms of writes with adding an additional index which needs some consideration. But without the index or appropriate collation the filter is basically unusable on any deployment using postgres with a significant number of tuples.
Testing
I couldn't find any existing tests specifically around index usage so testing was all manual, and was done by capturing the output from the query builder, replacing the specific revision with
pg_current_snapshot(), and manually running the following query before and after adding the index manually, on a deployment with ~4.1 million tuples:Before
After
References
Fixes #3274