  A typical workflow for solving a linear programming problem is to first write
a linear program parametrized by the data in a language such as Math GNU Prog
or AMPL then call the solver on this program while providing the data. When the
data is extracted using a query on a database, this approach ignores the
underlying structure of the answer set which may result in a blow-up of the
size of the linear program if the answer set is big. In this paper, we study
the problem of solving linear programming problems whose variables are the
answers to a conjunctive query. We show that one can exploit the structure of
the query to rewrite the linear program so that its size depends only on the
size of the database and not on the size of the answer set. More precisely, we
give a generic way of rewriting a linear program whose variables are the tuples
in Q(D) for a conjunctive query Q and a database D into a linear program having
a number of variables that only depends on the size of a factorized
representation of Q(D), which can be much smaller when the fractional hypertree
width of Q is bounded.
