A data query method, device, equipment and medium

By rewriting the query request of the graph traversal language and performing secondary queries based on materialized views, the problems of low query efficiency and high resource utilization of graph traversal language are solved, and more efficient data query is achieved.

CN113449067BActive Publication Date: 2025-08-05HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010219689.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-25
Publication Date
2025-08-05
Estimated Expiration
2040-03-25

AI Technical Summary

Technical Problem

When using graph traversal language to query data, resources occupy more and query efficiency is low.

Method used

Through rewriting traversal, the materialized view of historical query is used to match new query requests, and secondary queries are performed from the materialized historical query results, reducing physical read and write, sorting and aggregation operations, and improving query efficiency.

Benefits of technology

Shorten the query response time, reduce resource occupancy, and improve query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113449067B_ABST
    Figure CN113449067B_ABST
Patent Text Reader

Abstract

This application provides a data query method, comprising: receiving a first query request based on a graph traversal language, parsing the first query request, obtaining a first traversal, and rewriting the first traversal using a reference traversal that matches the first traversal, so that a database management system queries data based on the rewritten first traversal and a materialized view, wherein the reference traversal is a traversal corresponding to a materialized historical query request, and the materialized view includes historical query results corresponding to the materialized historical query request. This improves query efficiency and reduces resource usage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data query method, apparatus, device, and computer-readable storage medium. Background Art

[0002] With the advent of the information age, massive amounts of data have emerged. To meet users' data needs, databases have emerged. Databases are warehouses that organize, store, and manage data according to data structures. Based on differences in data structure, databases can be divided into relational databases and non-relational databases (also known as not only SQL, NoSQL).

[0003] Data queries in these databases are typically implemented using query statements generated by a query language. Classic database query languages, such as Structured Query Language (SQL), are distinct from the programming languages ultimately used in production environments, forcing developers to write both the main programming language and the database's query language. Graph traversal languages, on the other hand, can be seamlessly integrated into the main language, providing developers with greater convenience.

[0004] However, using graph traversal languages for data queries often consumes a lot of resources and has low query efficiency. Therefore, the industry urgently needs to provide an efficient and resource-efficient data query method. Summary of the Invention

[0005] This application provides a data query method that solves the problem of high resource consumption and low query efficiency when using graph traversal language for data query by rewriting traversal. This application also provides a device, equipment, computer-readable storage medium, and computer program product corresponding to the data query method.

[0006] First, the present application provides a data query method. This method uses materialized views of historical queries to match new query requests, allowing for secondary queries based on the materialized historical query results. This reduces physical read / write operations, sorting, and aggregation, reduces repeated computations, shortens query response time, improves query efficiency, and reduces resource usage.

[0007] Specifically, upon receiving a new query request (i.e., a first query request) based on a graph traversal language such as Gremlin, the first query request can be parsed to obtain a first traversal. The first traversal can then be rewritten using a reference traversal that matches the first traversal. This allows the database management system to query data based on the rewritten first traversal and the materialized view. The database management system then performs a secondary query based on the materialized historical query results after the rewritten first traversal, thereby improving query efficiency and reducing resource usage.

[0008] In some possible implementations, the actions included in the first traversal can be compared with the actions included in the reference traversal, and then the first traversal can be rewritten based on the comparison result. Specifically, the actions included in the first traversal are compared with the actions included in the reference traversal to determine a reference traversal that matches the first traversal. A reference action is then constructed based on the target filtering action and the reference tag corresponding to the target filtering action. The target filtering action is a filtering action included in the first traversal that is not included in the reference traversal that matches the first traversal. The first traversal can then be rewritten based on the reference action.

[0009] The rewritten first traversal can instruct the database management system to perform a secondary query from the materialized historical query results, such as performing further filtering operations on the historical query results. This can significantly shorten the query response time and improve query efficiency.

[0010] In some possible implementations, the reference traversal that matches the first traversal can be determined in the following manner. Specifically, the i-th action included in the first traversal is compared with the j-th action included in the reference traversal, where i and j are positive integers. When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, if the i-th action included in the first traversal meets a preset condition, the i+1-th action included in the first traversal is compared with the j-th action included in the reference traversal. When the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

[0011] It should be noted that when the i-th action has a nested sub-traversal, the actions included in the nested sub-traversal of the i-th action of the first traversal can also be recursively compared with the actions included in the nested sub-traversal of the j-th action of the reference traversal. The comparison process of the actions included in the sub-traversal can be referred to the comparison process of the actions included in the first traversal and the actions included in the reference traversal, and will not be repeated here.

[0012] By comparing the above, historical query requests similar to the first query request can be identified more accurately. Based on the traversals corresponding to the similar historical query requests, a reference traversal matching the first traversal can be obtained, and the first traversal can be rewritten based on the reference traversal.

[0013] In some possible implementations, the preset condition includes that the action is a filtering action, and a result set of an action preceding the filtering action is included in a result set corresponding to the reference traversal.

[0014] In some possible implementations, the rewritten first traversal may be converted into a first structured query statement, so that the database management system queries data according to the first structured query statement and the materialized view.

[0015] By converting the first traversal into a first structured query statement, queries with the same semantics in the graph traversal language can be identified, thereby optimizing the queries in the functional graph traversal language.

