Recursive query processing method and related device

By abstracting the table data from recursive queries into a directed graph and performing path calculations, and splitting it into multiple subgraphs, the problems of slow recursive query speed and high memory consumption are solved, enabling fast output of links and improving query efficiency and stability.

CN121326937APending Publication Date: 2026-01-13INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511357087.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-22
Publication Date
2026-01-13

AI Technical Summary

Technical Problem

Existing technologies suffer from slow query speed, high memory consumption, and are prone to query failure when handling recursive queries with many levels and complex relationships.

Method used

The table data from recursive queries is abstracted into a directed graph. Path calculation is optimized using graph theory algorithms, and the graph is split into multiple subgraphs to determine the links between the starting node and the target node.

Benefits of technology

It improves the efficiency of recursive queries, reduces the probability of query failures, and meets the in-depth requirements of lineage analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121326937A_ABST
    Figure CN121326937A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a recursive query processing method and a related device, and relates to the technical field of big data, the method comprises the following steps: when a statement to be processed is determined to be a recursive query statement, extracting a table name and a recursive condition in the recursive query statement; according to the table name and the recursion condition, constructing a directed graph, and based on the directed graph, obtaining the maximum depth of nodes and the total number of paths; splitting the directed graph into a plurality of sub-graphs according to the maximum depth and the total number of paths; and determining a link from a starting node to a target node according to the plurality of sub-graphs, and outputting the link. According to the method, the recursive query table data is abstracted into the directed graph, so that the success rate and efficiency of recursive query can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data technology, and in particular to a recursive query processing method and related apparatus. Background Technology

[0002] In the field of big data, task scheduling and data lineage analysis are core application scenarios. In these scenarios, the performance and stability of recursive queries directly affect query efficiency.

[0003] Currently, recursive queries mainly rely on the recursive query function provided by relational databases. However, for some tasks with many levels and complex relationships, the query speed may be slow, or even fail due to excessive memory consumption. Summary of the Invention

[0004] This application provides a recursive query processing method and related apparatus to improve the efficiency of recursive queries.

[0005] In a first aspect, embodiments of this application provide a recursive query processing method, including:

[0006] When it is determined that the statement to be processed is a recursive query statement, the table name and recursive conditions in the recursive query statement are extracted.

[0007] Based on the table name and the recursion condition, construct a directed graph, and obtain the maximum depth of the nodes and the total number of paths based on the directed graph;

[0008] The directed graph is divided into multiple subgraphs based on the maximum depth and the total number of paths.

[0009] The links from the starting node to the target node are determined based on the multiple subgraphs, and the links are output.

[0010] In some embodiments, obtaining the maximum depth of a node based on the directed graph includes:

[0011] Set the initial depth of all nodes to 0, and set the in-degree of the starting node to 0;

[0012] Starting from the initial node, traverse each node in reverse topological order to obtain the depth of each node's neighboring nodes.

[0013] The maximum depth is determined based on the depth of the neighboring nodes.

[0014] In some embodiments, obtaining the total number of paths to nodes based on the directed graph includes:

[0015] Reverse the edges of the directed graph to obtain a reversed graph;

[0016] Starting from the target node, the in-degree of the target node's neighboring nodes is updated sequentially to obtain the number of paths between the target node and its neighboring nodes; the target node is the node with an in-degree of 0 in the reverse graph.

[0017] The total number of paths is obtained based on the number of paths between the target node and its neighboring nodes.

[0018] In some embodiments, splitting the directed graph into multiple subgraphs based on the maximum depth and the total number of paths includes:

[0019] The number of recursion levels for the directed graph is determined based on the total number of paths.

[0020] The number of splits is determined based on the maximum depth and the number of recursive layers;

[0021] The directed graph is split based on the number of splits to obtain multiple subgraphs.

[0022] In some embodiments, splitting the directed graph based on the number of splits to obtain multiple subgraphs includes:

[0023] Using the starting node as the input for the query, the node with a maximum depth equal to the recursion level is queried in the directed graph to obtain the first subgraph;

