11. A system for optimizing a query in a multi-tenant database system, the system comprising: a processor; and one or more stored sequences of instructions which, when executed by the processor, cause the processor to: receiving a query request with a query predicate to filter data returned in response to the query request, wherein the query predicate comprises a formula; generating an index corresponding to one tenant of the multi-tenant database system; preprocessing the formula in the query predicate based upon the generated index for the tenant to create a transformed query request, wherein the preprocessing includes: applying the generated index to a database field referenced in the formula, replacing at least one reference to a database field within the formula with a reference to a second database field based upon the generated index; and optimizing the query request using the transformed query request, receiving a query request with a reference to a first database field in the query predicate, wherein the first database field comprises the formula in the query predicate, wherein the formula comprises a reference to a second database field; and transforming the query request to a transformed query request by replacing the reference to the first database field within the query request with at least one reference to the second database field.
11. A system for optimizing a query in a multi-tenant database system, the system comprising: a processor; and one or more stored sequences of instructions which, when executed by the processor, cause the processor to: receiving a query request with a query predicate to filter data returned in response to the query request, wherein the query predicate comprises a formula; generating an index corresponding to one tenant of the multi-tenant database system; preprocessing the formula in the query predicate based upon the generated index for the tenant to create a transformed query request, wherein the preprocessing includes: applying the generated index to a database field referenced in the formula, replacing at least one reference to a database field within the formula with a reference to a second database field based upon the generated index; and optimizing the query request using the transformed query request, receiving a query request with a reference to a first database field in the query predicate, wherein the first database field comprises the formula in the query predicate, wherein the formula comprises a reference to a second database field; and transforming the query request to a transformed query request by replacing the reference to the first database field within the query request with at least one reference to the second database field. 13. The system for optimizing a query in a database system of claim 11 , wherein the formula has a nested formula and the formula is flattened during preprocessing.