[0016] In some possible implementations, the historical query request includes a second query request, and the historical query request and historical query results may be materialized in the following manner. Specifically, before rewriting the first traversal using a reference traversal that matches the first traversal, a second query request based on a graph traversal language is received, the second query request is parsed to obtain a second traversal, the reference traversal includes the second traversal, and the second traversal is converted into a second structured query statement, so that the database management system generates a second query materialized view based on the second structured query statement and the second query results.

[0017] Materializing historical query requests and corresponding historical query results through the above method can provide assistance for subsequent query operations, reduce the time required for subsequent queries, improve query efficiency, and reduce resource usage.

[0018] In some possible implementations, the graph traversal language includes Gremlin.

[0019] In a second aspect, the present application provides a data query device. The device includes: a communication module, a parsing module, and a rewriting module. The communication module is used to receive a first query request based on a graph traversal language, the parsing module is used to parse the first query request and obtain a first traversal, and the rewriting module is used to rewrite the first traversal using a reference traversal that matches the first traversal, so that the database management system queries data based on the rewritten first traversal and a materialized view, wherein the reference traversal is a traversal corresponding to a materialized historical query request, and the materialized view includes historical query results corresponding to the materialized historical query request.

[0020] In some possible implementations, the rewriting module includes:

[0021] a comparing unit, configured to compare actions included in the first traversal with actions included in a reference traversal, and determine a reference traversal that matches the first traversal;

[0022] a construction unit, configured to construct a reference action according to a target filtering action and a reference tag corresponding to the target filtering action, wherein the target filtering action is a filtering action included in the first traversal and not included in the reference traversal matching the first traversal;

[0023] A rewriting unit is configured to rewrite the first traversal according to the reference action.

[0024] In some possible implementations, the comparison unit is specifically configured to:

[0025] Comparing the i-th action included in the first traversal with the j-th action included in the reference traversal, where i and j are positive integers;

[0026] When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, if the i-th action included in the first traversal meets a preset condition, comparing the i+1-th action included in the first traversal with the j-th action included in the reference traversal;

[0027] When the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

[0028] In some possible implementations, the preset condition includes that the action is a filtering action, and a result set of an action preceding the filtering action is included in a result set corresponding to the reference traversal.

[0029] In some possible implementations, the apparatus further includes:

[0030] The conversion module is used to convert the rewritten first traversal into a first structured query statement, so that the database management system queries data according to the first structured query statement and the materialized view.

[0031] In some possible implementations, the historical query request includes a second query request;

[0032] The communication module is also used for:

[0033] Before rewriting the first traversal using a reference traversal matching the first traversal, receiving a second query request based on a graph traversal language;

[0034] The parsing module is also used to:

[0035] Parsing the second query request to obtain a second traversal, wherein the reference traversal includes the second traversal;

[0036] The device further comprises:

[0037] A conversion module is used to convert the second traversal into a second structured query statement, so that the database management system generates a second query materialized view according to the second structured query statement and a second query result.

[0038] In some possible implementations, the graph traversal language includes Gremlin.

[0039] In a third aspect, the present application provides a computer, comprising a processor and a memory. The processor and the memory communicate with each other. The processor is configured to execute instructions stored in the memory, so that the computer performs the data query method according to the first aspect or any implementation of the first aspect.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium includes instructions, and the instructions instruct a computer to execute the data query method described in the first aspect or any implementation of the first aspect.

[0041] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the data query method described in the first aspect or any one of the implementations of the first aspect.

[0042] Based on the implementation methods provided in the above aspects, this application can also be further combined to provide more implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical methods of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments.

[0044] Figure 1 A schematic diagram of a relationship graph in a graph database provided in an embodiment of the present application;

[0045] Figure 2 A system architecture diagram 100 of a data query method provided in an embodiment of the present application;

[0046] Figure 3 A system architecture diagram 200 of a data query method provided in an embodiment of the present application;

[0047] Figure 4 A system architecture diagram 300 of a data query method provided in an embodiment of the present application;

[0048] Figure 5 A flowchart of a data query method provided in an embodiment of the present application;

[0049] Figure 6 A schematic diagram of rewriting the first traversal provided in an embodiment of the present application;

[0050] Figure 7 A flowchart for materializing historical queries provided in an embodiment of the present application;

[0051] Figure 8 A schematic diagram of the structure of a computer provided in an embodiment of the present application. DETAILED DESCRIPTION

[0052] The following will describe the solutions in the embodiments provided in this application in conjunction with the drawings in this application.

[0053] The terms "first," "second," and the like in the specification and claims of this application and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate and are merely used to describe the manner in which objects with the same attributes are described in the embodiments of this application.

[0054] In order to facilitate understanding of the technical solution of this application, some technical terms involved in this application are introduced below.

[0055] A database is a warehouse that organizes, stores, and manages data according to its structure. Databases typically store vast amounts of data. To improve query efficiency, users often use a data query language to write queries.

[0056] Data query languages include graph query languages, also known as graph traversal languages. Graph traversal languages are a general term for a class of languages that interact with graph databases to implement data queries. The implementation of graph traversal varies for different graph databases. Graph data in a graph database is organized in the form of vertices and edges (or relationships). Among them, a vertex generally refers to an entity, and an edge represents the relationship between points. For example, a "person" in a relationship graph is a point, and a "friend relationship" and a "transfer relationship" are edges. A point or edge can also include properties, which are used to describe the characteristics of the entity referred to by the point or the characteristics of the relationship referred to by the edge, such as a person's name, a person's age, a transfer time, and so on.

