The query should only return a few rows, so sorting afterwards won't be expensive and I don't worry about this. I do need to combine multiple criteria and I expect that the query planner will use the most selective index or even more than one(?). I think the only solution right now is to dynamically build the query with only those criteria which are given. Of course I'm talking about this (your) cg-sql - is there any other? So far I have built it from source and tried a few test cases, not much more.