# US 2017/0293658 A1 · Partition aware evaluation of top-n queries

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

- Number: US 2017/0293658 A1
- Document ID: US20170293658A1
- Status: Published application
- Kind: A1
- Application number: 15/092,483
- Filed: 2016-04-06
- Published: 2017-10-12
- Earliest claimed: 2016-04-06
- Assignees: Oracle International Corporation
- Applicants: Oracle International Corporation
- Inventors: GONG ZHANG; SAM IDICULA; MICHAEL DULLER; NITIN KUNAL
- Web page: https://patentgrep.com/patent/US20170293658A1

## CPC

- G06F 16/24554: {Unary operations; Data partitioning operations}
- G06F 7/16: Combined merging and sorting
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Techniques are described for executing an analytical query with a top-N clause. In an embodiment, a stream of tuples are received by each of the processing units from a data source identified in the query. The processing unit uses a portion of a received tuple to identify the partition that the tuple is assigned to. For each partition, the processing unit maintains a top-N data store that stores an N number of received tuples that match the criteria of top N tuples according to the query. The received tuple is compared to the N number of tuples to determine whether to store the received tuple and discard an already stored tuple, or to discard the received tuple. After all the tuples have been similarly processed by the processing units, all the top-N data stores for each partition are merged, yielding the top N number of tuples for each partition to return as a result of the query.

## Claims

### Claim 1

A method comprising:
for each processing unit of a plurality of processing units that maintain a plurality of data stores:
said each processing unit maintaining a respective set of data stores from the plurality of data stores;
said each processing unit partitioning respective tuples from a data source of tuples into said respective set of data stores, each respective data store, of said respective set of data stores, corresponding to a respective partition of a plurality of partitions of said data source of tuples;
said each processing unit storing sort key values in a respective set of sort key data stores, each sort key data store, in the respective set of sort key data stores, being associated with said each respective data store;
wherein the respective set of sort key data stores is stored in respective memory of said each processing unit, said respective memory having an affinity with said each processing unit; and
for each partition of said plurality of partitions, generating a respective result set by merging a respective collection of data stores from the plurality of data stores, each data store, in the collection of data stores, corresponding to said each partition.

### Claim 2 (depends on 1)

The method of claim 1, wherein the plurality of data stores are stored in the same memory.

### Claim 3 (depends on 1)

The method of claim 1, wherein each sort key value in the respective set of sort key data stores corresponds to each tuple in said respective set of data stores, said each sort key value generated based on said each tuple.

### Claim 4 (depends on 1)

The method of claim 1, further comprising:
receiving a request to select a particular number of rows from each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for each of the plurality of data partitions and a particular order in which to sort the rows;
in response to receiving the request, a particular processing unit scanning the data set and distributing plurality of tuples, generated from the data set, to the plurality of processing units, each tuple of the plurality of tuples corresponding to a row in the data set;
wherein the plurality of tuples are distributed substantially evenly among the plurality of processing units.

### Claim 5 (depends on 1)

The method of claim 1, further comprising:
said each processing unit:
receiving a tuple from a data set of the data source of tuples specified in a request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
evaluating a particular sort key value based on the tuple against the particular sort key store;
based on evaluating, determining whether to discard the tuple or to store the tuple in the particular data store.

### Claim 6 (depends on 1)

The method of claim 1, further comprising:
said each processing unit:
receiving a tuple from a data set of the data source of tuples specified in a request;
extracting a partition key value from a pre-determined number of bits in the tuple;
matching the partition key value with a label of a particular data store from the respective set of data stores.

### Claim 7 (depends on 1)

The method of claim 1, further comprising:
receiving a request to select a particular number of rows in a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
extracting a partition key value from a pre-determined number of bits in the tuple that includes data of the partition key in the tuple;
matching the partition key value with a label of a particular data store from the respective set of data stores.

### Claim 8 (depends on 1)

The method of claim 1, further comprising:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
determining a sort key value for the tuple based on data of the sort key in the tuple;
comparing the sort key value with sort key values from the particular sort key store;
if the sort key value in comparison with the sort key values is in the particular number of sort key values sorted in the particular order, then storing the tuple in the particular data store;
if the sort key value in comparison with the sort key values is not in the particular number of sort key values sorted in the particular order, then discarding the tuple.

### Claim 9 (depends on 1)

The method of claim 1, wherein said each sort key data store comprises at least a particular number of sort key values, wherein the particular number is based on a received request.

### Claim 10 (depends on 1)

The method of claim 1, wherein said each sort key data store is a heap data structure comprising at least a particular number of nodes, each node corresponding to a sort key value.

### Claim 11 (depends on 1)

The method of claim 1, further comprising:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
wherein said particular sort key store is a heap data structure comprising the particular number of sort key values, each sort key value being a node in the heap data structure, nodes in the heap data structure being arranged in an opposite order of the particular order with a root node of the heap data structure being a maximum for an ascending order and a minimum for a descending order;
determining a sort key value for the tuple based on data of the sort key in the tuple;
comparing the sort key value with the root node of the heap data structure;
if the sort key value is greater than the minimum or lesser than the maximum, then storing the tuple in the particular data store; and
if the sort key value is lesser than the minimum, or greater than the maximum, then discarding the tuple.