[0024] Using the end node in the first subgraph as the input for the query, the node with a maximum depth equal to the recursion level is queried in the directed graph to obtain the second subgraph;

[0025] Repeat the process of obtaining a new subgraph based on the end node of the previous subgraph until the number of subgraphs obtained is consistent with the number of splits.

[0026] In some embodiments, determining the link from the starting node to the target node based on the plurality of subgraphs includes:

[0027] Traverse each subgraph to determine the target subgraph that includes the target node;

[0028] Obtain the path between the end node and the target node in each target subgraph;

[0029] The paths in each of the target subgraphs are associated to obtain the links between the starting node and the target node.

[0030] In some embodiments, obtaining the path between the end node in each target subgraph and the target node includes:

[0031] For any target subgraph, using the target node as the starting node, obtain the path between the target node and the end node in the target subgraph;

[0032] Use the end node of the current target subgraph as the starting node of the next target subgraph, and obtain the path between the starting node and the end node;

[0033] Repeat the process of obtaining the path between the start node and the end node in the next target subgraph until all target subgraphs have been processed.

[0034] In some embodiments, constructing a directed graph based on the table name and the recursion condition includes:

[0035] Retrieve the original data corresponding to the recursive query statement based on the table name;

[0036] The nodes of the directed graph are determined based on the original data, and the directed edges between the nodes are determined based on the recursion conditions.

[0037] Construct the directed graph based on the nodes and the directed edges.

[0038] Secondly, embodiments of this application provide a recursive query processing apparatus, comprising:

[0039] The extraction module is used to extract the table name and recursive conditions from the recursive query statement when it is determined that the statement to be processed is a recursive query statement.

[0040] The processing module is used to construct a directed graph based on the table name and the recursion condition, and to obtain the maximum depth of the nodes and the total number of paths based on the directed graph.

[0041] A splitting module is used to split the directed graph into multiple subgraphs based on the maximum depth and the total number of paths;

[0042] The output module is used to determine the link from the starting node to the target node based on the multiple subgraphs, and output the link.

[0043] Thirdly, this application provides an electronic device, including: a memory and a processor;

[0044] The memory is used to store computer instructions; the processor is used to execute the computer instructions stored in the memory to implement the method of any one of the first aspects.

[0045] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the method of any of the first aspects.

[0046] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method of any one of the first aspects.

[0047] The recursive query processing method provided in this application, when determining that the statement to be processed is a recursive query statement, extracts the table name and recursive conditions from the recursive query statement; constructs a directed graph based on the table name and the recursive conditions, and obtains the maximum depth and total number of paths of the nodes based on the directed graph; splits the directed graph into multiple subgraphs based on the maximum depth and the total number of paths; determines the links from the starting node to the target node based on the multiple subgraphs, and outputs the links. This method abstracts the table data of the recursive query into a directed graph and performs path calculation based on the directed graph. In complex long-link scenarios such as task scheduling and lineage analysis in the big data field, it can quickly output the complete link from the starting node to a certain affected target node, thereby obtaining all affected scheduling tasks or business tables and business fields, thus improving the efficiency of recursive queries and reducing the probability of query failure. Attached Figure Description

[0048] Figure 1 This is a schematic diagram of a scenario provided for an embodiment of this application;

[0049] Figure 2 A flowchart illustrating a recursive query processing method provided in this application embodiment. Figure 1 ;

[0050] Figure 3 A flowchart illustrating a recursive query processing method provided in this application embodiment. Figure 2 ;

[0051] Figure 4 This is a schematic diagram of the structure of a recursive query processing method provided in an embodiment of this application;

[0052] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0054] In the embodiments of this application, the terms "first" and "second" are used to distinguish identical or similar items with essentially the same function and effect, without limiting their order. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" do not necessarily imply that they are different.

[0055] It should be noted that, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0056] It should be noted that the recursive query processing method and related apparatus provided in this application can be used in the field of big data, or in any field other than big data. This application does not limit the application field of the provided recursive query processing method and related apparatus.

[0057] In the field of big data, task scheduling and data lineage analysis are core application scenarios.

