Mediator systems integrate distributed, heterogeneous and autonomous data sources, but their e ective use requires the solution of hard query optimization problems. This is usually done in one of two ways: when the set of data sources is xed, their ordering into a feasible and e cient query is treated as a join order problem when the set is not known, their selection from a superset is treated as a set covering problem. This two-phase approach is unlikely to nd optimum queries, and we describe a generalised approach in which a feasible query is constructed from a subset of the available data sources. Under simple cost assumptions this can be encoded and solved as a SAT problem. Results on arti cial benchmarks indicate that this is an interesting problem, with a combination of features that make it hard for both complete and incomplete search. We investigate both types of algorithm and a hybrid approach, with and without symmetry breaking constraints. The best combination turns out to ...