# US 10,956,394 B2 · Reclustering of database tables based on peaks and widths

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

- Number: US 10,956,394 B2
- Document ID: US10956394B2
- Status: Granted
- Kind: B2
- Application number: 16/941,215
- Filed: 2020-07-28
- Published: 2020-11-12
- Granted: 2021-03-23
- Earliest claimed: 2018-07-17
- Assignees: Snowflake Inc.
- Applicants: Snowflake Inc.
- Inventors: Jiaqi Yan; Thierry Cruanes; Jeffrey Rosen; William Waddington; Prasanna Rajaperumal; Abdul Munir
- Web page: https://patentgrep.com/patent/US10956394B2

## CPC

- G06F 16/2282: {Tablespace storage structures; Management thereof}
- G06F 7/08: Sorting, i.e. grouping record carriers in numerical or other ordered sequence according to the classification of at least some of the information they carry (by merging two or more sets of carriers in ordered sequence G06F7/16)
- G06F 16/217: {Database tuning (G06F16/2282 takes precedence; database performance monitoring G06F11/3409)}
- G06F 16/278: {Data partitioning, e.g. horizontal or vertical partitioning}
- G06F 16/285: {Clustering or classification}
- G06F 16/22: Indexing; Data structures therefor; Storage structures
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The subject technology determines whether a table is sufficiently clustered. The subject technology in response to determining the table is not sufficiently clustered, selects one or more micro-partitions of the table to be reclustered. The subject technology constructs a data structure for the table. The subject technology extracts minimum and maximum endpoints for each micro-partition in the data structure. The subject technology sorts each of one or more peaks in the data structure based on height. The subject technology sorts overlapping micro-partitions based on width. The subject technology selects based on which micro-partitions are within the tallest peaks of the one or more peaks and further based on which of the overlapping micro-partitions have the widest widths.

## Claims

### Claim 1

A method performed by a database platform comprising at least one hardware processor, the method comprising:
determining whether a table is sufficiently clustered:
in response to determining that the table is not sufficiently clustered, selecting one or more micro-partitions of the table to be reclustered, the selecting comprising:
constructing a data structure for the table;
extracting minimum and maximum endpoints for each micro-partition in the data structure;
sorting each of one or more peaks in the data structure based on height;
sorting overlapping micro-partitions based on width; and
selecting based on which micro-partitions are within the tallest peaks of the one or more peaks and further based on which of the overlapping micro-partitions have the widest widths; and
reclustering the selected one or more micro-partitions of the table.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
defining a constant micro-partition having equivalent minimum and maximum values for a cluster key column; and
removing the constant micro-partition from the selected one or more micro-partitions of the table prior to the reclustering.

### Claim 3 (depends on 1)

The method of claim 1, wherein the selecting further comprises:
identifying the one or more peaks in the data structure as those that are taller than a predefined threshold; and
identifying the overlapping micro-partitions within each of the one or more peaks.

### Claim 4 (depends on 1)

The method of claim 1, wherein the data structure comprises a stabbing count array or an interval tree.

### Claim 5 (depends on 1)

The method of claim 1, further comprising determining a budget for allocating resources to perform reclustering operations.

### Claim 6 (depends on 5)

The method of claim 5, wherein the determining whether the table is sufficiently clustered is based at least in part on the budget.

### Claim 7 (depends on 1)

The method of claim 1, further comprising partitioning the selected one or more micro-partitions of the table into one or more batches each comprising a grouping of micro-partitions.

### Claim 8 (depends on 1)

The method of claim 1, further comprising receiving an indication that a data modification task has been executed on the table, wherein the executing of the data modification task on the table comprises ingesting new micro-partitions into the table.

### Claim 9 (depends on 1)

The method of claim 1, further comprising entering a catch-up mode in which, based at least in part on a high proportion of database partitions being within lower levels of the table, reclustering operations are performed.

### Claim 10 (depends on 1)

The method of claim 1, further comprising entering a stable mode in which, based at least in part on a low proportion of database partitions being within lower levels of the table, no reclustering operations are performed.

### Claim 11