[0058] For example, in data warehousing or ETL (Extract, Transform, Load) processes, it is necessary to manage the dependencies between a large number of tasks, forming complex long-chain dependencies. In data governance, it is necessary to track the source or scope of influence of a business table or field (which usually involves multi-level, multi-branch recursive queries). In fields such as financial risk control and supply chain management, it is necessary to analyze the relationships between business entities (such as customers, orders, and products), which may form deeply nested graph structures.

[0059] In the above scenarios, the performance and stability of recursive queries directly affect system efficiency. Existing technologies mainly rely on the recursive query functionality provided by relational databases for processing. However, the recursive query functionality provided by relational databases is difficult to efficiently calculate key indicators such as the longest path and the total number of paths, and it cannot process complex links in stages, resulting in slow recursive query speed, high memory consumption, and a high likelihood of query failure.

[0060] In view of this, embodiments of this application provide a recursive query processing method and related apparatus. By abstracting the table data of the recursive query into an unweighted directed acyclic graph and optimizing path calculation through graph theory algorithms, the database recursion level limitation can be avoided, the query failure rate can be reduced, and the method can support the rapid calculation of the longest path and the total number of paths, thus meeting the depth requirements of lineage analysis.

[0061] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0062] Figure 1 This is a schematic diagram of a scenario provided for an embodiment of this application, such as... Figure 1 As shown, it includes client 1 and server 2.

[0063] Client 1 inputs a recursive query statement to server 2, and server 2 executes the recursive query statement and outputs the execution result to client 1.

[0064] It should be understood that server 2 can be a server deployed locally or a server deployed in the cloud; it can be a standalone server or a server cluster; this application embodiment does not limit this.

[0065] Based on the above embodiments, the following will be used as an example. Figure 1 Taking the server shown as an example, the recursive query processing method provided in this application embodiment will be described in detail.

[0066] Figure 2 This is a flowchart illustrating a recursive query processing method provided in an embodiment of this application, as shown below. Figure 2 As shown, it includes:

[0067] S201. When it is determined that the statement to be processed is a recursive query statement, extract the table name and recursive conditions from the recursive query statement.

[0068] In some embodiments, when a query statement to be processed is obtained, the query statement can be syntax-recognized. If it is determined that the query statement includes a target field, then the statement to be processed is determined to be a recursive query statement. For example, the target field can be WITH RECURSIVE.

[0069] In some embodiments, when it is determined that the statement to be processed is a recursive query statement, the query statement can be parsed to extract the table name and recursive conditions from the recursive query statement. For example, the syntax tree that constructs the recursive query statement can be parsed, or a syntax parser can be used for parsing; this embodiment of the application does not limit this approach.

[0070] S202. Based on the table name and recursion conditions, construct a directed graph, and obtain the maximum depth of the nodes and the total number of paths based on the directed graph.

[0071] In some embodiments, when the table name and recursive conditions are obtained, the original data corresponding to the recursive query statement can be obtained based on the table name; the nodes of the directed graph can be determined based on the original data, and the directed edges between the nodes can be determined based on the recursive conditions; and the directed graph can be constructed based on the nodes and directed edges.

[0072] For example, the corresponding data table is retrieved from a relational database based on the table name. The original data is then obtained from this table and stored as key-value pairs. After determining the original data, all values ​​from the primary key column can be extracted as nodes in a directed graph.

[0073] The recursive condition defines the hierarchy or connection relationship between data, which corresponds to the directed edges in a directed graph. After obtaining the recursive condition, it is analyzed to extract the hierarchical or connection relationship it contains.

[0074] After determining the nodes and directed edges, an empty directed graph data structure can be created, and the nodes and directed edges can be added to the directed graph data structure to obtain the directed graph.

[0075] In some embodiments, after constructing a directed graph, the maximum depth and the total number of paths of the nodes in the directed graph can be calculated.

[0076] For example, a reverse topological sort can be performed on a directed graph to determine the processing order between nodes, and dynamic programming can be used to calculate the depth of each node and determine the maximum depth.

