perf: add indexes for Login filter fields#540
perf: add indexes for Login filter fields#540nishantxscooby wants to merge 1 commit intocertego:developfrom
Conversation
|
Hi @Lorygold This change only adds database indexes on the fields involved in the reported Seq Scan ( Let me know if you prefer a different indexing strategy, ty :) |
|
in addition to that, I was wondering that the in that case, a new test in the |
|
Could be nice to add also the |
| models.Index(fields=["timestamp"], name="login_timestamp_idx"), | ||
| models.Index(fields=["ip"], name="login_ip_idx"), | ||
| models.Index(fields=["country"], name="login_country_idx"), | ||
| models.Index(fields=["event_id"], name="login_event_id_idx"), |
There was a problem hiding this comment.
I don't remember if the event_id is queried somewhere? Because if not, its indexing is useless
|
|
||
| class Meta: | ||
| indexes = [ | ||
| models.Index(fields=["timestamp"], name="login_timestamp_idx"), |
There was a problem hiding this comment.
If I remember well, the timestamp is often queried as the inverse order:
.order_by("-timestamp")
so, it could be usefull to index it as "-timestamp"
what do you think?
|
You should double-check whether these indexes actually match the way queries are executed and prove their match For example, A plain index on |
Fixes #494
Improve Login query performance by adding DB indexes
Problem
Queries on the
Loginmodel were causing sequential scans when filtering bytimestamp,ip,country, andevent_id, leading to poor performance on large datasets.Solution
Add database indexes for the most commonly filtered fields in
Login:The
indexfield is intentionally not indexed, as previously discussed.Scope