# US 2025/0209072 A1 · Data query method and query engine

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

- Number: US 2025/0209072 A1
- Document ID: US20250209072A1
- Status: Published application
- Kind: A1
- Application number: 18/971,741
- Filed: 2024-12-06
- Published: 2025-06-26
- Earliest claimed: 2023-12-25
- Assignees: Alipay (Hangzhou) Information Technology Co., Ltd.
- Applicants: Alipay (Hangzhou) Information Technology Co., Ltd.
- Inventors: Litao LIN
- Web page: https://patentgrep.com/patent/US20250209072A1

## CPC

- G06F 16/24542: {Plan optimisation}
- G06F 16/24526: {Internal representations for queries}
- G06F 16/9024: {Graphs; Linked lists (G06F16/9027 takes precedence)}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A data query method is performed by a query engine, and includes: receiving a user query, wherein the user query includes an SQL query statement and a Gremlin graph query statement embedded into the SQL query statement, the Gremlin graph query statement indicates to perform matching on one or more types of graph elements in a target graph, and the one or more types of graph elements include at least one of a point type, an edge type, or a path type; parsing the user query, to determine an execution plan; and performing a data query based on the execution plan.

## Claims

### Claim 1

A data query method, performed by a query engine, wherein the method comprises:
receiving a user query, wherein the user query comprises an SQL query statement and a Gremlin graph query statement embedded into the SQL query statement, the Gremlin graph query statement indicates to perform matching on one or more types of graph elements in a target graph, and the one or more types of graph elements comprise at least one of a point type, an edge type, or a path type;
parsing the user query, to determine an execution plan; and
performing a data query based on the execution plan.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the user query requires to return a matched graph element.

### Claim 3 (depends on 1)

The method according to claim 1, wherein the SQL query statement comprises a projection operation statement, to convert a graph element found based on the Gremlin graph query statement into row data.

### Claim 4 (depends on 1)

The method according to claim 1, wherein the Gremlin graph query statement returns a matched subgraph, and the SQL query statement references a graph element in the subgraph by using a predetermined identifier.

### Claim 5 (depends on 1)

The method according to claim 1, wherein the query engine defines following data structure:
the point type comprising one or more fields, and the one or more fields comprising at least an identifier field indicating a node ID;
the edge type comprising one or more fields, and the one or more fields comprising at least an identifier field of each node in a node pair comprising a source node and a destination node; and
the path type comprising a type of consecutive points, a type of edges, or null values.

### Claim 6 (depends on 1)

The method according to claim 1, wherein the SQL query statement comprises a first statement, the first statement comprises a preset keyword for declaring an input parameter, a first parameter, and a second query, and the first parameter is used as a query parameter in the Gremlin graph query statement.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the performing the data query comprises:
performing the second query, and determining a parameter value of the first parameter based on a result of the second query; and
performing matching in the Gremlin graph query statement based on the parameter value of the first parameter.

### Claim 8 (depends on 7)

The method according to claim 7, wherein the second query is an SQL query.

### Claim 9 (depends on 7)

The method according to claim 7, wherein the second query is an external function, and performing the second query comprises: calling the external function, and receiving a function operation result.

### Claim 10 (depends on 1)

The method according to claim 1, wherein the query engine comprises an SQL parser, a Gremlin parser, and an optimizer; and
the parsing the user query, to determine the execution plan comprises:
parsing the SQL query statement by using the SQL parser, to obtain one or more first operators, wherein the one or more first operators represent a relationship operation for a table;
parsing the Gremlin graph query statement by using the Gremlin parser, to obtain one or more second operators, wherein the one or more second operators represent a relationship operation for a graph; and
optimizing, by using the optimizer, an execution path for a combination of the one or more first operators and the one or more second operators, to obtain the execution plan.

### Claim 11 (depends on 10)