[0057] For ease of understanding, this application also provides an example of graph data in a graph database. Figure 1As shown in the figure, the database includes 4 vertices and 5 edges, specifically 3 "person" vertices and 1 "software" vertex, as well as 3 "created" edges and 2 "knows" edges. Vertices and edges have several attributes. For example, software vertices include attributes such as "name" and "lang". An attribute consists of an attribute name and an attribute value, such as "lang:java". In addition, vertices and edges are usually divided into categories, so vertices and edges can also have classification labels, such as Figure 1 The category label of the vertices named HugeGraph is software, and the category label of the vertices named "Zhang San", "Li Si" and "Wang Wu" is person.

[0058] Graph traversal languages allow users to express complex graph traversals or queries in a simple manner. Graph traversal languages include Gremlin, Cypher, and others. For ease of description, Gremlin is used in the following examples. A Gremlin-based traversal, or Gremlin traversal, is an in-memory representation structure obtained by translating Gremlin statements. A Gremlin traversal consists of a series of actions (steps), each of which performs an atomic operation on a data stream. Actions can be categorized into the following types based on the type of operation:

[0059] Transformation action (map step): transform objects in the data stream;

[0060] Filter step: Filters objects in the data stream;

[0061] Calculation statistics action (sideEffect step): calculates statistics on the data stream.

[0062] It should be noted that in some cases, the actions included in the Gremlin traversal can also nest subtraversals. Correspondingly, the actions included in the Gremlin traversal can also be branch steps, which are used to split the data flow object into multiple subtraversals.

[0063] Gremlin traversals can be written in an imperative or declarative style, or a hybrid of the two. Imperative traversals tell the traverser how to execute each step in the traversal, while declarative traversals do not tell the traverser how to execute each step in the traversal, but allow each traverser to choose a pattern to execute from a set of possibly nested patterns.

[0064] Users can use imperative or declarative methods to write query statements, which are parsed into traversals. The traverser can perform traversals to implement data queries. Figure 1 The examples in this article illustrate the traversal obtained by imperative writing and declarative writing.

[0065] The traversal obtained by imperative writing is:

[0066] gV().has('name', 'HugeGraph').as('a').in('created').groupCount().by('name');

[0067] This traversal representation first searches for vertices named HugeGraph from all vertices of the graph, then searches for vertices that create HugeGraph, and then counts the vertices that create HugeGraph by name and displays the vertices that create HugeGraph.

[0068] The traversal obtained by declarative writing is:

[0069] gV().match(

[0070] __.as('a').has('name','HugeGraph').as('b'),

[0071] __.as('b').in('created').as('c')).

[0072] select('c').groupCount().by('name')

[0073] This traversal representation matches the names of the people who created the HugeGraph from all vertices of the graph, counts the people by name, and displays the names of the people.

[0074] However, whether using a declarative or imperative approach to query statements, each query operation starts from scratch. For example, starting a query from all vertices or all edges of a graph results in a large number of physical read / write, sorting, and aggregation operations. Similar queries result in repeated physical read / write, sorting, and aggregation operations, leading to long query response times, low query efficiency, and high resource usage.

[0075] In view of this, an embodiment of the present application provides a data query method. This method supports the materialization of historical queries, specifically generating a materialized view (materialized view) including historical query results for historical query requests. The traversal corresponding to the materialized historical query request can be used as a reference traversal for subsequent queries.

[0076] Specifically, when a new query request based on a graph traversal language such as Gremlin, namely a first query request, is received, the first query request can be parsed to obtain a first traversal, and the first traversal can be rewritten using a reference traversal that matches the first traversal, so that the database management system can query data based on the rewritten first traversal. The database management system can perform a secondary query from the materialized historical query results based on the rewritten first traversal, thereby reducing physical reading and writing, sorting, aggregation and other operations, thereby reducing repeated calculations, shortening query response time, improving query efficiency, and reducing resource utilization.

[0077] For ease of understanding, the application environment of the data query method provided in the embodiment of the present application is introduced below. The data query method provided in the embodiment of the present application can be applied to, but is not limited to, Figure 2 In the application environment shown.

[0078] like Figure 2 As shown, this application scenario includes a database management system (DBMS) 202 and a query device 204. The DBMS 202 is deployed on a management server, and the query device 204 is deployed on a query server. The DBMS 202 receives a query request and sends it to the query device 204. The query device 204 parses the query request into a corresponding traversal and then rewrites the traversal corresponding to the current query request using a reference traversal corresponding to a previous query request. The DBMS 202 can then perform data queries based on the rewritten traversal.

[0079] Specifically, the database management system 202 includes a communication module 2022, a materialization module 2024, and a storage module 2026. The communication module 2022 is used to receive query requests based on a graph traversal language, such as receiving historical query requests based on a graph traversal language. For ease of description, the embodiment of the present application refers to the historical query request as the second query request. The materialization module 2024 is used to materialize the second query request and the corresponding second query result to generate a materialized view. In actual application, the materialization module 2024 can materialize the second query request and the corresponding second query result through a relational table. The storage module 2026 stores the above-mentioned materialized view.

