Skip to content
Advertisement

Optimizing SQL query from derived table

I have the following SQL query

that selects from this table view_statistics (which stores millions of rows, narrowed down to ~2M here for testing purposes):

And medias

Other related tables (browsers,device, operating_system, etc.) are listing tables, nothing fancy.

and altought the query is simple to me, it runs over many seconds with the following explain:

I don’t see how I can optimize this so simple query at all, can anyone point me to the right direction ?

Advertisement

Answer

An equivalent query would be:

Ideal indexes for this query would probably be medias(channel_id, id) (already exists) and view_statistics(media_id, session_id). However – It might already improve the performance with the given indexes.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement