# US 2021/0173839 A1 · Placement of adaptive aggregation operators and properties in a query plan

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0173839 A1
- Document ID: US20210173839A1
- Status: Published application
- Kind: A1
- Application number: 17/180,323
- Filed: 2021-02-19
- Published: 2021-06-10
- Earliest claimed: 2019-09-25
- Assignees: Snowflake Inc.
- Applicants: Snowflake Inc.
- Inventors: Bowei Chen; Thierry Cruanes; Florian Andreas Funke; Allison Waingold Lee; Jiaqi Yan
- Web page: https://patentgrep.com/patent/US20210173839A1

## CPC

- G06F 16/24542: {Plan optimisation}
- G06F 16/2255: {Hash tables}
- G06F 16/24537: {of operators}
- G06F 16/24544: {Join order optimisation}
- G06F 16/24545: {Selectivity estimation or determination}
- G06F 16/24556: {Aggregation; Duplicate elimination}
- G06F 16/2456: {Join operations}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The subject technology receives a query plan, the query plan comprising a set of query operations, the set of query operations including at least one aggregation and at least one join operation. The subject technology analyzes the query plan to identify an aggregation that is redundant. The subject technology removes the aggregation based at least in part on the analyzing. The subject technology determines at least one aggregation property corresponding to at least one query operation of the query plan. The subject technology inserts at least one adaptive aggregation operator in the query plan based at least in part on the at least one aggregation property, the at least one aggregation property comprising a set of aggregation properties. The subject technology provides a modified query plan based at least in part on the inserted at least one adaptive aggregation operator in the query plan.

## Claims

### Claim 1

A method comprising:
receiving a query plan, the query plan comprising a set of query operations, the set of query operations including at least one aggregation and at least one join operation;
analyzing the query plan to identify an aggregation that is redundant;
removing the aggregation based at least in part on the analyzing;
determining at least one aggregation property corresponding to at least one query operation of the query plan;
inserting at least one adaptive aggregation operator in the query plan based at least in part on the at least one aggregation property, the at least one aggregation property comprising a set of aggregation properties, the set of aggregation properties comprising at least a splitability property, the splitability property indicating that the at least one adaptive aggregation operator is inserted below one side of the at least one join operation; and
providing a modified query plan based at least in part on the inserted at least one adaptive aggregation operator in the query plan.

### Claim 2 (depends on 1)

The method of claim 1, wherein analyzing the query plan to identify the aggregation that is redundant comprises:
determining that a first aggregation is guaranteed when a second aggregation is included in the query plan, the first aggregation and the second aggregation corresponding to different query operations at separate portions of the query plan, the query plan comprising a tree structure with multiple nodes, each node corresponding to a particular query operation; and
removing, as part of a pull-up phase, the first aggregation from the query plan.

### Claim 3 (depends on 1)

The method of claim 1, wherein determining the at least one aggregation property corresponding to at least one query operation of the query plan comprises:
determining the at least one aggregation property for associating to the at least one query operation of the query plan; and
assigning, as part of a push-down phase, the at least one aggregation property to the at least one query operation of the query plan.

### Claim 4 (depends on 3)

The method of claim 3, wherein each aggregation property is assigned to a particular query operation of the query plan, and a number of query operations that are assigned an aggregation property corresponds to a set of query operations in the query plan that are semantically equivalent when evaluating a particular aggregation at each query operation of the set of query operations.

### Claim 5 (depends on 1)

The method of claim 1, wherein the splitability property is based at least in part on a vector of aggregation operations including an aggregation operation that accesses attributes from one of two mutually exclusive subsets of input attributes, and the set of aggregation properties further comprises a decomposability property, or a duplicate-sensitivity property.

### Claim 6 (depends on 1)

The method of claim 1, wherein inserting the at least one adaptive aggregation operator in the query plan comprises:
analyzing a particular aggregation property to determine a type of aggregation operator to assign to a particular query operation of the query plan; and
generating at least one adaptive aggregation operation based at least in part on a threshold value, the threshold value corresponding to a number of keys or key lengths associated with the aggregation.

### Claim 7

A system comprising:
at least one processor; and
a memory device including instructions, which when executed by the at least one processor, cause the at least one processor to perform operations comprising:
receiving a query plan, the query plan comprising a set of query operations, the set of query operations including at least one aggregation and at least one join operation;
analyzing the query plan to identify an aggregation that is redundant;
removing the aggregation based at least in part on the analyzing;
determining at least one aggregation property corresponding to at least one query operation of the query plan;
inserting at least one adaptive aggregation operator in the query plan based at least in part on the at least one aggregation property, the at least one aggregation property comprising a set of aggregation properties, the set of aggregation properties comprising at least a splitability property, the splitability property indicating that the at least one adaptive aggregation operator is inserted below one side of the at least one join operation; and
providing a modified query plan based at least in part on the inserted at least one adaptive aggregation operator in the query plan.