[0080] The communication module 2022 of the database management system 202 is further configured to receive a new query request based on a graph traversal language. For ease of description, this embodiment of the application refers to the new query request (or the current query request) as the first query request. The communication module 2022 also sends the first query request to the query device 204.

[0081] The query device 204 includes a communication module 2042, a parsing module 2044, and a rewriting module 2046. When the communication module 2042 receives a first query request, the parsing module 2044 can parse the first query request to obtain a first traversal. The query device 2044 can also store traversals corresponding to materialized historical query requests, referred to as reference traversals in this embodiment of the application. The rewriting module 2046 can rewrite the first traversal using a reference traversal that matches the first traversal, allowing the database management system 202 to query data based on the rewritten first traversal.

[0082] In a specific implementation, the query device 204 may further include a conversion module 2048. The conversion module 2048 is configured to convert the rewritten first traversal into a first structured query statement based on a structured query language. The communication module 2042 sends the first structured query statement to the database management system 202. In this way, the database management system can perform a secondary query from the materialized relational table based on the first structured query statement, thereby quickly obtaining the first query result. This shortens the query response time, improves query efficiency, avoids resource waste caused by repeated physical read and write, sorting, and aggregation operations, and reduces resource utilization.

[0083] Need to explain, Figure 2 The query device 204 is illustrated as including the conversion module 2048. In some possible implementations, the functions of the conversion module 2048 may also be implemented by a separate device. For example, the functions of the conversion module 2048 may be implemented by the conversion device 206. The conversion device 206 may be specifically deployed in a transformer. The transformer may be a terminal or a server.

[0084] Figure 1 and Figure 2 The application scenarios are described in detail with the database management system 202 and the query device 204 deployed in physical devices such as servers. In some possible implementations, the database management system 202 and the query device 204 can also be deployed in a virtualized cloud device. Figure 3 As shown, the database management system 202 and the query device 204 can be deployed in a cloud computing cluster (including at least one cloud computing device, such as a cloud server, etc.).

[0085] It should also be noted that Figure 3 The example description assumes that the database management system 202 and query device 204 are deployed in different cloud computing clusters. In some possible implementations, the database management system 202 and query device 204 can also be deployed in the same computer cluster. Of course, the database management system 202 and query device 204 can also be deployed in a hybrid manner, that is, one is deployed in a physical device such as a server, and the other is deployed in a virtualized cloud device such as a cloud computing cluster. This embodiment of the present application is not limited to this.

[0086] In order to make the technical solution of the embodiment of the present application clearer and easier to understand, the data query method provided by the embodiment of the present application is described in detail below from the perspective of the interaction between the database management system 202 and the query device 204.

[0087] See also Figure 5 The data query method shown is a flowchart, and the method includes:

[0088] S502: The database management system 202 sends a first query request based on a graph traversal language to the query device 204.

[0089] Specifically, when querying data, a user can use a user device, such as a browser or a query client, to write a query statement in a graph traversal language. This query statement is specifically a query statement based on the graph traversal language. In response to the user operation, the user device can generate a query request based on the graph traversal language based on the query statement, and then send the query request based on the graph traversal language to the database management system 202. The current query request is referred to as the first query request, and the historical query request is referred to as the second query request.

[0090] When the database management system 202 receives the first query request sent by the user through the browser or the query client, it sends the first query request to the query device 204 so that the query device 204 processes the first query request to improve the query efficiency.

[0091] S504: The query device 204 parses the first query request and obtains a first traversal.

[0092] Specifically, the query means 204 may extract steps from the query statement carried in the first query request, and obtain a first traversal corresponding to the first query request based on the extracted steps, wherein the first traversal includes all steps in the query statement carried in the first query request.

[0093] S506: The query device 204 rewrites the first traversal using a reference traversal that matches the first traversal.

[0094] The query device 204 can parse the historical query request such as the second query request, for example, extract the action from the query statement carried by the second query request, and obtain the corresponding traversal based on the extracted action. The traversal corresponding to the historical query request can be called a reference traversal.

[0095] The query device 204 can determine a reference traversal that matches the first traversal from the reference traversal, and then rewrite the first traversal using the reference traversal that matches the first traversal, so that the database management system 202 can perform data query based on the rewritten first traversal and combined with the query results corresponding to the historical query request, without having to start the query from scratch, thereby improving query efficiency.

[0096] In a specific implementation, the query device 204 may compare the actions included in the first traversal with the actions included in the reference traversal, thereby determining a reference traversal that matches the first traversal. Specifically, the query device 204 may compare the i-th action included in the first traversal with the j-th action included in the reference traversal, where i and j are positive integers.

[0097] When the i-th action included in the first traversal matches the j-th action included in the reference traversal, that is, the action types are the same and the data streams affected by the actions are the same, continue to compare the i+1-th action and the j+1-th action. When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, that is, at least one of the action types or the data streams affected by the actions is different, then determine whether the i-th action included in the first traversal meets the preset conditions. If so, compare the i+1-th action included in the first traversal with the j-th action included in the reference traversal.

[0098] When the query device 204 compares to the last action, if the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

[0099] The preset condition may be that the action is a filtering action, and the result set of the previous action of the filtering action is included in the result set corresponding to the reference traversal. In this way, the current query can be performed based on the historical query results corresponding to the reference traversal, such as further filtering in the result set included in the historical query results.

