Sql text processing method and device, equipment, storage medium and program product
By converting SQL text into directed graphs and performing graph segmentation, the problem of low accuracy of intelligent chunking of SQL text is solved, and the independent execution of SQL subblocks and interface fluency are achieved.
Patent Information
- Application Number
- CN202510346198.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-11
AI Technical Summary
The existing technology has low accuracy when sql text intelligently chunked, resulting in incomplete chunking results and inability to run independently, increasing database operation complexity and error rate, affecting database performance and data consistency.
By parsing the SQL text into an abstract syntax tree and converting it into a directed graph, the SQL subblock is identified using the graph segmentation method to ensure that each subblock contains complete syntax structure and logical information, and the graph theory algorithm is used for segmentation and rendering, improving the accuracy of chunking.
实现了sql子块的独立执行和可读性,减少了渲染开销,提升了数据库操作的准确性和界面流畅性。
Smart Images

Figure CN120296026A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a SQL text processing method, device, equipment, storage medium and program product. Background Art
[0002] In the field of database management and optimization, intelligent segmentation of SQL text is a key task, which aims to decompose complex SQL scripts into independent and manageable code blocks to improve execution efficiency and maintenance convenience. However, the practice in this field faces significant challenges, especially the accuracy of intelligent segmentation.
[0003] Current smart chunking techniques mainly rely on regular expression matching, syntax parsers, or heuristic rules to try to automatically identify the boundaries of SQL statements, such as key operations such as SELECT, INSERT, UPDATE, and DELETE, as well as the logical relationships between them. However, the flexibility and complexity of the SQL language limits the accuracy of these methods. For example, nested queries, dynamic SQL generation, SQL code in stored procedures and triggers, and complex expressions spanning multiple lines may interfere with the accuracy of smart chunking.
[0004] A direct consequence of the low accuracy of smart chunking is that the chunked SQL statements may not be able to run independently. Since the start and end positions of SQL statements cannot be accurately identified, the chunking results may contain incomplete SQL commands, such as missing WHERE clauses, JOIN conditions, or necessary table names. In addition, the loss of contextual information is also a common problem, because smart chunking technology often has difficulty capturing the dependencies between SQL statements, such as the result of a query statement being used as a condition for another update statement.
[0005] Therefore, although the intelligent segmentation method in the prior art performs well in some simple scenarios, its accuracy and practicality are greatly reduced when processing complex SQL scripts. This not only increases the complexity and error rate of database operations, but may also have an adverse impact on database performance and data consistency. Therefore, improving the accuracy of intelligent segmentation of SQL texts is a key issue that needs to be urgently addressed in the current field of database management and optimization. Summary of the invention
[0006] The embodiments of the present application provide a method, apparatus, device, storage medium and program product for processing instruction sql text, so as to achieve the effect of improving the accuracy of sql segmentation.
[0007] In a first aspect, an embodiment of the present application provides a sql text processing method, comprising:
[0008] Generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text;
[0009] Based on the graph nodes and edges in the directed graph, perform graph segmentation on the directed graph, and determine at least one corresponding SQL sub-block based on at least one sub-graph obtained from the graph segmentation; the SQL sub-block includes at least part of the target SQL text;
[0010] In response to a call instruction, render the target SQL text in the SQL sub-block corresponding to the call instruction;
[0011] Display the rendered target SQL text.
[0012] In one possible implementation, the step of obtaining the abstract syntax tree corresponding to the target SQL text includes:
[0013] Parse the target SQL text using a preset parser to generate an abstract syntax tree corresponding to the target SQL text.
[0014] In one possible implementation, the generating a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text includes:
[0015] Traverse the abstract syntax tree, identify each node included in the abstract syntax tree and mark it;
[0016] Obtain metadata in the target database corresponding to the target SQL text, and based on the metadata, obtain the dependency relationship between each of the nodes;
[0017] Map each node included in the abstract syntax tree to a graph node, and map the dependency relationship between each of the nodes to an edge between the graph nodes corresponding to each of the nodes, to obtain the directed graph.
[0018] In one possible implementation, the performing graph segmentation on the directed graph based on the graph nodes and edges in the directed graph, and determining at least one corresponding SQL sub-block based on at least one sub-graph obtained from the graph segmentation includes:
[0019] Based on the graph nodes and edges in the directed graph, use the minimum cut algorithm or the maximum flow algorithm to perform graph segmentation on the directed graph to obtain at least one of the sub-graphs;
[0020] Based on the graph nodes and edges in the sub-graph, determine the target SQL text corresponding to each graph node in the sub-graph and the dependency relationship between the target SQL texts corresponding to each graph node in the sub-graph, and form the SQL sub-block based on the target SQL text corresponding to each graph node in the sub-graph and the dependency relationship between the target SQL texts corresponding to each graph node in the sub-graph.
[0021] In a possible implementation manner, before rendering the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction, it further includes:
[0022] Loading the target SQL text in the SQL sub-block and storing the loaded SQL block in the local cache;
[0023] The rendering of the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction includes:
[0024] In response to the call instruction, obtaining the target SQL text in the SQL block corresponding to the call instruction from the local cache and performing rendering.
[0025] In a possible implementation manner, the rendering of the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction further includes:
[0026] Based on the target SQL text corresponding to each graph node in the sub-graph and the dependency relationship between the target SQL texts corresponding to the graph nodes in the sub-graph, determining, from the SQL sub-block, the SQL blocks adjacent to the SQL sub-block corresponding to the call instruction, and rendering the target SQL text in the SQL blocks adjacent to the SQL sub-block corresponding to the call instruction.
[0027] In a second aspect, an embodiment of the present application provides an SQL text processing device, including:
[0028] A generation module, configured to generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text;
[0029] A splitting module, configured to perform graph splitting on the directed graph based on the graph nodes and edges in the directed graph, and determine at least one corresponding SQL sub-block based on at least one sub-graph obtained by the graph splitting; the SQL sub-block includes at least part of the target SQL text;
[0030] A rendering module, configured to render the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction;
[0031] A display module, configured to display the rendered target SQL text.
[0032] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0033] The memory stores computer execution instructions;
[0034] The processor executes the computer-executable instructions stored in the memory, such that the processor performs the above first aspect and / or various possible implementation manners of the first aspect.
[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the above first aspect and / or various possible implementation manners of the first aspect.
[0036] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which when executed by a processor, implements the above first aspect and / or various possible implementation manners of the first aspect.
[0037] The SQL text processing method, device, equipment, storage medium and program product provided by the embodiments of the present application can parse the SQL text into a syntax tree and further convert it into a directed graph, which can clearly represent each element in the target SQL text and the relationships between them. This representation is more intuitive and easier to analyze than a simple SQL text or syntax tree. In the directed graph, each part of the target SQL text is represented as graph nodes and edges. By analyzing the connection relationships of these graph nodes and edges, different logical blocks or subqueries in the target SQL text can be more accurately identified. This graph-structure-based segmentation method is more flexible and accurate than a text-matching-based segmentation method, and can ensure that each segmented SQL sub-block contains a complete syntax structure and necessary logical information, which means that each SQL sub-block can be executed as an independent SQL statement without relying on other SQL sub-blocks or external contexts. Further, by rendering the target SQL text corresponding to the visible area, the readability of the target SQL text can be improved, and at the same time, the rendering overhead of the target SQL text in the non-visible area can be reduced, thereby ensuring the interface fluency of the first terminal. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0039] Figure 1 It is a schematic diagram of the application environment of the SQL text processing method provided by the present application;
[0040] Figure 2 It is a schematic flowchart of the SQL text processing method provided by the present application;
[0041] Figure 3 It is a schematic structural diagram of the SQL text processing device provided by the present application;
[0042] Figure 4 Structural schematic diagram of the electronic device provided by this application.
[0043] Through the above-mentioned drawings, specific embodiments of this application have been shown, and there will be more detailed descriptions hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. Specific embodiments
[0044] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. On the contrary, they are merely examples of devices and methods consistent with some aspects of this application as detailed in the appended claims.
[0045] The SQL text processing method provided by the embodiments of this application can be applied to an application environment as Figure 1 shown. Among them, the first terminal 102 on the database side is communicatively connected to the first server 104, the second terminal 106 is communicatively connected to the second server 108, and the second terminal 106 can communicate directly or indirectly with the first terminal 102 or the first server 104 in a wired or wireless manner. The second server 108 can communicate directly or indirectly with the first terminal 102 or the first server 104 in a wired or wireless manner.
[0046] For example, when the SQL text processing method is applied to the first terminal 102, the first terminal 102 can store the target SQL text in the data storage system after receiving the target SQL text sent by the second terminal 106 or the second server 108, and then generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text; and based on the graph nodes and edges in the directed graph, perform graph segmentation on the directed graph, and then determine at least one corresponding SQL sub-block based on at least one sub-graph obtained by the graph segmentation; the SQL sub-block contains at least part of the target SQL text; further, in response to a call instruction, render the target SQL text in the SQL sub-block corresponding to the call instruction; finally, display the rendered target SQL text. Among them, the first terminal 102 and the second terminal 106 can be, but are not limited to, various personal computers, laptop computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, etc. The portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The first server 104 and the second server 108 can be implemented by an independent server or a server cluster composed of multiple servers.
[0047] For another example, the SQL text processing method is applied to the first server 104. After receiving the target SQL text sent by the second terminal 106 or the second server 108, the first server 104 can store the target SQL text in the data storage system, and then generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text; and based on the graph nodes and edges in the directed graph, perform graph segmentation on the directed graph, and then determine at least one corresponding SQL sub-block based on at least one sub-graph obtained by the graph segmentation; the SQL sub-block contains at least part of the target SQL text; further, in response to a call instruction, render the target SQL text in the SQL sub-block corresponding to the call instruction; finally, display the rendered target SQL text. It can be understood that the data storage system can be an independent storage device, or the data storage system is located on the first server 104, or the data storage system is located on another terminal.
[0048] In one embodiment, a SQL text processing method is provided. In this embodiment, it is exemplified that the SQL text processing method is applied to the first terminal. As Figure 2 shown, the SQL text processing method includes:
[0049] Step 202, generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text.
[0050] The target SQL text can be sent by the second terminal or the second server to the first terminal. As an example, the user can input the target SQL text through a specified interface in the human-computer interaction interface of the second terminal. The specified interface can be, for example, a command line interface, a graphical user interface, or an application program interface.
[0051] The user can be a database administrator, a developer, or a user of the database. They write the target SQL text according to their needs and send these statements to the first terminal of the database through the terminal to perform actions such as querying, updating, inserting, or deleting statements on the metadata stored in the database.
[0052] It should be noted that before generating the directed graph corresponding to the target SQL text, the first terminal needs to parse the target SQL text and convert it into a structured representation, that is, an abstract syntax tree (AST). The abstract syntax tree is a tree-like data structure used to represent the syntax structure of a programming language, specifically referring to the syntax structure of the target SQL text. In the AST, each node represents an element in the target SQL text (such as keywords like SELECT, FROM, WHERE, etc., or identifiers like table names and column names), and the connections between the nodes represent the syntactic relationships between these elements.
[0053] Further, the first terminal can construct a corresponding directed graph based on the parsed AST.
[0054] A directed graph is a data structure in graph theory, composed of graph nodes and edges connecting these graph nodes, and the edges connecting the graph nodes are directed. The graph nodes of the directed graph can correspond to the nodes in the AST (i.e., elements in the target SQL text), and the edges of the directed graph are used to represent the dependency relationships between these elements, such as logical or execution order relationships. For example, during the SQL query process, the SELECT clause depends on the FROM clause to determine the data source, so this dependency relationship can be represented by a directed edge from the FROM node to the SELECT node in the directed graph.
[0055] Step 204: Based on the graph nodes and edges in the directed graph, perform graph partitioning on the directed graph, and determine at least one corresponding SQL sub-block based on at least one sub-graph obtained from the graph partitioning; the SQL sub-block contains at least part of the target SQL text.
[0056] A sub-graph refers to a smaller and relatively independent graph split from the directed graph. It contains a part of the graph nodes and edges of the directed graph and retains the connection relationships between these graph nodes and edges.
[0057] An SQL sub-block refers to a smaller and relatively independent fragment of the SQL text extracted from the target SQL text. It usually corresponds to a sub-graph obtained after graph partitioning and retains the dependency relationships of the SQL elements represented by the graph nodes in the sub-graph, that is, logical or execution order relationships.
[0058] For example, the first terminal needs to first analyze the structure of the directed graph and determine a suitable graph partitioning strategy based on the analysis results. The goal of graph partitioning is to split the directed graph into multiple smaller and relatively independent sub-graphs, and each sub-graph should contain at least one set of closely related nodes and edges.
[0059] The partitioning strategy may be based on multiple factors, such as the connection density of nodes, the weights of edges, and the logical structure of the target SQL text, etc.
[0060] For each sub-graph obtained from the partitioning, it is necessary to map it back to the original target SQL text to determine the corresponding SQL sub-block. This usually involves identifying the positions of the nodes in the sub-graph in the target SQL text and extracting the fragments of the target SQL text containing these nodes.
[0061] Step 206: In response to the call instruction, render the target SQL text in the SQL sub-block corresponding to the call instruction.
[0062] When the target SQL text received by the first terminal from the second terminal or the second server at the user side is relatively long, the staff on the database side can view different parts of the target SQL text by sliding the visual area on the viewing interface of the first terminal. The staff on the database side can perform the sliding operation of the visual area by means of the mouse wheel, touch screen sliding, keyboard shortcuts, etc. At this time, it can be considered that the staff issues a call instruction on the viewing interface of the first terminal. The first terminal calculates the position of the new visual area according to the sliding operation (i.e., the call instruction) of the staff, which usually involves calculating the sliding distance, determining the new start point and end point, etc. Among them, the sliding operation of the visual area can correspond to the target SQL text in different SQL sub-blocks, that is, every time the staff slides the visual area, it corresponds to selecting different SQL word blocks.
[0063] Subsequently, according to the position of the new visual area, the first terminal can determine the target SQL text in the SQL sub-block that needs to be loaded, and further perform automatic and efficient rendering on it.
[0064] Step 208, display the rendered target SQL text.
[0065] In the above SQL text processing method, by parsing the SQL text into a syntax tree and further converting it into a directed graph, the various elements in the target SQL text and their relationships can be clearly represented. This representation method is more intuitive and easier to analyze than the simple SQL text or syntax tree. In the directed graph, each part of the target SQL text is represented as graph nodes and edges. By analyzing the connection relationships of these graph nodes and edges, different logical blocks or sub-queries in the target SQL text can be more accurately identified. This graph structure-based segmentation method is more flexible and accurate than the text matching-based segmentation method, and can make each segmented SQL sub-block contain a complete syntax structure and necessary logical information. This means that each SQL sub-block can be executed as an independent SQL statement without relying on other SQL sub-blocks or external contexts. Further, by rendering the target SQL text corresponding to the visual area, the readability of the target SQL text can be improved, and at the same time, the rendering overhead of the target SQL text in the non-visual area can be reduced, thereby ensuring the fluency of the interface of the first terminal.
[0066] In some possible embodiments, the step of obtaining the abstract syntax tree corresponding to the target SQL text includes:
[0067] Parse the target SQL text using a preset parser to generate the abstract syntax tree corresponding to the target SQL text.
[0068] Before the first terminal executes step 202, it first selects a preset parser, which is specifically designed to parse SQL text and has built-in syntax rules and lexical analyzers of the SQL language. The parser first performs lexical analysis on the target SQL text. Lexical analysis is the process of decomposing the input SQL text string into a series of meaningful lexical units (tokens), including keywords (such as SELECT, FROM), identifiers (such as table names, column names), operators (such as =, >), delimiters (such as commas, semicolons), etc.
[0069] Secondly, after completing lexical analysis, the parser performs syntax analysis. Syntax analysis is the process of organizing the sequence of lexical units into a syntax tree (i.e., an abstract syntax tree) according to the syntax rules of the SQL language. The abstract syntax tree is a tree-like data structure that represents the syntax structure of the SQL statement.
[0070] The above SQL text processing method converts the target SQL text into an abstract syntax tree through the parser, representing the syntax structure of the target SQL text in a tree-like structure, making the target SQL text more intuitive and easier to understand.
[0071] In some possible embodiments, step 202 includes:
[0072] Traverse the abstract syntax tree, identify each node included in the abstract syntax tree and mark it;
[0073] Obtain the metadata in the target database corresponding to the target SQL text, and based on the metadata, obtain the dependency relationships between the nodes;
[0074] Map each node included in the abstract syntax tree to a graph node, and map the dependency relationships between the nodes to the edges between the corresponding graph nodes of each node to obtain a directed graph.
[0075] In this embodiment, for example, the first terminal can start from the root node of the abstract syntax tree and traverse the entire tree structure in a depth-first or breadth-first manner to comprehensively check each node in the tree to ensure that none are missed.
[0076] Secondly, during the traversal process, each node in the abstract syntax tree is identified one by one. These nodes represent different components of the target SQL text, such as SELECT statements, FROM clauses, WHERE conditions, etc. Each identified node is marked for subsequent processing. The marking may include information such as the type, location, value of the node.
[0077] Further, the metadata of the target database, i.e., the metadata stored in the database corresponding to the first terminal, is a detailed description of information such as database structure, tables, columns, indexes, etc. The first terminal analyzes the dependency relationships between the various nodes in the abstract syntax tree using the obtained metadata. Such dependency relationships may be reflected in aspects such as the association between tables, the reference between columns, the relationship between functions and parameters, etc. The identification of dependency relationships is crucial for understanding the logic and execution plan of the target SQL text.
[0078] Furthermore, each node in the abstract syntax tree is mapped to a corresponding graph node in a directed graph. This step establishes a conversion from a tree structure to a graph structure, enabling the use of graph theory methods to analyze the structure and dependency relationships of the target SQL text. Also, based on the dependency relationships between the nodes in the abstract syntax tree, edges are added between the corresponding graph nodes in the directed graph. These edges represent the dependencies or associations between the graph nodes and constitute the core structure of the directed graph.
[0079] After the above steps, a complete directed graph is finally obtained, which contains the graph representations of all the nodes in the abstract syntax tree and their dependency relationships.
[0080] The above SQL text processing method accurately captures each component in the target SQL text by traversing the abstract syntax tree and identifying the nodes, which helps to reduce syntax errors and semantic ambiguities and improve the accuracy of the execution of the target SQL text. Also, by obtaining the metadata in the target database and determining the dependency relationships between the nodes based on the metadata, an in-depth understanding of the target SQL text and database metadata is achieved. And after mapping the nodes and dependency relationships in the abstract syntax tree to the graph nodes and edges of the directed graph, complex analysis of the target SQL text can be performed using graph theory methods, providing strong support for subsequent processing.
[0081] In some possible embodiments, step 204 includes:
[0082] Based on the graph nodes and edges in the directed graph, the directed graph is graph partitioned using the minimum cut algorithm or the maximum flow algorithm to obtain at least one subgraph;
[0083] Based on the graph nodes and edges in the subgraph, the target SQL text corresponding to each graph node in the subgraph and the dependency relationships between the target SQL texts corresponding to the graph nodes in the subgraph are determined, and SQL sub-blocks are formed based on the target SQL texts corresponding to the graph nodes in the subgraph and the dependency relationships between the target SQL texts corresponding to the graph nodes in the subgraph.
[0084] The directed graph is segmented using the minimum cut algorithm or the maximum flow algorithm. Both of these algorithms are classic methods in graph theory for finding a set of edges in a directed graph such that when these edges are removed, the directed graph is split into two or more unconnected subgraphs.
[0085] In the minimum cut algorithm, the goal is to find a set of edges with the minimum weight such that the directed graph is segmented after removing these edges. In the maximum flow algorithm, usually the minimum cut set is indirectly found by calculating the maximum flow in the directed graph.
[0086] For each subgraph obtained by segmentation, based on the graph nodes and edges therein, the corresponding target SQL text is determined. Since the graph nodes are mapped from the abstract syntax tree, it is possible to directly trace back to the original target SQL text and find the fragment of the target SQL text corresponding to the graph nodes.
[0087] At the same time, it is also necessary to determine the dependency relationships between the graph nodes in the subgraph. These dependency relationships can be deduced from the syntax structure and semantics of the original target SQL text, or can be identified by analyzing the structure of the subgraph. Finally, the SQL text fragments in each subgraph and their dependency relationships are combined into an SQL sub-block.
[0088] The above SQL text processing method, through graph segmentation, can decompose the complex target SQL text into multiple relatively independent SQL sub-blocks. Each SQL sub-block contains a fragment of the complete target SQL text and internal dependency relationships, thus improving the modularity of the target SQL text, which helps to reduce the complexity of the target SQL text.
[0089] In some possible embodiments, before step 206, it further includes:
[0090] Load the target SQL text in the SQL sub-block and store the loaded SQL block in the local cache;
[0091] Step 206 includes:
[0092] In response to the call instruction, obtain the target SQL text in the SQL block corresponding to the call instruction from the local cache and perform rendering.
[0093] The first terminal, for example, can pre-read the target SQL text in several SQL sub-blocks corresponding to the target SQL text from the data storage system and store the target SQL text in several SQL sub-blocks in the local cache. The local cache can be an area in the memory of the first terminal, or a file or database table on the disk.
[0094] The above SQL text processing method can improve the speed and efficiency of subsequent access by storing the target SQL text in several SQL sub - blocks in the local cache. When it is necessary to render the target SQL text in a certain SQL sub - block, the first terminal can directly obtain it from the local cache without having to read it again from the database or other storage media, thus greatly improving the rendering speed.
[0095] In some possible embodiments, step 206 further includes:
[0096] Based on the target SQL text corresponding to each graph node in the sub - graph and the dependency relationship between the target SQL texts corresponding to each graph node in the sub - graph, determine, from the SQL sub - blocks, the SQL sub - blocks adjacent to the SQL sub - block corresponding to the call instruction, and render the target SQL text in the SQL sub - blocks adjacent to the SQL sub - block corresponding to the call instruction.
[0097] In this embodiment, for example, the first terminal can first analyze the dependency relationship between the target SQL text in the SQL sub - block corresponding to the call instruction and the target SQL texts upstream and downstream. These dependency relationships may be manifested as the transfer of data flow, logical sequence, or execution dependencies, etc.
[0098] Subsequently, based on the analysis of the dependency relationship, the first terminal can determine the SQL sub - blocks adjacent to the SQL sub - block corresponding to the call instruction. These adjacent SQL sub - blocks may be the pre - or post - sub - blocks directly dependent on this SQL sub - block, or other sub - blocks at the same logical level but mutually related to this SQL sub - block.
[0099] Furthermore, for the determined adjacent SQL sub - blocks, the first terminal can load their corresponding target SQL texts from the local cache and render the target SQL texts in the adjacent SQL sub - blocks according to the same rules or templates as the SQL sub - block corresponding to the call instruction.
[0100] The above SQL text processing method can predict the viewing actions of the staff and pre - render the target SQL texts in the SQL sub - blocks that may be called in advance by determining and rendering the target SQL texts in the SQL sub - blocks adjacent to the SQL sub - block corresponding to the call instruction. Thus, when the staff views the target SQL texts in the SQL sub - blocks upstream or downstream of the current SQL sub - block, it can be quickly displayed.
[0101] It should be understood that although the steps in the flowcharts involved in the above embodiments are sequentially shown according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, there is no strict order limit for the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.
[0102] Based on the same inventive concept, an embodiment of the present application also provides an SQL text processing device for implementing the SQL text processing method described above. The implementation solution provided by this SQL text processing device for solving problems is similar to the implementation solution described in the above SQL text processing method. Therefore, the specific limitations in one or more of the following device embodiments can refer to the limitations on the SQL text processing method in the above, and will not be repeated here.
[0103] In one embodiment, as Figure 3 shown, an SQL text processing device 300 is provided, including:
[0104] A generation module 302, configured to generate a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text;
[0105] A segmentation module 304, configured to perform graph segmentation on the directed graph based on the graph nodes and edges in the directed graph, and determine at least one corresponding SQL sub-block based on at least one sub-graph obtained by the graph segmentation; the SQL sub-block includes at least part of the target SQL text;
[0106] A rendering module 306, configured to render the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction;
[0107] A display module 308, configured to display the rendered target SQL text.
[0108] In some possible embodiments, the generation module 302 is further configured to:
[0109] Parse the target SQL text using a preset parser to generate an abstract syntax tree corresponding to the target SQL text.
[0110] In some possible embodiments, the generation module 302 is further configured to:
[0111] Traverse the abstract syntax tree, identify each node included in the abstract syntax tree and mark them;
[0112] Obtain the metadata in the target database corresponding to the target sql text, and based on the metadata, obtain the dependency relationships between the nodes;
[0113] Map each node included in the abstract syntax tree to a graph node, and map the dependency relationships between the nodes to the edges between the corresponding graph nodes of each node, to obtain a directed graph.
[0114] In some possible embodiments, the splitting module 304 is further configured to:
[0115] Based on the graph nodes and edges in the directed graph, use the minimum cut algorithm or the maximum flow algorithm to perform graph splitting on the directed graph to obtain at least one subgraph;
[0116] Based on the graph nodes and edges in the subgraph, determine the target sql text corresponding to each graph node in the subgraph and the dependency relationships between the target sql texts corresponding to each graph node in the subgraph, and form sql sub-blocks based on the dependency relationships between the target sql texts corresponding to each graph node in the subgraph and the target sql texts corresponding to each graph node in the subgraph.
[0117] In some possible embodiments, the rendering module 306 is further configured to:
[0118] Load the target sql text in the sql sub-blocks and store the loaded sql blocks in the local cache;
[0119] In response to a call instruction, obtain the target sql text in the sql block corresponding to the call instruction from the local cache and perform rendering.
[0120] In some possible embodiments, the rendering module 306 is further configured to:
[0121] Based on the target sql text corresponding to each graph node in the subgraph and the dependency relationships between the target sql texts corresponding to each graph node in the subgraph, determine the sql blocks adjacent to the sql block corresponding to the call instruction from the sql sub-blocks, and render the target sql text in the sql blocks adjacent to the sql block corresponding to the call instruction.
[0122] The crack identification device provided in this embodiment can execute the method provided in the above method embodiment, and its implementation principle and technical effects are similar, which will not be elaborated here in this embodiment.
[0123] Figure 4 It is a schematic structural diagram of the electronic device provided in this application. As Figure 4As shown in the figure, the electronic device 40 provided in this embodiment includes: at least one processor 401 and a memory 402. Optionally, the device 40 further includes a communication component 403. Among them, the processor 401, the memory 402, and the communication component 403 are connected through a bus 404.
[0124] In the specific implementation process, at least one processor 401 executes the computer-executable instructions stored in the memory 402, so that at least one processor 401 executes the above-mentioned method.
[0125] For the specific implementation process of the processor 401, reference can be made to the above method embodiment. The implementation principle and technical effect are similar, and will not be elaborated here in this embodiment.
[0126] In the above embodiment, it should be understood that the processor may be a central processing unit (English: Central Processing Unit, abbreviated as: CPU), or other general-purpose processors, digital signal processors (English: Digital Signal Processor, abbreviated as: DSP), application specific integrated circuits (English: Application Specific Integrated Circuit, abbreviated as: ASIC), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the invention can be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
[0127] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0128] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.
[0129] This application also provides a computer program product, including a computer program, which implements the above-mentioned method when executed by a processor.
[0130] The present application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above method.
[0131] The above-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disk. The readable storage medium can be any available medium accessible by a general-purpose or special-purpose computer.
[0132] An exemplary readable storage medium is coupled to the processor so that the processor can read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in a device.
[0133] The division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be indirect couplings or communication connections through some interfaces, devices, or units, and can be in electrical, mechanical, or other forms.
[0134] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0135] In addition, in each embodiment of the present invention, the functional units can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0136] If a function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs, and other various media that can store program codes.
[0137] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When this program is executed, it executes the steps including the above method embodiments; and the aforementioned storage medium includes: ROMs, RAMs, magnetic disks, or optical discs, and other various media that can store program codes.
[0138] Finally, it should be noted that those skilled in the art will readily think of other implementations of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses, or adaptations of the present invention, which follow the general principles of the present invention and include the common general knowledge or conventional technical means in the technical field not disclosed in the present invention. It is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present invention is only limited by the appended claims.
Claims
1. A method for processing SQL text, characterized in that, including: generating a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text; performing graph segmentation on the directed graph based on the graph nodes and edges in the directed graph, and determining at least one corresponding SQL sub-block based on at least one sub-graph obtained from the graph segmentation; the SQL sub-block includes at least part of the target SQL text; rendering the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction; displaying the rendered target SQL text.
2. The method according to claim 1, characterized in that, The step of obtaining the abstract syntax tree corresponding to the target SQL text includes: parsing the target SQL text using a preset parser to generate an abstract syntax tree corresponding to the target SQL text.
3. The method according to claim 1, wherein The generating a directed graph corresponding to the target SQL text based on the abstract syntax tree corresponding to the target SQL text includes: traversing the abstract syntax tree, identifying each node included in the abstract syntax tree and marking them; obtaining metadata in the target database corresponding to the target SQL text, and based on the metadata, obtaining the dependency relationships between the nodes; mapping each node included in the abstract syntax tree to a graph node, and mapping the dependency relationships between the nodes to the edges between the corresponding graph nodes of the nodes, to obtain the directed graph.
4. The method according to claim 1, wherein The performing graph segmentation on the directed graph based on the graph nodes and edges in the directed graph, and determining at least one corresponding SQL sub-block based on at least one sub-graph obtained from the graph segmentation includes: performing graph segmentation on the directed graph based on the graph nodes and edges in the directed graph using a minimum cut algorithm or a maximum flow algorithm to obtain at least one sub-graph; determining the target SQL text corresponding to each graph node in the sub-graph and the dependency relationships between the target SQL texts corresponding to the graph nodes in the sub-graph, and forming the SQL sub-block based on the target SQL texts corresponding to the graph nodes in the sub-graph and the dependency relationships between the target SQL texts corresponding to the graph nodes in the sub-graph.
5. The method according to claim 4, wherein Before the rendering the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction, it further includes: loading the target SQL text in the SQL sub-block and storing the loaded SQL block in the local cache; The rendering the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction includes: responding to the call instruction, obtaining the target SQL text in the SQL block corresponding to the call instruction from the local cache and performing rendering.
6. The method according to claim 1, characterized in that, The rendering the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction further includes: based on the target SQL texts corresponding to the graph nodes in the sub-graph and the dependency relationships between the target SQL texts corresponding to the graph nodes in the sub-graph, determining the SQL blocks adjacent to the SQL sub-block corresponding to the call instruction from the SQL sub-block, and rendering the target SQL text in the SQL blocks adjacent to the SQL sub-block corresponding to the call instruction.
7. A SQL text processing device, characterized in that, Comprising: A generation module, configured to generate a directed graph corresponding to the target SQL text based on an abstract syntax tree corresponding to the target SQL text; A splitting module, configured to perform graph splitting on the directed graph based on graph nodes and edges in the directed graph, and determine at least one corresponding SQL sub-block based on at least one sub-graph obtained by the graph splitting; The SQL sub-block contains at least part of the target SQL text; A rendering module, configured to render the target SQL text in the SQL sub-block corresponding to the call instruction in response to the call instruction; A display module, configured to display the rendered target SQL text.
8. An electronic device, characterized in that, Comprising: A memory, a processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, so that the processor executes the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, Computer execution instructions are stored in the computer-readable storage medium, and when the computer execution instructions are executed by the processor, they are used to implement the method according to any one of claims 1-6.
10. A computer program product, characterized in that, Comprising a computer program, which when executed by a processor implements the method according to any one of claims 1-6.
