Have a really large table consisting of 8 fields (I know, unprecise).
In my application I run this SELECT repeatedly:
SELECT d1, time, s1, s2 from Collection WHERE (d1 = 1) and (s1 = 1) and (time BETWEEN 5666300000 AND 566630700);
I run this SELECT with different time ranges. d1 is a field with 200-300 different values, same with s1. Primary keys are d1, time, s1.
I’m looking for tips on optimizing my table structure and query. The thing is that the time field is not in ascending/descending order. So this can be a query requiring some time. I was wondering about indexing my time field. Would I then have to change my query? I that case, how?
Is there any obv wrong with my query I’m not seeing? This runs slow in my application.
Thanks!
I woild recommend building your clustered index (primary key) on time + d1 + s1 (in that order). This will ensure that the data is physically stored in order of time and then d1 and s1