Optimize constraint solver's catalog interface

We shouldn't ask sqlite for a list of rows and then go back and ask for
each row one by one!

Addresses #3043.