[0100] It should be noted that the above i and j can be the same or different. For example, in the initial stage, the query device 204 compares the first action of the first traversal with the first action of the reference traversal. When the first action matches, that is, the action type is the same and the data stream affected by the action is also the same, the query device 204 continues to compare the next action, such as comparing the second action of the first traversal with the second action of the reference traversal. When the second action does not match, if the second action included in the first traversal meets the preset condition, the third action included in the first traversal is compared with the second action included in the reference traversal.

[0101] During the process of determining the reference traversal that matches the first traversal, if a filter step is determined to be included in the first traversal and not included in the reference traversal that matches the first traversal, i.e., a target filter step, the query device 204 may construct a reference action based on the target filter step and the reference tag corresponding to the target filter step. The reference tag indicates the data stream affected by the target filter step, specifically the result set corresponding to the previous action of the target filter step. The query device 204 may then rewrite the first traversal based on the reference action.

[0102] The process of rewriting the first traversal is described below with reference to a specific example.

[0103] like Figure 6 As shown, the reference traversal corresponding to the materialized historical query request includes the following traversal:

[0104] gV().as(′a′).match(_.as(′a′).out(′own′).out(′call′).in(′own′).as(′b′)).select(′a′,′b′)

[0105] The first traversal corresponding to the first query request is as follows:

[0106] gV().has(′name′,′jack′).match(_.as(′r′).out(′own′).out(′call′).in(′own′).as(′s′)).select(′s′)

[0107] In this example, the query device 204 first compares the first step of the first traversal, i.e., gV(), with the first step of the reference traversal, i.e., gV(). If the two match, the query device 204 then compares the second step of the first traversal, i.e., has('name', 'jack'), with the second step of the reference traversal, i.e., match(_.as('a').out('own').out('call').in('own').as('b')). The function of as is to temporarily save the result set of the previous step and has no substantial action on the data. Therefore, in the embodiment of the present application, as is not considered a step.

[0108] Query device 204 determines that the second step does not match and then determines whether the second step included in the first traversal is a filter action. In this example, has('name', 'jack') is clearly a filter action. Query device 204 determines the validity of the filter action. Specifically, it determines the validity of the filter action by determining whether the result set of the reference traversal includes the data stream affected by the filter action.

[0109] like Figure 6 As shown by the dashed line ①, the reference label 'a' represents the result set from the previous step, which includes all vertices in the graph. The query results corresponding to the reference traversal also include this result set. This is consistent with the first traversal where the query "has('name','jack')" was applied to all vertices. Therefore, this filtering action is valid.

[0110] The query device 204 can compare the next step of the first traversal, that is, the third step, with the second step in the reference traversal. In this example, the query device 204 compares match(_.as(′r′).out(′own′).out(′call′).in(′own′).as(′s′)) and match(_.as(′a′).out(′own′).out(′call′).in(′own′).as(′b′)). It should be noted that if the step to be compared includes sub traversal, the query device 204 needs to recursively compare the above subtraversal and determine the relationship between each sub traversal based on the current semantics. For example, for match, the relationship between all its sub traversals is to intersect in order, and for or, the relationship between all its sub traversals is to be obtained by OR.

[0111] During the comparison process, reference labels for the same position can be different, such as Figure 6The reference tags 'a' and 'b' of the reference traversal and the reference tags 'r' and 's' of the first traversal are recorded in the query device 204. The query device 204 can record the locations of the reference tags and establish a mapping relationship between the reference tags in the reference traversal and the first traversal to address the equivalence mapping of the reference tags between the two traversals and avoid misidentifying a matching step as a mismatch. Based on the above description, it can be seen that the third step of the first traversal matches the second step of the reference traversal.

[0112] Query device 204 continues to compare select('s'), the last step of the first traversal, with select('a', 'b'), the last step of the reference traversal. Because reference label 'b' and reference label 's' are equivalent, select('s') is included in select('a', 'b'). select('s') and select('a', 'b') match. Therefore, query device 204 can determine that the reference traversal is the reference traversal that matches the first traversal.

[0113] Among them, has('name','jack') is the target filtering operation. This target filtering operation acts on the result set referred to by the reference label 'a'. Figure 6 As shown by the dotted line ②, the query device 204 creates a reference operation based on the target filtering operation and the reference tag corresponding to the target filtering operation. The reference tag corresponding to the target filtering operation includes the reference tag corresponding to the result set on which the target filtering operation acts, such as the reference tag 'a'. In some cases, the reference tag corresponding to the target filtering operation also includes the application tag corresponding to the result set of this query, such as the reference tag 's'. In this example, the reference operation can be expressed as mgtStep('s',('a',has('name','jack'))).

[0114] S508: The query device 204 converts the rewritten first traversal into a first structured query statement.

[0115] When the query device has a conversion module 2048, the conversion module can be used to convert the graph traversal language into a structured query language, and the rewritten first traversal can be converted into a first structured query statement.

[0116] In some cases, the query device 204 may not execute S508 , and the independent conversion device 206 may perform the conversion function to convert the rewritten first traversal into a first structured query statement.

[0117] S510 : The query device 204 sends a first structured query statement to the database management system 202 .