[0077] For example, a reverse graph of a directed graph can be constructed, and topological sorting and dynamic programming can be used to process the reverse graph to count the total number of paths for each node and determine the total number of paths.

[0078] S203. Divide the directed graph into multiple subgraphs based on the maximum depth and the total number of paths.

[0079] In some embodiments, the total number of paths can be used as an indicator to assess the complexity of recursive query results; the higher the total number of paths, the more complex the recursive query results. Therefore, to reduce query complexity, the recursion level of the directed graph can be determined based on the total number of paths.

[0080] For example, the more paths there are, the larger the recursion level; the fewer paths there are, the smaller the recursion level. It should be understood that the specific correspondence between the total number of paths and the recursion level can be set based on actual needs, and this application does not limit this.

[0081] In some embodiments, after determining the number of recursion levels, the number of times the directed graph needs to be split can be determined based on the ratio between the maximum depth and the number of recursion levels. The directed graph is then split into multiple subgraphs based on this number of splits.

[0082] For example, using the recursion level as the maximum depth of the subgraph to be split, querying the corresponding node in the directed graph yields a subgraph after the split. Repeating this splitting process multiple times (using the ratio mentioned above) results in multiple subgraphs.

[0083] S204. Determine the links from the starting node to the target node based on multiple subgraphs, and output the links.

[0084] In some embodiments, the target node may refer to the node specified by the user or the upper-layer application during the query.

[0085] After splitting the directed graph into multiple subgraphs, a target subgraph including the target node can be determined from the multiple subgraphs. The path between the starting node and the target node in each target subgraph is calculated, and the paths are associated to obtain the complete link between the starting node and the target node.

[0086] In some embodiments, after obtaining the link between the starting node and the target node, the initial recursive query statement can be rewritten based on the node IDs of the complete link summary to obtain the final query statement, and the query statement can be executed to output the query results.

[0087] The recursive query processing method provided in this application extracts the table name and recursive conditions from the recursive query statement when it is determined that the statement to be processed is a recursive query statement; constructs a directed graph based on the table name and recursive conditions, and obtains the maximum depth and total number of paths of the nodes based on the directed graph; splits the directed graph into multiple subgraphs based on the maximum depth and total number of paths; determines the links from the starting node to the target node based on the multiple subgraphs, and outputs the links. This method abstracts the table data of the recursive query into a directed graph and performs path calculation based on the directed graph. In complex long-link scenarios such as task scheduling and lineage analysis in the big data field, it can quickly output the complete link from the starting node to a certain affected target node, thereby obtaining all affected scheduling tasks or business tables and business fields, thus improving the efficiency of recursive queries and reducing the probability of query failure.

[0088] Based on the above embodiments, the following is combined with Figure 3 The recursive query processing method provided in the embodiments of this application will be further described.

[0089] Figure 3 A flowchart illustrating a query processing method provided in this application embodiment. Figure 2 ,like Figure 3 As shown, it includes:

[0090] S301. When it is determined that the statement to be processed is a recursive query statement, extract the table name and recursive conditions from the recursive query statement.

[0091] S302. Construct a directed graph based on the table name and recursion conditions.

[0092] The specific implementation methods shown in S301-S302 of this application embodiment are the same as those shown in the embodiment of this application. Figure 2 The specific implementation methods shown in S201-S202 of the embodiments are similar, and will not be described again here.

[0093] S303. Obtain the maximum depth of nodes and the total number of paths based on a directed graph.

[0094] In some embodiments, after obtaining a directed graph, the directed graph can be reverse topologically sorted to determine the processing order between nodes, and the depth of each node can be calculated using dynamic programming to determine the maximum depth.

[0095] For example, the initial depth of all nodes is set to 0, and the in-degree of the starting node is set to 0; starting from the starting node, each node is traversed in reverse topological order to obtain the depth of each node's neighboring nodes; the maximum depth is determined based on the depth of the neighboring nodes.

[0096] In this context, the in-degree of a node is the number of edges pointing to that node in the directed graph.

[0097] For example, each node is initialized by setting its initial depth[i] to 0, setting the in-degree of the starting node to 0, and removing edges pointing to the starting node to avoid loops.

