# US 12,007,994 B1 · Partition granular selectivity estimation for predicates

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

- Number: US 12,007,994 B1
- Document ID: US12007994B1
- Status: Granted
- Kind: B1
- Application number: 18/362,369
- Filed: 2023-07-31
- Granted: 2024-06-11
- Earliest claimed: 2023-07-31
- Assignees: Snowflake Inc.
- Applicants: Snowflake Inc.
- Inventors: Sangyong Hwang; Adem Khachnaoui; Li Yan; Yongsik Yoon
- Web page: https://patentgrep.com/patent/US12007994B1

## CPC

- G06F 16/24544: {Join order optimisation}
- G06F 11/3452: {Performance evaluation by statistical analysis}
- G06F 16/2282: {Tablespace storage structures; Management thereof}
- G06F 16/24545: {Selectivity estimation or determination}
- G06F 2201/80: Database-specific techniques
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A query engine can use partition-granular level statistics to optimize query performance. A query can reference a table with a plurality of partitions and include a predicate. A partition-granular selectivity estimate for the predicate can be generated based on statistics stored regarding the plurality of partitions of the table. A query plan can be generated based on partition-granular selectivity estimate to optimize query processing.

## Claims

### Claim 1

A method comprising:
receiving a query including at least one predicate referencing a table stored in a network-based data system, the table including a plurality of partitions, respective partitions of the plurality of partitions including a group of rows and at least one partition of the plurality of partitions being created in response to new data being written to the table, the at least one partition replacing an older partition;
retrieving statistics regarding the plurality of partitions of the table;
generating a partition-granular selectivity estimate for the at least one predicate based on the retrieved statistics;
generating a query plan based on the partition-granular selectivity estimate; and
executing the query plan to generate results of the query.

### Claim 2 (depends on 1)

The method of claim 1, wherein generating the partition-granular selectivity estimate is based on the selectivity estimation of at least two partitions of the plurality of partitions and based on a number of rows in the at least two partitions.

### Claim 3 (depends on 2)

The method of claim 2, wherein the at least two partitions are randomly selected.

### Claim 4 (depends on 2)

The method of claim 2, wherein the at least two partitions are selected based on skews in statistical properties of the at least two partitions.

### Claim 5 (depends on 1)

The method of claim 1, further comprising:
generating an initial query plan, wherein the query plan is a modified query plan based on the initial query plan and the partition-granular selectivity estimate.

### Claim 6 (depends on 5)

The method of claim 5, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table and a third table.

### Claim 7 (depends on 5)

The method of claim 5, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table including selection of the first table or the second table as a build table.

### Claim 8

A machine-storage medium embodying instructions that, when executed by a machine, cause the machine to perform operations comprising:
receiving a query including at least one predicate referencing a table stored in a network-based data system, the table including a plurality of partitions, respective partitions of the plurality of partitions including a group of rows and at least one partition of the plurality of partitions being created in response to new data being written to the table, the at least one partition replacing an older partition;
retrieving statistics regarding the plurality of partitions of the table;
generating a partition-granular selectivity estimate for the at least one predicate based on the retrieved statistics;
generating a query plan based on the partition-granular selectivity estimate; and
executing the query plan to generate results of the query.

### Claim 9 (depends on 8)

The machine-storage medium of claim 8, wherein generating the partition-granular selectivity estimate is based on the selectivity estimation of at least two partitions of the plurality of partitions and based on a number of rows in the at least two partitions.

### Claim 10 (depends on 9)

The machine-storage medium of claim 9, wherein the at least two partitions are randomly selected.

### Claim 11 (depends on 9)

The machine-storage medium of claim 9, wherein the at least two partitions are selected based on skews in statistical properties of the at least two partitions.

### Claim 12 (depends on 8)

The machine-storage medium of claim 8, further comprising:
generating an initial query plan, wherein the query plan is a modified query plan based on the initial query plan and the partition-granular selectivity estimate.

### Claim 13 (depends on 12)

The machine-storage medium of claim 12, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table and a third table.

### Claim 14 (depends on 12)

The machine-storage medium of claim 12, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table including selection of the first table or the second table as a build table.

### Claim 15

A system comprising:
at least one hardware processor; and
at least one memory storing instructions that, when executed by the at least one hardware processor, cause the at least one hardware processor to perform operations comprising:
receiving a query including at least one predicate referencing a table stored in a network-based data system, the table including a plurality of partitions, respective partitions of the plurality of partitions including a group of rows and at least one partition of the plurality of partitions being created in response to new data being written to the table, the at least one partition replacing an older partition;
retrieving statistics regarding the plurality of partitions of the table;
generating a partition-granular selectivity estimate for the at least one predicate based on the retrieved statistics;
generating a query plan based on the partition-granular selectivity estimate; and
executing the query plan to generate results of the query.

### Claim 16 (depends on 15)

The system of claim 15, wherein generating the partition-granular selectivity estimate is based on the selectivity estimation of at least two partitions of the plurality of partitions and based on a number of rows in the at least two partitions.

### Claim 17 (depends on 16)

The system of claim 16, wherein the at least two partitions are randomly selected.

### Claim 18 (depends on 15)

The system of claim 15, wherein the at least two partitions are selected based on skews in statistical properties of the at least two partitions.

### Claim 19 (depends on 15)

The system of claim 15, the operations further comprising:
generating an initial query plan, wherein the query plan is a modified query plan based on the initial query plan and the partition-granular selectivity estimate.

### Claim 20 (depends on 19)

The system of claim 19, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table and a third table.

### Claim 21 (depends on 19)

The system of claim 19, wherein the table is a first table, and wherein modifying the initial query plan includes changing a join order of the first table with a second table including selection of the first table or the second table as a build table.
