Firstly, the presence of a large number of SortedList is a good design. This, in essence, is how all modern RDBMSs solve the same problem.
In addition to this: if there were a simple, general, close to optimally efficient way of responding to such requests, RDBMSes would not bother with a relatively complex and slow hack to optimize the query plan, i.e. generating large numbers of candidate plans, and then heuristically evaluate which one will take a minimum of time.
Admittedly, queries with many joins between tables are what usually make the possible plan space huge in practice with RDBMSes, and you don't seem to have one here. But even with just one table (set of objects), if there are k fields that can be used to select rows (objects), then theoretically you can have k! different indices ( SortedList pairs (key, value), in which the key is an ordered sequence of values ββof the field k, and the value is, for example, a memory pointer to an object) to choose from. If the query result is a single object (or, alternatively, if the query contains a sentence without a range for all k fields), then the index used does not matter, but in each other case, each index will generally perform otherwise, the query planner must have accurate selectivity estimates each offer to choose the best index to use.
source share