[0098] Starting from the initial node, traverse the nodes in reverse topological order. For each node u, recursively update the depth of its neighboring node v.

[0099] Since the default edge weight of a borderless graph is 1, the depth of a neighboring node v satisfies the following formula:

[0100] depth[v]=max(depth[v], depth[u] + 1)

[0101] The maximum depth of each neighboring node is taken as the maximum depth of the node in the directed graph.

[0102] In some embodiments, after obtaining a directed graph, a reverse graph of the directed graph can be constructed, and the reverse graph can be processed using topological sorting and dynamic programming to count the total number of paths for each node and determine the total number of paths.

[0103] For example, the edges of the directed graph are reversed to obtain a reverse graph; starting from the target node, the in-degree of the target node's neighboring nodes is updated sequentially to obtain the number of paths between the target node and its neighboring nodes; the target node is the node with an in-degree of 0 in the reverse graph; based on the number of paths between the target node and its neighboring nodes, the total number of paths is obtained.

[0104] For example, reverse all edges of a directed graph so that the terminal node becomes the initial node with an in-degree of 0. Create a dictionary of total paths, initializing the path count of the terminal node to 1 and the others to 0. Using topological sorting, start from the initial node, process each node, update the in-degree and total path count of its neighbors (in-degree decreases by 1, path count increases by 1), process the nodes whose in-degree becomes 0 and their neighbors in turn, obtain the total path count of each neighbor, and sum the path count of the target node and the total path count of each neighbor to obtain the total path count.

[0105] S304. Divide the directed graph into multiple subgraphs based on the maximum depth and the total number of paths.

[0106] In some embodiments, the number of recursion levels of the directed graph can be determined based on the total number of paths; the number of splits can be determined based on the maximum depth and the number of recursion levels; and the directed graph can be split based on the number of splits to obtain multiple subgraphs.

[0107] For example, the total number of paths can be used to indicate the complexity of recursive query results; the more paths there are, the more complex the recursive query results. To reduce the complexity of recursive queries, the recursion level of the directed graph can be determined based on the total number of paths. For instance, the more paths there are, the larger the recursion level, and vice versa. It should be understood that the specific correspondence between the total number of paths and the recursion level can be set based on actual needs, and this application does not limit this.

[0108] In some embodiments, after determining the number of recursion levels, the number of times the directed graph needs to be split can be determined based on the ratio between the maximum depth and the number of recursion levels. The directed graph is then split into multiple subgraphs based on this number of splits.

[0109] In some embodiments, when splitting a directed graph based on the number of splits, the starting node can be used as the input for a query to find the node in the directed graph whose maximum depth is the number of recursion levels, thus obtaining a first subgraph; the end node in the first subgraph can be used as the input for a query to find the node in the directed graph whose maximum depth is the number of recursion levels, thus obtaining a second subgraph; the process of obtaining a new subgraph based on the end node of the previous subgraph is repeated until the number of subgraphs obtained is consistent with the number of splits.

[0110] For example, if the recursion level is determined to be 3 based on the total number of paths, and the maximum depth is 12, then the number of splits is 4, meaning that the directed graph needs to be split 4 times.

[0111] Using the starting node of the directed graph as input for the first split (query), query the directed graph for nodes with a depth of 3 (recursively down 3 levels), determine all included nodes and the parent-child relationships and depths between nodes, and obtain the first subgraph.

[0112] Using the terminal node of the first subgraph as the input for the second split, we query the directed graph for the node with a maximum depth of 3, determine all the nodes it includes, as well as the parent-child relationships and depths between the nodes, to obtain the second subgraph.

[0113] Perform a third split on the second subgraph, similar to the first, to obtain the third subgraph. Then, perform a fourth split on the third subgraph, similar to the first, to obtain the fourth subgraph, thus completing the splitting of the directed graph.

[0114] In some embodiments, if the number of splits has not yet reached the set number during the splitting process, and the split subgraph already includes the end node of the directed graph, it indicates that the splitting of the directed graph has been completed, and subsequent splitting is stopped.

