add index by user_id on classifications #56
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.
Add index by user_id on classification_events. Currently, we are indexing by
event_time
as well as our composite primary key which automatically creates index by pkey (a combo ofevent_time
andclassification_id
).Originally, classification_events was designed without the index by
user_id
mainly becauseuser_id
to the materialized view/continuous aggregate. (DailyClassificationCountsPerUser____)As we look into sync script (syncing newly added group members and their classifications), we now care about the case where users who are supposed to belong to a user_group but did not join the user_group (and have classifications that should be counted to the user_group). And therefore we need to search classification_events by user_id. This search is currently inefficient since it has to go through sequential scans of the whole hypertable in order to receive results.
NOTE
-Timescale currently does not support creating indexes concurrently. This means that we cannot avoid write locks.
CREATE INDEX
See: https://docs.timescale.com/api/latest/hypertable/create_index/ for more details.