skip to Main Content

Mysql – Slow performance when order by field in foreign key

When a queryset is sorted by a field in a related model performance decreases drastically. I use mysql. For example, I have two models: class Event(models.Model): idEvent = models.BigAutoField(primary_key=True) created_at = models.DateTimeField(db_index=True, verbose_name=_('date')) processed_at = models.DateTimeField(auto_now_add=True, verbose_name=_('processed')) data = models.TextField()…

VIEW QUESTION

Mysql – Improving performance of SQL query for time series data

I'm writing a query in MySQL for a Grafana dashboard, but the performance of only this particular query is very poor. This is the query: SELECT br.reading ,CONCAT(ino.project,"_",SUBSTRING_INDEX(br.sensor,"_",-1)) AS new_metric ,ino.vessel ,ADDTIME(DATE('2023-01-01'),-TIMEDIFF(ino.date,br.datetime)) AS norm_date ,br.sensor FROM db.milestones br INNER JOIN…

VIEW QUESTION
Back To Top
Search