### Claim 8 (depends on 7)

The system of claim 7, wherein analyzing the query plan to identify the aggregation that is redundant further causes the at least one processor to perform operations further comprising:
determining that a first aggregation is guaranteed when a second aggregation is included in the query plan, the first aggregation and the second aggregation corresponding to different query operations at separate portions of the query plan, the query plan comprising a tree structure with multiple nodes, each node corresponding to a particular query operation; and
removing, as part of a pull-up phase, the first aggregation from the query plan.

### Claim 9 (depends on 7)

The system of claim 7, wherein determining the at least one aggregation property corresponding to at least one query operation of the query plan further causes the at least one processor to perform operations further comprising:
determining the at least one aggregation property for associating to the at least one query operation of the query plan; and
assigning, as part of a push-down phase, the at least one aggregation property to the at least one query operation of the query plan.

### Claim 10 (depends on 9)

The system of claim 9, wherein each aggregation property is assigned to a particular query operation of the query plan, and a number of query operations that are assigned an aggregation property corresponds to a set of query operations in the query plan that are semantically equivalent when evaluating a particular aggregation at each query operation of the set of query operations.

### Claim 11 (depends on 7)

The system of claim 7, wherein the set of aggregation properties further comprises a decomposability property, or a duplicate-sensitivity property.

### Claim 12 (depends on 7)

The system of claim 7, wherein inserting the at least one adaptive aggregation operator in the query plan further causes the at least one processor to perform operations further comprising:
analyzing a particular aggregation property to determine a type of aggregation operator to assign to a particular query operation of the query plan; and
generating at least one adaptive aggregation operation based at least in part on a threshold value, the threshold value corresponding to a number of keys or key lengths associated with the aggregation.

### Claim 13

A non-transitory computer-storage medium comprising instructions that, when executed by at least one processor, cause the at least one processor to perform operations comprising:
receiving a query plan, the query plan comprising a set of query operations, the set of query operations including at least one aggregation and at least one join operation;
analyzing the query plan to identify an aggregation that is redundant;
removing the aggregation based at least in part on the analyzing;
determining at least one aggregation property corresponding to at least one query operation of the query plan;
inserting at least one adaptive aggregation operator in the query plan based at least in part on the at least one aggregation property, the at least one aggregation property comprising a set of aggregation properties, the set of aggregation properties comprising at least a splitability property, the splitability property indicating that the at least one adaptive aggregation operator is inserted below one side of the at least one join operation; and
providing a modified query plan based at least in part on the inserted at least one adaptive aggregation operator in the query plan.

### Claim 14 (depends on 13)

The system of claim 13, wherein analyzing the query plan to identify the aggregation that is redundant further causes the at least one processor to perform operations further comprising:
determining that a first aggregation is guaranteed when a second aggregation is included in the query plan, the first aggregation and the second aggregation corresponding to different query operations at separate portions of the query plan, the query plan comprising a tree structure with multiple nodes, each node corresponding to a particular query operation; and
removing, as part of a pull-up phase, the first aggregation from the query plan.

### Claim 15 (depends on 13)

The system of claim 13, wherein determining the at least one aggregation property corresponding to at least one query operation of the query plan further causes the at least one processor to perform operations further comprising:
determining the at least one aggregation property for associating to the at least one query operation of the query plan; and
assigning, as part of a push-down phase, the at least one aggregation property to the at least one query operation of the query plan.

### Claim 16 (depends on 15)

The system of claim 15, wherein each aggregation property is assigned to a particular query operation of the query plan, and a number of query operations that are assigned an aggregation property corresponds to a set of query operations in the query plan that are semantically equivalent when evaluating a particular aggregation at each query operation of the set of query operations.

### Claim 17 (depends on 13)

The system of claim 13, wherein the set of aggregation properties further comprises a decomposability property, or a duplicate-sensitivity property.

### Claim 18 (depends on 17)

The system of claim 17, wherein the duplicate-sensitivity property relates to one or more aggregation operations in which results are sensitive to whether there are duplicate values in an argument, the duplicate-sensitivity property comprises a separate count column for each group in a particular aggregation before a particular join operation.

### Claim 19 (depends on 13)

The system of claim 13, wherein inserting the at least one adaptive aggregation operator in the query plan further causes the at least one processor to perform operations further comprising:
analyzing a particular aggregation property to determine a type of aggregation operator to assign to a particular query operation of the query plan; and
generating at least one adaptive aggregation operation based at least in part on a threshold value, the threshold value corresponding to a number of keys or key lengths associated with the aggregation.

### Claim 20 (depends on 13)

The system of claim 13, wherein the splitability property is based at least in part on a vector of aggregation operations including an aggregation operation that accesses attributes from one of two mutually exclusive subsets of input attributes.