### Claim 12 (depends on 1)

The method of claim 1, further comprising:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort; and
wherein said each partition of said plurality of partitions corresponds to a respective data partition in the plurality of data partitions; and
wherein, for said each partition, generating a respective result set by merging, the merging further comprising:
sorting sort key values from corresponding sort key data stores of the collection of data stores based on the particular order, and
selecting, as the respective result set, the particular number of tuples, from the collection of data stores, corresponding to the particular number of the sorted sort key values.

### Claim 13

One or more non-transitory storage media storing instructions, which, when executed by one or more hardware processors, cause:
for each processing unit of a plurality of processing units that maintain a plurality of data stores:
said each processing unit maintaining a respective set of data stores from the plurality of data stores;
said each processing unit partitioning respective tuples from a data source of tuples into said respective set of data stores, each respective data store, of said respective set of data stores, corresponding to a respective partition of a plurality of partitions of said data source of tuples;
said each processing unit storing sort key values in a respective set of sort key data stores, each sort key data store, in the respective set of sort key data stores, being associated with said each respective data store;
wherein the respective set of sort key data stores is stored in respective memory of said each processing unit, said respective memory having an affinity with said each processing unit; and
for each partition of said plurality of partitions, generating a respective result set by merging a respective collection of data stores from the plurality of data stores, each data store, in the collection of data stores, corresponding to said each partition.

### Claim 14 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the plurality of data stores are stored in the same memory.

### Claim 15 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein each sort key value in the respective set of sort key data stores corresponds to each tuple in said respective set of data stores, said each sort key value generated based on said each tuple.

### Claim 16 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
receiving a request to select a particular number of rows from each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for each of the plurality of data partitions and a particular order in which to sort the rows;
in response to receiving the request, a particular processing unit scanning the data set and distributing plurality of tuples, generated from the data set, to the plurality of processing units, each tuple of the plurality of tuples corresponding to a row in the data set;
wherein the plurality of tuples are distributed substantially evenly among the plurality of processing units.

### Claim 17 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
said each processing unit:
receiving a tuple from a data set of the data source of tuples specified in a request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
evaluating a particular sort key value based on the tuple against the particular sort key store;
based on evaluating, determining whether to discard the tuple or to store the tuple in the particular data store.

### Claim 18 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
said each processing unit:
receiving a tuple from a data set of the data source of tuples specified in a request;
extracting a partition key value from a pre-determined number of bits in the tuple;
matching the partition key value with a label of a particular data store from the respective set of data stores.

### Claim 19 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
receiving a request to select a particular number of rows in a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
extracting a partition key value from a pre-determined number of bits in the tuple that includes data of the partition key in the tuple;
matching the partition key value with a label of a particular data store from the respective set of data stores.

### Claim 20 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
determining a sort key value for the tuple based on data of the sort key in the tuple;
comparing the sort key value with sort key values from the particular sort key store;
if the sort key value in comparison with the sort key values is in the particular number of sort key values sorted in the particular order, then storing the tuple in the particular data store;
if the sort key value in comparison with the sort key values is not in the particular number of sort key values sorted in the particular order, then discarding the tuple.

### Claim 21 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein said each sort key data store comprises at least a particular number of sort key values, wherein the particular number is based on a received request.

### Claim 22 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein said each sort key data store is a heap data structure comprising at least a particular number of nodes, each node corresponding to a sort key value.

### Claim 23 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort;
said each processing unit:
receiving a tuple from the data set specified in the request;
based on a partition key value from the tuple, identifying a particular data store from the respective set of data stores that is associated with a particular sort key store from the respective set of sort key stores;
wherein said particular sort key store is a heap data structure comprising the particular number of sort key values, each sort key value being a node in the heap data structure, nodes in the heap data structure being arranged in an opposite order of the particular order with a root node of the heap data structure being a maximum for an ascending order and a minimum for a descending order;
determining a sort key value for the tuple based on data of the sort key in the tuple;
comparing the sort key value with the root node of the heap data structure;
if the sort key value is greater than the minimum or lesser than the maximum, then storing the tuple in the particular data store; and
if the sort key value is lesser than the minimum, or greater than the maximum, then discarding the tuple.

### Claim 24 (depends on 13)

The one or more non-transitory storage media of claim 13, wherein the instructions comprise one or more instructions, which cause:
receiving a request to select a particular number of rows in each of a plurality of data partitions of a data set of the data source of tuples, the request specifying:
a partition key of the data set by which values to partition the data set into the plurality of data partitions, and
a sort key of the data set by which values to sort rows for said each of the plurality of data partitions and a particular order in which to sort; and
wherein said each partition of said plurality of partitions corresponds to a respective data partition in the plurality of data partitions; and
wherein, for said each partition, generating a respective result set by merging, the merging further comprising:
sorting sort key values from corresponding sort key data stores of the collection of data stores based on the particular order, and
selecting, as the respective result set, the particular number of tuples, from the collection of data stores, corresponding to the particular number of the sorted sort key values.