[0118] After converting the rewritten first traversal into a first structured query statement, the query device 204 may send the first structured query statement to the database management system 202 .

[0119] In some cases, the query device 204 may not execute S510 , and the independent conversion device 206 may convert the rewritten first traversal into a first structured query statement, and then send the first structured query statement to the database management system.

[0120] S512: The database management system 202 queries data according to the first structured query statement and the materialized view.

[0121] Database management system 202 uses the first structured query statement to query data from the historical query results materialized in the materialized view. For example, the historical query results include the names of all individuals who created the HugeGraph software. The first query request specifically requests the names of individuals who created the HugeGraph software and are over 45 years old. Database management system 202 can then further filter the historical query results by age greater than 45, thereby quickly obtaining the first query result corresponding to the first query request.

[0122] Based on the above description, the data query method provided by the present application materializes historical queries, specifically generates a materialized view including historical query results for historical query requests. Among them, the traversal corresponding to the materialized historical query request can be used as a reference traversal for subsequent queries. When a new query request based on a graph traversal language such as Gremlin is received, the query request can be parsed to obtain the traversal, and then the reference traversal that matches the traversal can be used to rewrite the traversal, so that the database management system can query data based on the rewritten traversal. The database management system can perform a secondary query from the materialized historical query results based on the rewritten traversal, thereby reducing physical reading and writing, sorting and aggregation operations, shortening the query response time, improving query efficiency, and reducing resource occupancy.

[0123] Figure 5 The illustrated embodiment mainly describes the data query process in detail, and the data query process relies on the materialization of historical queries. Based on this, the embodiment of the present application provides a specific implementation method for materializing historical queries.

[0124] See also Figure 7 The flowchart of materializing historical queries is shown in Figure 5 Based on the embodiment shown, before executing S506, the method further includes:

[0125] S514: The database management system 202 sends a second query request based on the graph traversal language to the query device 204.

[0126] The second query request is a historical query request, i.e., a query request triggered earlier than the first query request. Similar to the first query request, the second query request may be a graph traversal language-based query request generated by the user device in response to a user-triggered query operation, based on a query statement in the graph traversal language. The user device then sends the second query request to database management system 202, which in turn sends the second query request to query device 204.

[0127] S516: The query device 204 parses the second query request to obtain a second traversal.

[0128] The query means 204 can extract the action from the query statement carried in the second query request, thereby obtaining the second traversal. The specific implementation thereof can refer to the process of parsing the first query request and obtaining the first traversal, that is, the description of the relevant content of S504, which will not be repeated here.

[0129] Furthermore, the querying means 204 may store the second traversal and use the second traversal as a reference traversal for use in subsequent queries.

[0130] S518: The query device 204 converts the second traversal into a second structured query statement.

[0131] The query device 204 can convert the second traversal into a corresponding structured query statement, i.e., the second structured query statement, through the conversion module 2048. The specific implementation process is similar to the process of the query device 204 converting the rewritten first traversal into the first structured query statement, and will not be repeated here.

[0132] S520 : The query device 204 sends a second structured query statement to the database management system 202 .

[0133] S522: The database management system 202 generates a second query materialized view according to the second structured query statement and the second query result.

[0134] Specifically, the database management system 202 can generate a relational table based on the second structured query statement and the second query result, thereby materializing the query result. The relational table is the materialized view corresponding to the second query request, ie, the second query materialized view.

[0135] It should be noted that, in the embodiment of the present application, after obtaining the first query result corresponding to the first query request, the database management system 202 may also materialize the first query result to generate a first query materialized view for use in subsequent queries.

[0136] In some cases, users can selectively use the data query method provided in this application to accelerate queries according to their needs. Specifically, the query device 204 can provide three control modules for reference traversal, as follows:

[0137] Global control mode: When this mode is enabled, all data queries against the database can use all reference traversals of the database to achieve query acceleration; when this mode is disabled, all data queries against the database cannot use reference traversals of the database.

[0138] Session control mode: If this mode is enabled, only the query operations on the database initiated during the current session will use the available reference traversal. If this mode is disabled, the query operations on the database initiated during the current session will not use the available reference traversal.

[0139] Individual control: Each reference traversal has a usage attribute. When the attribute indicates available, it means that the reference traversal can be used. When the attribute indicates unavailable, it means that the reference traversal cannot be used.

[0140] Based on the above settings, users can choose to enable the corresponding control mode, so as to meet the user's personalized needs for data query.

[0141] Combined with the above Figures 1 to 7 , describes in detail the data query method provided by the embodiment of the present application. The following will describe the data query device and corresponding equipment provided according to the embodiment of the present application in conjunction with the accompanying drawings.

[0142] See also Figure 2 The query device 204 shown in FIG. 2 includes:

[0143] Communication module 2042, configured to receive a first query request based on a graph traversal language;

[0144] A parsing module 2044 is configured to parse the first query request and obtain a first traversal;

[0145] The rewrite module 2046 is used to rewrite the first traversal using a reference traversal that matches the first traversal, so that the database management system queries data based on the rewritten first traversal and the materialized view, wherein the reference traversal is a traversal corresponding to the materialized historical query request, and the materialized view includes the historical query results corresponding to the materialized historical query request.

