The performance of sorting degrades significantly when the useFilterForSortedQuery is enabled, and there's no filter query specified.
Steps to Reproduce:
1. Set useFilterForSortedQuery=true in solrconfig.xml
2. Run a query to match and return a single document. Also add sorting
- Example /select?q=foo:123&sort=bar+desc
Having a large index (> 10 million documents), this yields to a slow response (a few hundreds of milliseconds on average) even when the resulting set consists of a single document.
- Disabling useFilterForSortedQuery improves the performance to < 1ms
- Removing the sort improves the performance to < 1ms
- Keeping the sort, and adding any filter query (such as fq=*:*) improves the performance to < 1 ms.
After profiling SolrIndexSearcher.java found that the bottleneck is on
DocSet bigFilt = getDocSet(cmd.getFilterList());
when cmd.getFilterList()) is passed in as null. This is making getDocSet() function collect document ids every single time it is called without any caching.