A system comprising:
at least one hardware processor; and
a memory device including instructions that, when executed by the at least one hardware processor, cause the at least one hardware processor to perform operations comprising:
determining whether a table is sufficiently clustered;
in response to determining that the table is not sufficiently clustered, selecting one or more micro-partitions of the table to be reclustered, the selecting comprising:
constructing a data structure for the table;
extracting minimum and maximum endpoints for each micro-partition in the data structure;
sorting each of one or more peaks in the data structure based on height;
sorting overlapping micro-partitions based on width; and
selecting based on which micro-partitions are within the tallest peaks of the one or more peaks and further based on which of the overlapping micro-partitions have the widest widths; and
reclustering the selected one or more micro-partitions of the table.

### Claim 12 (depends on 11)

The system of claim 11, the operations further comprising:
defining a constant micro-partition having equivalent minimum and maximum values for a cluster key column; and
removing the constant micro-partition from the selected one or more micro-partitions of the table prior to the reclustering.

### Claim 13 (depends on 11)

The system of claim 11, wherein the selecting further comprises:
identifying the one or more peaks in the data structure as those that are taller than a predefined threshold; and
identifying the overlapping micro-partitions within each of the one or more peaks.

### Claim 14 (depends on 11)

The system of claim 11, wherein the data structure comprises a stabbing count array or an interval tree.

### Claim 15 (depends on 11)

The system of claim 11, the operations further comprising determining a budget for allocating resources to perform reclustering operations.

### Claim 16 (depends on 15)

The system of claim 15, wherein the determining whether the table is sufficiently clustered is based at least in part on the budget.

### Claim 17 (depends on 11)

The system of claim 11, the operations further comprising partitioning the selected one or more micro-partitions of the table into one or more batches each comprising a grouping of micro-partitions.

### Claim 18 (depends on 11)

The system of claim 11, the operations further comprising receiving an indication that a data modification task has been executed on the table, wherein the executing of the data modification task on the table comprises ingesting new micro-partitions into the table.

### Claim 19 (depends on 11)

The system of claim 11, the operations further comprising entering a catch-up mode in which, based at least in part on a high proportion of database partitions being within lower levels of the table, reclustering operations are performed.

### Claim 20 (depends on 11)

The system of claim 11, the operations further comprising entering a stable mode in which, based at least in part on a low proportion of database partitions being within lower levels of the table, no reclustering operations are performed.

### Claim 21

A non-transitory computer-readable medium comprising instructions that, when executed by at least one hardware processor, cause the at least one hardware processor to perform operations comprising:
determining whether a table is sufficiently clustered;
in response to determining that the table is not sufficiently clustered, selecting one or more micro-partitions of the table to be reclustered, the selecting comprising:
constructing a data structure for the table;
extracting minimum and maximum endpoints for each micro-partition in the data structure;
sorting each of one or more peaks in the data structure based on height;
sorting overlapping micro-partitions based on width; and
selecting based on which micro-partitions are within the tallest peaks of the one or more peaks and further based on which of the overlapping micro-partitions have the widest widths; and
reclustering the selected one or more micro-partitions of the table.

### Claim 22 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising:
defining a constant micro-partition having equivalent minimum and maximum values for a cluster key column; and
removing the constant micro-partition from the selected one or more micro-partitions of the table prior to the reclustering.

### Claim 23 (depends on 21)

The non-transitory computer-readable medium of claim 21, wherein the selecting further comprises:
identifying the one or more peaks in the data structure as those that are taller than a predefined threshold; and
identifying the overlapping micro-partitions within each of the one or more peaks.

### Claim 24 (depends on 21)

The non-transitory computer-readable medium of claim 21, wherein the data structure comprises a stabbing count array or an interval tree.

### Claim 25 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising determining a budget for allocating resources to perform reclustering operations.

### Claim 26 (depends on 25)

The non-transitory computer-readable medium of claim 25, wherein the determining whether the table is sufficiently clustered is based at least in part on the budget.

### Claim 27 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising partitioning the selected one or more micro-partitions of the table into one or more batches each comprising a grouping of micro-partitions.

### Claim 28 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising receiving an indication that a data modification task has been executed on the table, wherein the executing of the data modification task on the table comprises ingesting new micro-partitions into the table.

### Claim 29 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising entering a catch-up mode in which, based at least in part on a high proportion of database partitions being within lower levels of the table, reclustering operations are performed.

### Claim 30 (depends on 21)

The non-transitory computer-readable medium of claim 21, the operations further comprising entering a stable mode in which, based at least in part on a low proportion of database partitions being within lower levels of the table, no reclustering operations are performed.