[0146] The specific implementation of the communication module 2042 can be found in Figure 5 The specific implementation of the parsing module 2044 can be found in the description of S502 in the embodiment shown. Figure 5The specific implementation of the rewriting module 2046 can be found in the description of S504 in the embodiment shown. Figure 5 Description of the relevant contents of S506 in the illustrated embodiment.

[0147] In some possible implementations, the rewriting module 2046 includes:

[0148] a comparing unit, configured to compare actions included in the first traversal with actions included in a reference traversal, and determine a reference traversal that matches the first traversal;

[0149] a construction unit, configured to construct a reference action according to a target filtering action and a reference tag corresponding to the target filtering action, wherein the target filtering action is a filtering action included in the first traversal and not included in the reference traversal matching the first traversal;

[0150] A rewriting unit is configured to rewrite the first traversal according to the reference action.

[0151] The specific implementation of rewriting module 2046 can be found in Figure 5 The description of the relevant contents of S506 in the illustrated embodiment will not be repeated here.

[0152] In some possible implementations, the comparison unit is specifically configured to:

[0153] Comparing the i-th action included in the first traversal with the j-th action included in the reference traversal, where i and j are positive integers;

[0154] When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, if the i-th action included in the first traversal meets a preset condition, comparing the i+1-th action included in the first traversal with the j-th action included in the reference traversal;

[0155] When the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

[0156] The specific implementation process of the comparison unit can be found in Figure 5 The description of the relevant contents of S506 in the illustrated embodiment will not be repeated here.

[0157] In some possible implementations, the preset condition includes that the action is a filtering action, and a result set of an action preceding the filtering action is included in a result set corresponding to the reference traversal.

[0158] In some possible implementations, the querying means 204 further includes:

[0159] The conversion module 2048 is configured to convert the rewritten first traversal into a first structured query statement, so that the database management system queries data according to the first structured query statement and the materialized view.

[0160] The specific implementation of the conversion module 2048 can be found in Figure 5 The description of the relevant contents of S508 in the illustrated embodiment will not be repeated here.

[0161] In some possible implementations, the historical query request includes a second query request;

[0162] The communication module 2042 is further used to:

[0163] Before rewriting the first traversal using a reference traversal matching the first traversal, receiving a second query request based on a graph traversal language;

[0164] The parsing module 2044 is further configured to:

[0165] Parsing the second query request to obtain a second traversal, wherein the reference traversal includes the second traversal;

[0166] The query device 204 further includes:

[0167] The conversion module 2048 is configured to convert the second traversal into a second structured query statement, so that the database management system generates a second query materialized view according to the second structured query statement and a second query result.

[0168] In some possible implementations, the graph traversal language includes Gremlin.

[0169] The data query device 204 according to the embodiment of the present application may be configured to execute the method described in the embodiment of the present application, and the above and other operations and / or functions of each module / unit of the data query device 204 are respectively to implement Figure 5 、 Figure 7 For the sake of brevity, the corresponding processes of the various methods in the illustrated embodiments are not described here in detail.

[0170] The present application also provides a computer. The computer may be a server or a cloud server, specifically for implementing the following Figure 2 The function of the data query device 204 in the illustrated embodiment.

[0171] Figure 8 A schematic diagram of the structure of a computer is provided. Figure 8As shown, computer 800 includes bus 801, processor 802, communication interface 803 and memory 804. Processor 802, memory 804 and communication interface 803 communicate via bus 801. Bus 801 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of representation, Figure 8 The use of only one bold line in the figure does not necessarily mean that there is only one bus or only one type of bus. The communication interface 803 is used for external communication. For example, it can receive a first query request based on a graph traversal language, a second query request based on a graph traversal language, and so on.

[0172] The processor 802 may be a central processing unit (CPU). The memory 804 may include a volatile memory, such as a random access memory (RAM). The memory 804 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a HDD, or an SSD.

[0173] The memory 804 stores executable codes, and the processor 802 executes the executable codes to perform the aforementioned data query method.

[0174] Specifically, in the implementation Figure 2 In the case of the embodiment shown, and Figure 2 When each module of the data query device 204 described in the embodiment is implemented by software, Figure 2The software or program code required for the functions of the parsing module 2044, the rewriting module 2046 and the conversion module 2048 are stored in the memory 804. The function of the communication module 2042 is implemented through the communication interface 803. The communication interface 803 receives a first query request based on the graph traversal language and transmits it to the processor 802 through the bus 601. The processor 802 executes the program code corresponding to each module stored in the memory 804, such as the program code corresponding to the parsing module 2044 and the rewriting module 2046, so as to parse the first query request to obtain a first traversal, and rewrite the first traversal based on the reference traversal matching the first traversal. Of course, the processor 802 can also execute the program code corresponding to the conversion module 2048 to convert the rewritten first traversal into the corresponding first SQL statement. In this way, the database management system 202 can perform data query based on the first SQL statement and the materialized view.

[0175] The embodiment of the present application further provides a computer-readable storage medium, which includes instructions, and the instructions instruct a computer to execute the data query method applied to the data query device 204.

[0176] The embodiment of the present application further provides a computer-readable storage medium, which includes instructions, and the instructions instruct a computer to execute the data query method applied to the data query device 204.

[0177] The present application also provides a computer program product. When the computer program product is executed by a computer, the computer performs any of the aforementioned data query methods. The computer program product may be a software installation package. When any of the aforementioned data query methods is required, the computer program product may be downloaded and executed on the computer.

