15. A computer-implemented method of processing a query, comprising: receiving the query, wherein the query comprises one or more query blocks; determining a set of candidate queries and costs, wherein the costs include a cost for each candidate query in the set of candidate queries, wherein each candidate query in the set of candidate queries corresponds to a combination of possible alternative states for the one or more query blocks in the query, and wherein the set of candidate queries comprises all possible combinations of alternative states for the one or more query blocks; wherein each candidate query in the set of candidate queries is semantically equivalent to the query; choosing a particular query from the set of candidate queries based on the costs; and executing the particular query in response to a request to execute the query; wherein the method is performed by one or more computing devices.
15. A computer-implemented method of processing a query, comprising: receiving the query, wherein the query comprises one or more query blocks; determining a set of candidate queries and costs, wherein the costs include a cost for each candidate query in the set of candidate queries, wherein each candidate query in the set of candidate queries corresponds to a combination of possible alternative states for the one or more query blocks in the query, and wherein the set of candidate queries comprises all possible combinations of alternative states for the one or more query blocks; wherein each candidate query in the set of candidate queries is semantically equivalent to the query; choosing a particular query from the set of candidate queries based on the costs; and executing the particular query in response to a request to execute the query; wherein the method is performed by one or more computing devices. 16. The method of claim 15 , wherein determining the set of candidate queries comprises: generating a copy of the query in memory for each semantically equivalent query in the set of candidate queries; and processing the copy of the query in memory in order to produce the semantically equivalent query.