[0115] It should be understood that if the subgraph obtained after the split (such as the fourth subgraph mentioned above) does not include the end node of the directed graph, then the directed graph corresponding to the remaining nodes in the directed graph will be taken as the last subgraph.

[0116] S305. Determine the links from the starting node to the target node based on multiple subgraphs.

[0117] In some embodiments, after obtaining the target node and each subgraph, the links between the starting node and the target node can be determined by traversing each subgraph.

[0118] For example, traverse each subgraph to determine the target subgraph that includes the target node; obtain the path between the end node and the target node in each target subgraph; associate the paths in each target subgraph to obtain the link between the starting node and the target node.

[0119] For example, traverse each subgraph and search for the node value or node identifier of each subgraph. If the node value or node identifier of any node in the subgraph is consistent with the node value or node identifier of the target node, then mark the subgraph as the target subgraph.

[0120] For any target subgraph, take the target node as the starting node and obtain the path between the target node and the end node in the target subgraph; take the end node of the current target subgraph as the starting node of the next target subgraph and obtain the path between the starting node and the end node; repeat the process of obtaining the path between the starting node and the end node in the next target subgraph until all target subgraphs have been processed.

[0121] For example, for any target subgraph, find the terminal node (the node with an out-degree of 0) in the current subgraph. Using the target node as the starting node, use a depth-first search strategy starting from the starting node, checking the connectivity with the terminal node, and recording all paths. Then, using the terminal node of the current subgraph as input (the starting node), pass it to the previous subgraph, repeating the same depth-first search strategy starting from the starting node, checking the connectivity with the terminal node, and recording all paths, until all paths are found in the target subgraphs. Finally, associate the path fragments found in all the target subgraphs to form a complete path from the original starting node to the target node.

[0122] In summary, the recursive query processing method provided in this application transforms the recursive query of complex long-link databases in big data task scheduling and lineage analysis into graph topology and recursion. This significantly reduces the memory usage of the database's built-in recursive functions and the redundant calculation of intermediate associations, effectively avoiding query failures and improving query speed.

[0123] Based on the above embodiments, this application also provides a recursive query processing device.

[0124] Figure 4 This is a schematic diagram of the recursive query processing device 40 provided in the embodiments of this application, as shown below. Figure 4 As shown, it includes:

[0125] The extraction module 401 is used to extract the table name and recursive conditions from the recursive query statement when it is determined that the statement to be processed is a recursive query statement.

[0126] Processing module 402 is used to construct a directed graph based on the table name and recursion conditions, and obtain the maximum depth of nodes and the total number of paths based on the directed graph.

[0127] Splitting module 403 is used to split a directed graph into multiple subgraphs based on the maximum depth and the total number of paths.

[0128] Output module 404 is used to determine the links from the starting node to the target node based on multiple subgraphs and output the links.

[0129] In some embodiments, the processing module 402 is configured to set the initial depth of all nodes to 0 and the in-degree of the starting node to 0; starting from the starting node, traverse each node in reverse topological order to obtain the depth of the neighboring nodes of each node; and determine the maximum depth based on the depth of the neighboring nodes.

[0130] In some embodiments, the processing module 402 is used to reverse the edges of the directed graph to obtain a reverse graph; starting from the target node, the in-degree of the target node's neighboring nodes is updated sequentially to obtain the number of paths between the target node and its neighboring nodes; the target node is a node with an in-degree of 0 in the reverse graph; and the total number of paths is obtained based on the number of paths between the target node and its neighboring nodes.

[0131] In some embodiments, the splitting module 403 is used to determine the number of recursion levels of the directed graph based on the total number of paths; determine the number of splits based on the maximum depth and the number of recursion levels; and split the directed graph based on the number of splits to obtain multiple subgraphs.

[0132] In some embodiments, the splitting module 403 is used to query the directed graph for nodes with a maximum depth equal to the recursion level, using the starting node as the input of the query, to obtain a first subgraph; and to query the directed graph for nodes with a maximum depth equal to the recursion level, using the ending node in the first subgraph as the input of the query, to obtain a second subgraph; and to repeat the process of obtaining a new subgraph based on the ending node of the previous subgraph until the number of subgraphs obtained is consistent with the number of splits.

