Transforming queries in a multi-tenant database system
View Patent ↗In a method, system, and computer-readable medium having instructions for executing a query in a database system, a query request is received with a query predicate to filter data returned in response to the query request and the query predicate has a formula, the query request is transformed to a transformed query request by preprocessing the formula in the query predicate, and the query request is optimized using the transformed query request.
1. A method for executing a query by a database system, the method comprising:
receiving a query request with a reference to a first database field in a query predicate, the query predicate comprising a formula referencing a second database field, the query request to filter data returned from the database system in response to the query request, the database system being shared by a plurality of organizations;
transforming the query request to a transformed query request by preprocessing the formula in the query predicate by replacing the reference to the first database field within the query request with at least one reference to the second database field, the at least one reference to the second database field including an index within the database system associated with one of the plurality of organizations; and
executing the query request using the transformed query request.
2. The method for executing a query by the database system of claim 1 , the method further comprising:
preprocessing the formula by performing an inverse function on a function within the formula.
3. The method for executing a query by the database system of claim 1 , the method further comprising:
applying an index to a database field referenced in the formula, wherein the index is for data of a tenant of the multi-tenant database.
4. The method for executing a query by the database system of claim 1 , wherein the formula has a nested formula and the formula is flattened during preprocessing.
5. The method for executing a query by the database system of claim 1 , the method further comprising:
preprocessing the formula by performing a range scan for the formula.
6. The method for executing a query by the database system of claim 1 , the method further comprising:
generating a SQL database request with the transformed query request.
7. A non-transitory computer-readable storage medium having one or more instructions thereon for executing a query in a database system, the instructions when executed by one or more processors causing the one or more processors to carry out:
receiving a query request with a reference to a first database field in a query predicate, the query predicate comprising a formula referencing a second database field, the query request to filter data returned from the database system in response to the query request, the database system being shared by a plurality of organizations;
transforming the query request to a transformed query request by preprocessing the formula in the query predicate by replacing the reference to the first database field within the query request with at least one reference to the second database field, the at least one reference to the second database field including an index within the database system associated with one of the plurality of organizations; and
executing the query request using the transformed query request.
8. The non-transitory computer-readable storage medium of claim 7 , the instructions further comprising:
preprocessing the formula by performing an inverse function on a function within the formula.
9. The non-transitory computer-readable storage medium of claim 7 , the instructions further comprising:
applying an index to a database field referenced in the formula, wherein the index is for data of a tenant of the multi-tenant database.
10. The non-transitory computer-readable storage medium of claim 7 , wherein the formula has a nested formula and the formula is flattened during preprocessing.
11. The non-transitory computer-readable storage medium of claim 7 , the instructions further comprising:
generating a SQL database request with the transformed query request.
12. A system for executing a query in a 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 carry out:
receiving a query request with a reference to a first database field in a query predicate, the query predicate comprising a formula referencing a second database field, the query request to filter data returned from the database system in response to the query request, the database system being shared by a plurality of organizations;
transforming the query request to a transformed query request by preprocessing the formula in the query predicate by replacing the reference to the first database field within the query request with at least one reference to the second database field, the at least one reference to the second database field including an index within the database system associated with one of the plurality of organizations; and
executing the query request using the transformed query request.
13. The system for executing a query in a database system of claim 12 , wherein the one or more stored sequences of instructions which, when executed by the processor, cause the processor to further carry out:
preprocessing the formula by performing an inverse function on a function within the formula.
14. The system for executing a query in a database system of claim 12 , wherein the one or more stored sequences of instructions which, when executed by the processor, cause the processor to further carry out:
applying an index to a database field referenced in the formula, wherein the index is for data of a tenant of the multi-tenant database.
15. The system for executing a query in a database system of claim 12 , wherein the formula has a nested formula and the formula is flattened during preprocessing.
16. The system for executing a query in a database system of claim 12 , wherein the one or more stored sequences of instructions which, when executed by the processor, cause the processor to further carry out:
generating a SQL database request with the transformed query request.
17. The system for executing a query in a database system of claim 12 , wherein the one or more stored sequences of instructions which, when executed by the processor, cause the processor to further carry out:
preprocessing the formula by performing a range scan for the formula.