IP Library Granted Patent US 11,120,021
Granted Patent B2
US 11,120,021 · App. 15/404,118 · Granted Sep 14, 2021

Systems and methods for optimizing queries

Inventors: Kevin Alan Schaeffer (San Francisco, CA); Wojciech Galuba (San Francisco, CA)
Assignee: Facebook, Inc.
G06F16/24539G06F16/24542
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,120,021
App. No.
15/404,118
Granted
Sep 14, 2021
Kind
B2
Abstract

Systems, methods, and non-transitory computer-readable media can receive a query that includes at least one operation for aggregating data stored in one or more database tables. A determination is made that at least a portion of the data being aggregated by the operation has been pre-computed. The query is optimized so that the operation uses the pre-computed data when executed.

Claims (42)

1. A computer-implemented method comprising:

receiving, by a computing system, a query that includes at least one operation for aggregating data stored in one or more database tables;

determining, by the computing system, that at least a portion of the data being aggregated by the operation has been pre-aggregated,

wherein the data was pre-aggregated in response to a number of previous queries that aggregated the data, the number of previous queries that aggregated the data satisfying a threshold number; and

optimizing, by the computing system, the query so that the operation uses the pre-aggregated data when executed.

2. The computer-implemented method of claim 1 , wherein the operation for aggregating data corresponds to an average function, a count function, a maximum function, a minimum function, a median function, a sum function, or a union function.

3. The computer-implemented method of claim 1 , wherein optimizing the query so that the operation uses the pre-aggregated data when executed further comprises:

generating, by the computing system, an intermediate representation of the query; and

modifying, by the computing system, the intermediate representation of the query to reference the pre-aggregated data.

4. The computer-implemented method of claim 3 , wherein the intermediate representation of the query corresponds to an abstract syntax tree that describes the query, and wherein one or more nodes in the abstract syntax tree are modified to reference the pre-aggregated data.

5. The computer-implemented method of claim 1 , the method further comprising:

generating, by the computing system, a translated version of the query for execution by a given SQL query engine.

6. The computer-implemented method of claim 5 , wherein the translated version of the query corresponds to an Apache Hive query or a Presto query.

7. The computer-implemented method of claim 1 , wherein the data was pre-aggregated in response to the data being aggregated by one or more scheduled queries.

8. The computer-implemented method of claim 1 , the method further comprising:

determining, by the computing system, that a cost estimate for running the query satisfies a threshold value; and

preventing, by the computing system, the query from being executed.

9. A system comprising:

at least one processor; and

a memory storing instructions that, when executed by the at least one processor, cause the system to perform:

receiving a query that includes at least one operation for aggregating data stored in one or more database tables;

determining that at least a portion of the data being aggregated by the operation has been pre-aggregated, wherein the data was pre-aggregated in response to a number of previous queries that aggregated the data, the number of previous queries that aggregated the data satisfying a threshold number; and

optimizing the query so that the operation uses the pre-aggregated data when executed.

10. The system of claim 9 , wherein the operation for aggregating data corresponds to an average function, a count function, a maximum function, a minimum function, a median function, a sum function, or a union function.

11. The system of claim 9 , wherein optimizing the query so that the operation uses the pre-aggregated data when executed further comprises:

generating an intermediate representation of the query; and

modifying the intermediate representation of the query to reference the pre-aggregated data.

12. The system of claim 11 , wherein the intermediate representation of the query corresponds to an abstract syntax tree that describes the query, and wherein one or more nodes in the abstract syntax tree are modified to reference the pre-aggregated data.

13. The system of claim 9 , the method further comprising:

generating a translated version of the query for execution by a given SQL query engine.

14. A non-transitory computer-readable storage medium including instructions that, when executed by at least one processor of a computing system, cause the computing system to perform a method comprising:

receiving a query that includes at least one operation for aggregating data stored in one or more database tables;

determining that at least a portion of the data being aggregated by the operation has been pre-aggregated, wherein the data was pre-aggregated in response to a number of previous queries that aggregated the data, the number of previous queries that aggregated the data satisfying a threshold number; and

optimizing the query so that the operation uses the pre-aggregated data when executed.

15. The non-transitory computer-readable storage medium of claim 14 , wherein the operation for aggregating data corresponds to an average function, a count function, a maximum function, a minimum function, a median function, a sum function, or a union function.

16. The non-transitory computer-readable storage medium of claim 14 , wherein optimizing the query so that the operation uses the pre-aggregated data when executed further comprises:

generating an intermediate representation of the query; and

modifying the intermediate representation of the query to reference the pre-aggregated data.

17. The non-transitory computer-readable storage medium of claim 16 , wherein the intermediate representation of the query corresponds to an abstract syntax tree that describes the query, and wherein one or more nodes in the abstract syntax tree are modified to reference the pre-aggregated data.

18. The non-transitory computer-readable storage medium of claim 14 , the method further comprising:

generating a translated version of the query for execution by a given SQL query engine.

19. The computer-implemented method of claim 1 , wherein the data was pre-aggregated in response to at least one previous query that required an amount of time to execute, the amount of time to execute satisfying a threshold amount of time.

Assignments (2)
CHANGE OF NAME Recorded Dec 1, 2021
From: FACEBOOK, INC.
To: META PLATFORMS, INC.
Reel/Frame 058294/0083 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 12, 2017
From: SCHAEFFER, KEVIN ALAN; GALUBA, WOJCIECH
To: FACEBOOK, INC.
Reel/Frame 042676/0449 →
Continuity (1)
Related Publication 20180196850A1 · Jul 12, 2018