The method according to claim 10, wherein the optimizing the execution path for the combination of the one or more first operators and the one or more second operators comprises:
performing an operator adjustment operation, to obtain one or more candidate paths, wherein the operator adjustment operation comprises one or more of: exchanging operator execution sequences and combining some operators, and operators on which the operator adjustment operation is performed comprise the first operator and the second operator; and
determining the optimized execution path based on an execution cost of each candidate path.

### Claim 12 (depends on 1)

The method according to claim 1, wherein the query engine comprises an SQL parser and an optimizer, and a Gremlin querier configured to perform a Gremlin query is deployed outside the query engine; and
the parsing the user query, to determine the execution plan comprises:
parsing the SQL query statement by using the SQL parser, to obtain one or more first operators, wherein the one or more first operators represent a relationship operation for a table; and
optimizing, by using the optimizer, an execution path for a combination of the one or more first operators and a graph operation operator, to obtain the execution plan, wherein the graph operation operator corresponds to the Gremlin graph query statement, and is set to be a fixed-cost and non-separable operation.

### Claim 13 (depends on 12)

The method according to claim 12, wherein the performing the data query based on the execution plan comprises:
calling an interface provided by the Gremlin querier, to obtain a matching result of the Gremlin graph query statement.

### Claim 14

A device operating as a query engine, comprising:
a processor; and
a memory storing instructions executable by the processor;
wherein the processor is configured to:
receive a user query, wherein the user query comprises an SQL query statement and a Gremlin graph query statement embedded into the SQL query statement, the Gremlin graph query statement indicates to perform matching on one or more types of graph elements in a target graph, and the one or more types of graph elements comprise at least one of a point type, an edge type, or a path type;
parse the user query, to determine an execution plan; and
perform a data query based on the execution plan.

### Claim 15 (depends on 14)

The device according to claim 14, wherein the SQL query statement comprises a projection operation statement, to convert a graph element found based on the Gremlin graph query statement into row data.

### Claim 16 (depends on 14)

The device according to claim 14, wherein the Gremlin graph query statement returns a matched subgraph, and the SQL query statement references a graph element in the subgraph by using a predetermined identifier.

### Claim 17 (depends on 14)

The device according to claim 14, wherein the SQL query statement comprises a first statement, the first statement comprises a preset keyword for declaring an input parameter, a first parameter, and a second query, and the first parameter is used as a query parameter in the Gremlin graph query statement; and
the processor is further configured to:
perform the second query, and determine a parameter value of the first parameter based on a result of the second query; and
perform matching in the Gremlin graph query statement based on the parameter value of the first parameter.

### Claim 18 (depends on 14)

The device according to claim 14, wherein the processor is configured to implement an SQL parser, a Gremlin parser, and an optimizer; and
the processor is further configured to:
parse the SQL query statement by using the SQL parser, to obtain one or more first operators, wherein the one or more first operators represent a relationship operation for a table;
parse the Gremlin graph query statement by using the Gremlin parser, to obtain one or more second operators, wherein the one or more second operators represent a relationship operation for a graph; and
optimize, by using the optimizer, an execution path for a combination of the one or more first operators and the one or more second operators, to obtain the execution plan.

### Claim 19 (depends on 18)

The device according to claim 18, wherein the processor is further configured to:
perform an operator adjustment operation, to obtain one or more candidate paths, wherein the operator adjustment operation comprises one or more of: exchanging operator execution sequences and combining some operators, and operators on which the operator adjustment operation is performed comprise at least one of the one or more first operators and at least one of the one or more second operators; and
determine the optimized execution path based on an execution cost of each candidate path.

### Claim 20 (depends on 14)

The device according to claim 14, wherein the processor is configured to implement an SQL parser and an optimizer, and a Gremlin querier configured to perform a Gremlin query is deployed outside the query engine; and
the processor is further configured to:
parse the SQL query statement by using the SQL parser, to obtain one or more first operators, wherein the one or more first operators represent a relationship operation for a table; and
optimize, by using the optimizer, an execution path for a combination of the one or more first operators and a graph operation operator, to obtain the execution plan, wherein the graph operation operator corresponds to the Gremlin graph query statement, and is set to be a fixed-cost and non-separable operation.