Claims

1. A data query method, characterized in that: The method comprises: receiving a first query request based on a graph traversal language; Parsing the first query request to obtain a first traversal, where the first traversal includes actions in a query statement carried by the first query request; Actions in the first traversal are rewritten using a reference traversal that matches the first traversal to obtain a rewritten first traversal, so that a database management system queries data based on the rewritten first traversal and a materialized view, wherein the reference traversal is a traversal corresponding to a materialized historical query request, and the materialized view includes historical query results corresponding to the materialized historical query request.

2. The method according to claim 1, characterized in that The step of rewriting the actions in the first traversal by using the reference traversal matching the first traversal to obtain a rewritten first traversal includes: Comparing the actions included in the first traversal with the actions included in the reference traversal, and determining a reference traversal that matches the first traversal; constructing a reference action according to a target filtering action and a reference tag corresponding to the target filtering action, wherein the target filtering action is a filtering action included in the first traversal and not included in the reference traversal matching the first traversal; The actions in the first traversal are rewritten according to the reference action to obtain a rewritten first traversal.

3. The method according to claim 2, characterized in that The comparing the actions included in the first traversal with the actions included in the reference traversal to determine a reference traversal matching the first traversal includes: Comparing the i-th action included in the first traversal with the j-th action included in the reference traversal, where i and j are positive integers; When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, if the i-th action included in the first traversal meets a preset condition, comparing the i+1-th action included in the first traversal with the j-th action included in the reference traversal; When the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

4. The method according to claim 3, characterized in that The preset condition includes that the action is a filtering action, and a result set of an action preceding the filtering action is included in a result set corresponding to the reference traversal.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: The rewritten first traversal is converted into a first structured query statement, so that the database management system queries data according to the first structured query statement and the materialized view.

6. The method according to any one of claims 1 to 4, characterized in that The historical query request includes a second query request. Before rewriting the first traversal with a reference traversal matching the first traversal, the method further includes: receiving a second query request based on the graph traversal language; Parsing the second query request to obtain a second traversal, wherein the reference traversal includes the second traversal; The second traversal is converted into a second structured query statement, so that the database management system generates a second query materialized view according to the second structured query statement and a second query result.

7. The method according to any one of claims 1 to 4, characterized in that The graph traversal language includes Gremlin.

8. A data query device, characterized in that: The device comprises: A communication module, configured to receive a first query request based on a graph traversal language; a parsing module, configured to parse the first query request to obtain a first traversal, where the first traversal includes actions in a query statement carried by the first query request; A rewriting module is configured to rewrite actions in the first traversal using a reference traversal that matches the first traversal to obtain a rewritten first traversal, so that a database management system queries data based on the rewritten first traversal and a materialized view, wherein the reference traversal is a traversal corresponding to a materialized historical query request, and the materialized view includes historical query results corresponding to the materialized historical query request.

9. The device according to claim 8, characterized in that The rewriting module includes: a comparing unit, configured to compare actions included in the first traversal with actions included in a reference traversal, and determine a reference traversal that matches the first traversal; a construction unit, configured to construct a reference action according to a target filtering action and a reference tag corresponding to the target filtering action, wherein the target filtering action is a filtering action included in the first traversal and not included in the reference traversal matching the first traversal; The rewriting unit is configured to rewrite the actions in the first traversal according to the reference action to obtain a rewritten first traversal.

10. The device according to claim 9, characterized in that The comparison unit is specifically used for: Comparing the i-th action included in the first traversal with the j-th action included in the reference traversal, where i and j are positive integers; When the i-th action included in the first traversal does not match the j-th action included in the reference traversal, if the i-th action included in the first traversal meets a preset condition, comparing the i+1-th action included in the first traversal with the j-th action included in the reference traversal; When the last action included in the first traversal matches the last action included in the reference traversal, or the last action included in the first traversal meets the preset condition, the reference traversal is determined to be the reference traversal that matches the first traversal.

11. The device according to claim 10, characterized in that The preset condition includes that the action is a filtering action, and a result set of an action preceding the filtering action is included in a result set corresponding to the reference traversal.

12. The device according to any one of claims 8 to 11, characterized in that The device further comprises: A conversion module is used to convert the rewritten first traversal into a first structured query statement, so that the database management system queries data according to the first structured query statement and the materialized view.

13. The device according to any one of claims 8 to 11, characterized in that The historical query request includes a second query request; The communication module is also used for: Before rewriting the first traversal using a reference traversal matching the first traversal, receiving a second query request based on a graph traversal language; The parsing module is also used to: Parsing the second query request to obtain a second traversal, wherein the reference traversal includes the second traversal; The device further comprises: A conversion module is used to convert the second traversal into a second structured query statement, so that the database management system generates a second query materialized view according to the second structured query statement and a second query result.

14. The device according to any one of claims 8 to 11, characterized in that The graph traversal language includes Gremlin.

15. A computer, characterized in that: The computer includes a processor and a memory; The processor is configured to execute instructions stored in the memory, so that the computer executes the data query method according to any one of claims 1 to 7.

16. A computer-readable storage medium, characterized in that The computer-readable storage medium includes instructions, and the instructions instruct a computer to execute the data query method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Inline view query rewrite using a materialized view

    US20090019001A1