[0133] In some embodiments, the output module 404 is used to traverse each subgraph, determine the target subgraph including the target node, obtain the path between the end node and the target node in each target subgraph, and associate the paths in each target subgraph to obtain the link between the start node and the target node.

[0134] In some embodiments, the output module 404 is configured to, for any target subgraph, take the target node as the starting node, obtain the path between the target node and the end node in the target subgraph; take the end node of the current target subgraph as the starting node of the next target subgraph, obtain the path between the starting node and the end node; and repeat the process of obtaining the path between the starting node and the end node in the next target subgraph until all target subgraphs have been processed.

[0135] In some embodiments, the processing module 402 is configured to obtain the original data corresponding to the recursive query statement based on the table name; determine the nodes of the directed graph based on the original data; and determine the directed edges between the nodes based on the recursive conditions; and construct the directed graph based on the nodes and directed edges.

[0136] The recursive query processing apparatus provided in this application embodiment can execute the recursive query processing method shown in any of the above embodiments. Its principle and technical effect are similar, and will not be described again here.

[0137] This application also provides an electronic device.

[0138] Figure 5 This is a schematic diagram of the structure of the electronic device 50 provided in the embodiments of this application, such as... Figure 5As shown, the electronic device may include: a transceiver 501, a processor 502, and a memory 503. The electronic device may be a server as described in any of the above embodiments.

[0139] Processor 502 executes computer execution instructions stored in memory, causing processor 502 to perform the scheme in the above embodiments. Processor 502 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0140] The memory 503 is connected to the processor 502 via the system bus and completes communication between them. The memory 503 is used to store computer program instructions.

[0141] Transceiver 501 can perform the functions of receiving and sending data and instructions.

[0142] Optionally, the electronic device 50 may also include a communication interface 504, which allows communication and interaction with external or internal devices via the communication interface 503. External devices may be, for example, client devices (e.g., mobile phones, tablets). In specific implementations, if the communication interface 504, memory 503, and processor 502 are implemented independently, they can be interconnected via a bus to complete communication with each other.

[0143] The system bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. Transceivers are used to enable communication between database access devices and other computers (e.g., clients, read-write libraries, and read-only libraries). Memory may include random access memory (RAM) and may also include non-volatile memory.

[0144] Optionally, in a specific implementation, if the communication interface 504, memory 503, and processor 502 are integrated on a single chip, then the communication interface 504, memory 503, and processor 502 can communicate through an internal interface.

[0145] This application also provides a chip for executing instructions, which is used to execute the technical solution of the recursive query processing method in the above embodiments.

[0146] This application also provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the technical solution of the above-described recursive query processing method embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.

[0147] In one possible implementation, a computer-readable medium may include random access memory (RAM), read-only memory (ROM), compact discread-only memory (CD-ROM) or other optical disc storage, disk storage or other magnetic storage devices, or any other medium targeted to carry or to store the required program code in the form of instructions or data structures, and accessible by a computer. Furthermore, any connection is appropriately referred to as a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, Digital Subscriber Line (DSL), or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. As used herein, disks and optical discs include optical discs, laser discs, optical discs, Digital Versatile Discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0148] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the technical solution of the above-described recursive query processing method embodiment. Its implementation principle and technical effects are similar, and will not be repeated here.

[0149] In the specific implementation of the aforementioned terminal device or server, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.

[0150] Those skilled in the art will understand that all or part of the steps in any of the above method embodiments can be implemented by hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium, and when the program is executed, all or part of the steps in the above method embodiments are performed.

[0151] If the technical solution of this application is implemented in software form and sold or used as a product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the technical solution of this application can be embodied in the form of a software product, which is stored in a storage medium and includes a computer program or several instructions. This computer software product enables a computer device (which may be a personal computer, server, network device, or similar electronic device) to execute all or part of the steps of the methods in the embodiments of this application.

[0152] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.

