The cost of a query plan depends on many parameters, such as predicate selectivities and available memory, whose values may not be known at optimization time.Parametric query optimization (PQO) optimizes a query into a number of candidate plans, each optimal for some region of the parameter space.We first propose a solution for the PQO problem for the case when the cost functions are linear in the given parameters. This solution is minimally intrusive in the sense that an existing query optimizer can be used with minor modifications: the solution invokes the conventional query optimizer multiple times, with different parameter values.We then propose a solution for the PQO problem for the case when the cost functions are piecewise-linear in the given parameters. The solution is based on modification of an existing query optimizer. This solution is quite general, since arbitrary cost functions can be approximated to piecewise linear form. Both the solutions work for an arbitrary number of parameters.