[0153] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0154] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.

[0155] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.

[0156] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.

[0157] If the integrated unit / module is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0158] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.

[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A recursive query processing method, characterized in that, When it is determined that the statement to be processed is a recursive query statement, the table name and recursive conditions in the recursive query statement are extracted. Based on the table name and the recursion condition, construct a directed graph, and obtain the maximum depth of the nodes and the total number of paths based on the directed graph; The directed graph is divided into multiple subgraphs based on the maximum depth and the total number of paths. The links from the starting node to the target node are determined based on the multiple subgraphs, and the links are output.

2. The method according to claim 1, characterized in that, Obtaining the maximum depth of a node based on the directed graph includes: Set the initial depth of all nodes to 0, and set the in-degree of the starting node to 0; Starting from the initial node, traverse each node in reverse topological order to obtain the depth of each node's neighboring nodes. The maximum depth is determined based on the depth of the neighboring nodes.

3. The method according to claim 1, characterized in that, The process of obtaining the total number of paths to nodes based on the directed graph includes: Reverse the edges of the directed graph to obtain a reversed graph; Starting from the target node, the in-degree of the target node's neighboring nodes is updated sequentially to obtain the number of paths between the target node and its neighboring nodes; the target node is the node with an in-degree of 0 in the reverse graph. The total number of paths is obtained based on the number of paths between the target node and its neighboring nodes.

4. The method according to claim 2, characterized in that, The step of splitting the directed graph into multiple subgraphs based on the maximum depth and the total number of paths includes: The number of recursion levels for the directed graph is determined based on the total number of paths. The number of splits is determined based on the maximum depth and the number of recursive layers; The directed graph is split based on the number of splits to obtain multiple subgraphs.

5. The method according to claim 4, characterized in that, The directed graph is split based on the number of splits to obtain multiple subgraphs, including: Using the starting node as the input for the query, the node with a maximum depth equal to the recursion level is queried in the directed graph to obtain the first subgraph; Using the end node in the first subgraph as the input for the query, the node with a maximum depth equal to the recursion level is queried in the directed graph to obtain the second subgraph; Repeat the process of obtaining a new subgraph based on the end node of the previous subgraph until the number of subgraphs obtained is consistent with the number of splits.

6. The method according to any one of claims 1-5, characterized in that, Determining the links from the starting node to the target node based on the multiple subgraphs includes: Traverse each subgraph to determine the target subgraph that includes the target node; Obtain the path between the end node and the target node in each target subgraph; The paths in each of the target subgraphs are associated to obtain the links between the starting node and the target node.

7. The method according to claim 6, characterized in that, The step of obtaining the path between the end node in each of the target subgraphs and the target node includes: For any target subgraph, using the target node as the starting node, obtain the path between the target node and the end node in the target subgraph; Use the end node of the current target subgraph as the starting node of the next target subgraph, and obtain the path between the starting node and the end node; Repeat the process of obtaining the path between the start node and the end node in the next target subgraph until all target subgraphs have been processed.

8. The method according to any one of claims 1-5, characterized in that, The construction of a directed graph based on the table name and the recursion condition includes: Retrieve the original data corresponding to the recursive query statement based on the table name; The nodes of the directed graph are determined based on the original data, and the directed edges between the nodes are determined based on the recursion conditions. Construct the directed graph based on the nodes and the directed edges.

9. A recursive query processing device, characterized in that, include: The extraction module is used to extract the table name and recursive conditions from the recursive query statement when it is determined that the statement to be processed is a recursive query statement. The processing module is used to construct a directed graph based on the table name and the recursion condition, and to obtain the maximum depth of the nodes and the total number of paths based on the directed graph. A splitting module is used to split the directed graph into multiple subgraphs based on the maximum depth and the total number of paths; The output module is used to determine the link from the starting node to the target node based on the multiple subgraphs, and output the link.

10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the method of any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, It stores a computer program, which is executed by a processor to implement the method of any one of claims 1-8.

12. A computer program product, characterized in that, Includes a computer program that, when executed by a controller, implements the method of any one of claims 1-8.