Method, device and electronic equipment for determining dependency information of database stored procedures

By parsing the source code of the stored procedure and constructing an abstract syntax tree, target metadata is generated and recursively processed, solving the problem of difficulty in obtaining the dependency information of the stored procedure in the existing technology, and realizing the acquisition of complete dependency information and improving accuracy.

CN116069808BActive Publication Date: 2026-03-27INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-03
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

In existing technologies, it is difficult to obtain complete dependency information of stored procedures, especially when some databases cannot be queried through views or searched through source code, making it impossible to parse the logical structure and static SQL statements of stored procedures.

Method used

By parsing the source code of the target stored procedure, an abstract syntax tree is generated, and target metadata is constructed. Based on the target metadata, multiple code nodes are recursively processed to obtain the dependency information of the stored procedure.

Benefits of technology

It enables the complete acquisition of dependency information for stored procedures, simplifies the survey workload, improves the survey accuracy, and can be used for field usage analysis and SQL statement extraction. It also supports feature analysis and performance stress testing during database migration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116069808B_ABST
    Figure CN116069808B_ABST
Patent Text Reader

Abstract

The application discloses a kind of determination method, device and electronic equipment of the dependency information of database stored procedure.It relates to the field of financial technology or other fields, which comprises: code analysis is carried out on the source code of target stored procedure, and a plurality of code nodes are obtained;An abstract syntax tree is generated based on the plurality of code nodes;Target metadata is constructed according to the abstract syntax tree;According to the target metadata, the plurality of code nodes are processed recursively, and the dependency information of the target stored procedure is obtained, the dependency information at least includes first dependency information and second dependency information, the first dependency information is used to represent the stored procedure that there is a dependency relationship with the target stored procedure, and the second dependency information is used to represent the data required to be referenced by the source code of the target stored procedure at runtime.The present application solves the technical problem that the dependency information of the stored procedure cannot be completely obtained in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of financial technology or other fields, in particular, to a method and device for determining dependency information of a database stored procedure and an electronic device. BACKGROUND

[0002] Before performing architecture investigation, partial or whole reconstruction and other work on a system, the stored procedure as a part of an application needs to analyze the structure of the stored procedure, extract dependency information such as called objects and called stored procedures of the stored procedure from the stored procedure, and further perform recursive analysis on the called stored procedures through the dependency information.

[0003] However, in the prior art, only some databases can query coarse-grained dependency information through views, and the other databases do not provide related views, and can only perform investigation by searching source code. Therefore, through the view query and the source code search, the logic structure and the static SQL (Structured Query Language) statements in the stored procedure cannot be parsed, and thus there is a problem that the dependency information of the stored procedure cannot be completely obtained.

[0004] At present, no effective solution has been proposed for the above problem. SUMMARY

[0005] Embodiments of the present application provide a method and device for determining dependency information of a database stored procedure and an electronic device, to at least solve the technical problem that the dependency information of the stored procedure cannot be completely obtained in the prior art.

[0006] According to an aspect of an embodiment of the present application, a method for determining dependency information of a database stored procedure is provided, including: performing code analysis on source code of a target stored procedure to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements stored in a database for completing a target function, and each code node is used to represent a function or a variable in the source code of the target stored procedure; generating an abstract syntax tree based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; constructing target metadata according to the abstract syntax tree, wherein the target metadata at least includes an association relationship between the plurality of code nodes and position information of each code node in the source code of the target stored procedure; and performing recursive processing on the plurality of code nodes according to the target metadata to obtain the dependency information of the target stored procedure, wherein the dependency information at least includes first dependency information and second dependency information, the first dependency information is used to represent a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information is used to represent data required to be referenced by the source code of the target stored procedure at runtime.

[0007] Further, the target metadata is constructed according to the abstract syntax tree, including: parsing the abstract syntax tree to obtain a layer of each tree node in the abstract syntax tree and a connection relationship between all tree nodes in the abstract syntax tree; determining an association relationship between the plurality of code nodes according to the connection relationship; determining the layer of each tree node in the abstract syntax tree as a line number of the code node corresponding to the tree node in the source code of the target stored procedure; determining the position information of each code node in the source code of the target stored procedure according to the line number; and generating the target metadata according to the position information and the association relationship between the plurality of code nodes.

[0008] Further, the target metadata is generated according to the position information and the association relationship between the plurality of code nodes, including: obtaining a calling mode corresponding to each code node; and generating the target metadata according to the calling mode, the position information and the association relationship between the plurality of code nodes.

[0009] Further, the plurality of code nodes are recursively processed according to the target metadata to obtain the dependency information of the target stored procedure, including: randomly selecting a tree node from the abstract syntax tree as a to-be-processed tree node according to the target metadata, and determining a target tree node in the abstract syntax tree that has an association relationship with the to-be-processed tree node and is located at a lower layer of the to-be-processed tree node; determining a starting code node corresponding to the to-be-processed tree node; starting from the starting code node, recursively processing at least one target code node in the plurality of code nodes according to the association relationship between the to-be-processed tree node and the target tree node to obtain first node dependency information and / or second node dependency information corresponding to each target code node, wherein the target code node is a code node corresponding to the target tree node, the first node dependency information is used to represent a stored procedure required to be called by the target code node at runtime, and the second node dependency information is used to represent data required to be referenced by the target code node at runtime; determining first dependency information of the target stored procedure according to the first node dependency information corresponding to each target code node; and determining second dependency information of the target stored procedure according to the second node dependency information corresponding to each target code node.

[0010] Further, starting from the starting code node, at least one target code node in the plurality of code nodes is processed recursively downwards according to the association between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node, including: detecting whether the code node currently being processed recursively downwards is a first code node, wherein the first code node is a code node that needs to call a stored procedure having a dependency relationship with the target stored procedure; when the code node currently being processed recursively downwards is the first code node, detecting whether an iteration identifier exists in the first code node, wherein the iteration identifier is used to indicate that the first code node has completed iteration processing, and the iteration processing is used to perform program code parsing operations on the stored procedure having the dependency relationship with the target stored procedure through the first code node; and when the iteration identifier exists in the first code node, starting from the first code node, at least one target code node in the plurality of code nodes is processed recursively downwards according to the association between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0011] Further, the method for determining dependency information of a database stored procedure further includes: when the iteration identifier does not exist in the first code node, determining that the first code node has not been processed iteratively; processing the first code node iteratively, and after the iteration processing of the first code node is completed, starting from the first code node, at least one target code node in the plurality of code nodes is processed recursively downwards according to the association between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0012] Further, the method for determining dependency information of a database stored procedure further includes: detecting whether the code node currently being processed recursively downwards is a second code node, wherein the second code node is a code node corresponding to the last tree node in the abstract syntax tree; and when the code node currently being processed recursively downwards is the second code node, determining that the code nodes corresponding to all tree nodes in the abstract syntax tree have completed the recursive processing.

[0013] According to another aspect of the embodiments of the present application, there is also provided a device for determining dependency information of a database stored procedure, comprising: an obtaining module configured to perform code parsing on source code of a target stored procedure to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements stored in a database for completing a target function, and each code node is configured to represent a function or a variable in the source code of the target stored procedure; a generating module configured to generate an abstract syntax tree based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; a constructing module configured to construct target metadata according to the abstract syntax tree, wherein the target metadata comprises at least an association relationship between the plurality of code nodes and position information of each code node in the source code of the target stored procedure; and a processing module configured to perform recursive processing on the plurality of code nodes according to the target metadata to obtain dependency information of the target stored procedure, wherein the dependency information comprises at least first dependency information and second dependency information, the first dependency information is configured to represent a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information is configured to represent data required to be referenced by the source code of the target stored procedure at runtime.

[0014] According to another aspect of the embodiments of the present application, there is also provided a computer readable storage medium having a computer program stored therein, wherein the computer program is configured to execute the above-mentioned method for determining dependency information of a database stored procedure when executed.

[0015] According to another aspect of the embodiments of the present application, there is also provided an electronic device comprising one or more processors; and a memory configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a program configured to execute the above-mentioned method for determining dependency information of a database stored procedure.

[0016] According to another aspect of the embodiments of the present application, there is also provided a computer program product comprising computer programs / instructions, which when executed by a processor, implement the above-mentioned method for determining dependency information of a database stored procedure.

[0017] In the embodiment of the present application, the dependency information of the target stored procedure is obtained by recursively processing the plurality of code nodes according to the target metadata. First, the source code of the target stored procedure is parsed to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements stored in a database for completing a target function, and each code node represents a function or a variable in the source code of the target stored procedure. Then, an abstract syntax tree is generated based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree. Then, the target metadata is constructed according to the abstract syntax tree, wherein the target metadata at least includes the association relationship between the plurality of code nodes and the position information of each code node in the source code of the target stored procedure. Finally, the dependency information of the target stored procedure is obtained by recursively processing the plurality of code nodes according to the target metadata, wherein the dependency information at least includes first dependency information and second dependency information, the first dependency information represents a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information represents data required to be referenced by the source code of the target stored procedure at runtime.

[0018] In the above process, the target metadata is constructed according to the abstract syntax tree, and the dependency information of the target stored procedure is obtained by recursively processing the plurality of code nodes according to the target metadata, thereby solving the technical problem that the prior art can only obtain partial dependency information of the stored procedure and it is difficult to obtain complete dependency information of the stored procedure.

[0019] Therefore, the scheme provided in the present application achieves the purpose of obtaining the dependency information of the target stored procedure by recursively processing the plurality of code nodes according to the target metadata, thereby realizing the technical effect of obtaining complete dependency information of the stored procedure, and further solving the technical problem that it is difficult to obtain complete dependency information of the stored procedure in the prior art. BRIEF DESCRIPTION OF DRAWINGS

[0020] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and serve to explain the present application. In the drawings:

[0021] Figure 1 is a schematic diagram of an optional method for determining dependency information of a database stored procedure according to an embodiment of the present application;

[0022] Figure 2 is a flowchart of an optional method for constructing target metadata according to an embodiment of the present application;

[0023] Figure 3 is a flowchart of an optional iterative processing of a database stored procedure according to an embodiment of the present application;

[0024] Figure 4 is a schematic diagram of an optional database stored procedure dependency information determination apparatus according to an embodiment of the present application;

[0025] Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to enable persons skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by persons skilled in the art without creative labor should fall within the protection scope of the present application.

[0027] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to only those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to the process, method, product, or device.

[0028] It should be noted that the database stored procedure dependency information determination method, apparatus and electronic device of the present disclosure can be used in the field of financial technology, and can also be used in any field other than the field of financial technology. The application field of the database stored procedure dependency information determination method, apparatus and electronic device of the present disclosure is not limited.

[0029] It should be noted that the related information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, analyzed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties. For example, an interface is provided between the system and the related user or institution. Before obtaining the related information, the interface needs to send a request for obtaining the information to the aforementioned user or institution, and after receiving the consent information fed back by the aforementioned user or institution, the related information is obtained.

[0030] Embodiment 1

[0031] According to the embodiment of the present application, an embodiment of a method for determining dependency information of a database stored procedure is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0032] For the convenience of understanding the technical solutions of the present application, the following are specific definitions of some key terms in the present application:

[0033] Stored Procedure: an application stored in a database and written in a certain general-purpose programming language.

[0034] Package: a collection of one or more stored procedures aggregated according to certain logical rules.

[0035] Figure 1 The method according to the embodiment of the present application for determining dependency information of a database stored procedure is shown in FIG. Figure 1 The method comprises the following steps:

[0036] Step S101: code analysis is performed on the source code of the target stored procedure to obtain a plurality of code nodes.

[0037] In step S101, the target stored procedure is a set of SQL statements stored in a database for completing a target function, and each code node is used to represent a function or variable in the source code of the target stored procedure.

[0038] In an optional embodiment, a database stored procedure dependency relationship analysis system can be used as the execution subject of the method for determining dependency information of a database stored procedure according to the embodiment of the present application. For the convenience of description, the database stored procedure dependency relationship analysis system is referred to as the system hereinafter.

[0039] Optionally, as shown in FIG. Figure 2 The system can analyze the source code of the target stored procedure by a lexical analyzer (Lexer) to obtain a plurality of code nodes, wherein the code node is a function, character or variable in the source code of the target stored procedure, and then the system can mark the type of each code node, for example, the system marks the code node as an operator (Operator), an identifier (Identity), a keyword (Keyword), a symbol (Symbol), etc.

[0040] Step S102: an abstract syntax tree is generated based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree.

[0041] In step S102, as Figure 2 As shown, the system can organize multiple code nodes into a grammar sequence through the parser to generate an abstract syntax tree (AST), with each code node corresponding to a tree node in the AST.

[0042] Step S103: Construct target metadata based on the abstract syntax tree, wherein the target metadata includes at least the association between multiple code nodes and the location information of each code node in the source code of the target stored procedure.

[0043] In step S103, the system can parse the abstract syntax tree to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree. Based on the connection relationship, the system can determine the association relationship between multiple code nodes. Based on the level of each tree node in the abstract syntax tree, the system can determine the location information of each code node in the source code of the target stored procedure. Based on the location information and the association relationship between multiple code nodes, the system can generate target metadata.

[0044] Step S104: Recursively process multiple code nodes based on the target metadata to obtain the dependency information of the target stored procedure. The dependency information includes at least first dependency information and second dependency information. The first dependency information is used to characterize the stored procedures that have a dependency relationship with the target stored procedure, and the second dependency information is used to characterize the data that the source code of the target stored procedure needs to reference at runtime.

[0045] In step S104, the system recursively processes multiple code nodes based on the target metadata to obtain the dependency information of the target stored procedure. This dependency information can include stored procedures that have a dependency relationship with the target stored procedure, such as stored procedures within a package called by the target stored procedure. The dependency information can also include data that the target stored procedure's source code needs to reference at runtime, such as variables, variable definitions, tables, fields, functions, packages, views, synonyms, and SQL statements called by the target stored procedure's source code at runtime.

[0046] Optional, such as Figure 3 As shown, after obtaining the dependency information of the target stored procedure, the dependency information can be filtered and screened to remove redundant information that is not needed, so as to obtain the dependency information that is needed. For example, the table, view, synonym and other content that is not of interest in the dependency information can be filtered.

[0047] Based on the scheme defined in steps S101 to S104, it can be known that, in the embodiment of the application, the dependency information of the target stored procedure is obtained by recursively processing the plurality of code nodes according to the target metadata. First, the source code of the target stored procedure is parsed to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements for completing a target function stored in a database, and each code node represents a function or a variable in the source code of the target stored procedure. Then, an abstract syntax tree is generated based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree. Then, the target metadata is constructed according to the abstract syntax tree, wherein the target metadata at least includes the association relationship between the plurality of code nodes and the position information of each code node in the source code of the target stored procedure. Finally, the dependency information of the target stored procedure is obtained by recursively processing the plurality of code nodes according to the target metadata, wherein the dependency information at least includes first dependency information and second dependency information, the first dependency information represents a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information represents data required to be referenced by the source code of the target stored procedure at runtime.

[0048] It is easy to note that, in the above process, the dependency information of the target stored procedure is obtained by constructing the target metadata according to the abstract syntax tree and recursively processing the plurality of code nodes according to the target metadata, which solves the technical problem that the prior art can only obtain partial dependency information of the stored procedure and cannot obtain complete dependency information of the stored procedure.

[0049] Therefore, the scheme provided in the application achieves the purpose of obtaining the dependency information of the target stored procedure by recursively processing the plurality of code nodes according to the target metadata, thereby achieving the technical effect of obtaining complete dependency information of the stored procedure, and further solving the technical problem that complete dependency information of the stored procedure cannot be obtained in the prior art.

[0050] Further, the system parses the abstract syntax tree to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree. Then, the association relationship between the plurality of code nodes is determined according to the connection relationship. Then, the level of each tree node in the abstract syntax tree is determined as the line number of the code node corresponding to the tree node in the source code of the target stored procedure. The position information of each code node in the source code of the target stored procedure is determined according to the line number. Finally, the target metadata is generated according to the position information and the association relationship between the plurality of code nodes.

[0051] Optionally, as Figure 2As shown, the system can parse the abstract syntax tree through the syntax tree analyzer (AST Analyzer) to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree, then the system determines the association relationship between the plurality of code nodes according to the connection relationship, then determines the level of each tree node in the abstract syntax tree as the line number of the code node corresponding to the tree node in the source code of the target stored procedure, then the system determines the position information of each code node in the source code of the target stored procedure according to the line number, and finally the system generates the target metadata according to the position information and the association relationship between the plurality of code nodes.

[0052] It should be noted that the system determines the association relationship between the plurality of code nodes and the position information of each code node in the source code of the target stored procedure based on the level of the abstract syntax tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree by parsing the abstract syntax tree, and generates the target metadata according to the association relationship and the position information, which makes the dependency relationship analysis possible and prepares for subsequent recursive processing of the plurality of code nodes according to the target metadata.

[0053] In an optional embodiment, the system obtains the calling mode corresponding to each code node, and then generates the target metadata according to the calling mode, the position information, and the association relationship between the plurality of code nodes.

[0054] Optionally, in this embodiment, the system obtains the calling mode corresponding to each code node, and then generates the target metadata according to the calling mode, the position information, and the association relationship between the plurality of code nodes. For example, when the code node is a call to a stored procedure in a package, the system records that the code node is a call node (call) and obtains the calling mode, and then generates the target metadata based on the calling mode, the position information, and the association relationship between the plurality of code nodes.

[0055] It should be noted that the system generates the target metadata based on the calling mode, the position information, and the association relationship between the plurality of code nodes, which makes the dependency relationship analysis possible and prepares for subsequent recursive processing of the plurality of code nodes according to the target metadata.

[0056] Further, the system randomly selects a tree node from the abstract syntax tree as a to-be-processed tree node according to the target metadata, determines a target tree node that has an association relationship with the to-be-processed tree node and is located at a lower layer of the to-be-processed tree node in the abstract syntax tree, and determines a code node corresponding to the to-be-processed tree node as a starting code node. Then, the system starts from the starting code node, recursively processes at least one target code node in the plurality of code nodes according to the association relationship between the to-be-processed tree node and the target tree node, and obtains first node dependency information and / or second node dependency information corresponding to each target code node, wherein the target code node is a code node corresponding to the target tree node, the first node dependency information is used to represent a stored procedure that needs to be called by the target code node at runtime, and the second node dependency information is used to represent data that needs to be referenced by the target code node at runtime. Finally, the system determines first dependency information of the target stored procedure according to the first node dependency information corresponding to each target code node, and determines second dependency information of the target stored procedure according to the second node dependency information corresponding to each target code node.

[0057] Optionally, as shown in Figure 3 When the system recursively processes the plurality of code nodes according to the target metadata, the system randomly selects a tree node from the abstract syntax tree as a to-be-processed tree node according to the target metadata, determines a target tree node that has an association relationship with the to-be-processed tree node and is located at a lower layer of the to-be-processed tree node, and then the system takes a code node corresponding to the to-be-processed tree node as a starting code node, starts from the starting code node, recursively processes each target code node corresponding to the target tree node, and obtains first node dependency information and / or second node dependency information corresponding to each target code node. Then, the system determines first dependency information of the target stored procedure based on each first node dependency information, and determines second dependency information of the target stored procedure based on each second node dependency information, wherein the starting code node also needs to be recursively processed.

[0058] It should be noted that by recursively processing the plurality of code nodes according to the target metadata, the dependency information of the target stored procedure is obtained, which solves the technical problem that the prior art can only obtain part of the dependency information of the stored procedure and it is difficult to obtain complete dependency information of the stored procedure.

[0059] Further, the system detects whether the code node currently undergoing the downward recursive processing is a first code node, wherein the first code node is a code node requiring calling a stored procedure having a dependency relationship with the target stored procedure; then detects whether an iteration identifier exists in the first code node when the code node currently undergoing the downward recursive processing is the first code node, wherein the iteration identifier is used to represent that the first code node has completed iteration processing, and the iteration processing is used to perform program code parsing operations on the stored procedure having the dependency relationship with the target stored procedure through the first code node; and finally, when the iteration identifier exists in the first code node, the system performs downward recursive processing on at least one target code node in the plurality of code nodes starting from the first code node according to the association relationship between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0060] Optionally, as shown in Figure 3 the system detects whether the code node currently undergoing the downward recursive processing is a first code node, wherein the first code node is a code node requiring calling a stored procedure having a dependency relationship with the target stored procedure; when the code node currently undergoing the downward recursive processing is the first code node, the system detects whether an iteration identifier exists in the first code node, and if the iteration identifier exists in the first code node, the system determines that the first code node has completed iteration, i.e., has performed program code parsing operations on the stored procedure having the dependency relationship with the target stored procedure through the first code node, and marks the iteration identifier for the first code node, wherein the iteration identifier is used to represent that the first code node has completed iteration processing. Then, the system performs downward recursive processing on at least one target code node in the plurality of code nodes starting from the first code node according to the association relationship between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0061] Optionally, the iteration processing is that the system performs program code parsing operations on the stored procedure having the dependency relationship with the target stored procedure through the first code node. Specifically, the system performs parsing on the program code of the stored procedure having the dependency relationship with the target stored procedure through a lexical tokenizer (Lexer) to obtain a plurality of code nodes, organizes the plurality of code nodes into a syntax sequence through a syntax analyzer (Parser) to generate an abstract syntax tree, and performs parsing on the abstract syntax tree through an abstract syntax tree analyzer (ASTAnalyzer) to generate target metadata.

[0062] Further, the system determines that the first code node is not iterated when the iteration identifier is not present in the first code node, and then iterates the first code node. After the iteration of the first code node is completed, the system starts from the first code node, and according to the association relationship between the tree node to be processed and the target tree node, recursively processes at least one target code node in the plurality of code nodes, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0063] Optionally, as shown in FIG. 1, when the iteration identifier is not present in the first code node, the system determines that the first code node is not iterated, and then iterates the first code node. After the iteration of the first code node is completed, the system takes the first code node as an initial code node, and according to the association relationship between the tree node to be processed and the target tree node, recursively processes at least one target code node in the plurality of code nodes, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node. Figure 3

[0064] It should be noted that by detecting whether the iteration identifier is present in the first code node, the occurrence of repeated iteration or dead loop can be avoided.

[0065] Further, the system detects whether the code node currently being recursively processed is the second code node, where the second code node is the code node corresponding to the last tree node in the abstract syntax tree. When the code node currently being recursively processed is the second code node, the system determines that the code nodes corresponding to all tree nodes in the abstract syntax tree have completed the recursive processing.

[0066] Optionally, the system detects whether the code node currently being recursively processed is the second code node, where the second code node is the code node corresponding to the last tree node in the abstract syntax tree. When the code node currently being recursively processed is the second code node, the system determines that the code nodes corresponding to all tree nodes in the abstract syntax tree have completed the recursive processing, and ends the recursive processing. When the code node currently being recursively processed is not the code node corresponding to the last tree node in the abstract syntax tree, the system continues to recursively process the next code node corresponding to the code node.

[0067] ​Therefore, the application provides a method for determining dependency information of a database stored procedure, which can recursively process a plurality of code nodes according to target metadata to obtain complete dependency information of a target stored procedure, solves the technical problem that it is difficult to completely obtain the dependency information of the stored procedure in the prior art, and greatly simplifies the investigation workload of the inventory stored procedure program, improves the accuracy of the investigation work, and can also be used to solve the problems of field usage analysis, SQL statement extraction (SQL statement extraction can be used for characteristic analysis and performance stress testing during migration between different databases), and the like.

[0068] Embodiment 2

[0069] According to the embodiment of the application, an embodiment of a device for determining dependency information of a database stored procedure is provided, wherein, Figure 4 An optional schematic diagram of the device for determining dependency information of a database stored procedure according to the embodiment of the application is shown in Figure 4 The device comprises:

[0070] The parsing module 401 is configured to parse source code of a target stored procedure to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements stored in a database for completing a target function, and each code node is used to represent a function or a variable in the source code of the target stored procedure; the generating module 402 is configured to generate an abstract syntax tree based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; the constructing module 403 is configured to construct target metadata according to the abstract syntax tree, wherein the target metadata at least includes an association relationship between the plurality of code nodes and position information of each code node in the source code of the target stored procedure; and the processing module 404 is configured to recursively process the plurality of code nodes according to the target metadata to obtain dependency information of the target stored procedure, wherein the dependency information at least includes first dependency information and second dependency information, the first dependency information is used to represent a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information is used to represent data required to be referenced by the source code of the target stored procedure during runtime.

[0071] It should be noted that the parsing module 401, the generating module 402, the constructing module 403, and the processing module 404 correspond to steps S101 to S104 in the above embodiment, and the four modules have the same examples and application scenarios as the corresponding steps, but are not limited to the content disclosed in the above embodiment 1.

[0072] Optionally, the constructing module further comprises a first parsing module, a first determining module, a second determining module, a third determining module and a first generating module. The first parsing module is configured to parse the abstract syntax tree to obtain a layer of each tree node in the abstract syntax tree and a connection relationship between all tree nodes in the abstract syntax tree; the first determining module is configured to determine an association relationship between the plurality of code nodes according to the connection relationship; the second determining module is configured to determine that the layer of each tree node in the abstract syntax tree is a line number of the code node corresponding to the tree node in the source code of the target stored procedure; the third determining module is configured to determine the position information of each code node in the source code of the target stored procedure according to the line number; and the first generating module is configured to generate the target metadata according to the position information and the association relationship between the plurality of code nodes.

[0073] Optionally, the first generating module further comprises a first obtaining module and a second generating module. The first obtaining module is configured to obtain the calling mode corresponding to each code node; and the second generating module is configured to generate the target metadata according to the calling mode, the position information and the association relationship between the plurality of code nodes.

[0074] Optionally, the processing module comprises a first processing module, a fourth determining module, a second processing module, a fifth determining module and a sixth determining module. The first processing module is configured to randomly select a tree node from the abstract syntax tree as a to-be-processed tree node according to the target metadata, and determine that a tree node associated with the to-be-processed tree node and located at a lower layer of the to-be-processed tree node in the abstract syntax tree is a target tree node; the fourth determining module is configured to determine that the code node corresponding to the to-be-processed tree node is a starting code node; the second processing module is configured to start from the starting code node, and perform downward recursive processing on at least one target code node in the plurality of code nodes according to the association relationship between the to-be-processed tree node and the target tree node, to obtain first node dependency information and / or second node dependency information corresponding to each target code node, wherein the target code node is the code node corresponding to the target tree node, the first node dependency information is used to represent a stored procedure required to be called by the target code node at runtime, and the second node dependency information is used to represent data required to be referenced by the target code node at runtime; the fifth determining module is configured to determine first dependency information of the target stored procedure according to the first node dependency information corresponding to each target code node; and the sixth determining module is configured to determine second dependency information of the target stored procedure according to the second node dependency information corresponding to each target code node.

[0075] Optionally, the second processing module comprises a first detection module, a second detection module and a third processing module. The first detection module is configured to detect whether the code node currently being subjected to the downward recursion processing is a first code node, wherein the first code node is a code node requiring a storage procedure dependent on the target storage procedure to be invoked; the second detection module is configured to detect whether an iteration identifier exists in the first code node when the code node currently being subjected to the downward recursion processing is the first code node, wherein the iteration identifier is used to indicate that the first code node has completed iteration processing, and the iteration processing is used to perform a program code parsing operation on the storage procedure dependent on the target storage procedure through the first code node; and the third processing module is configured to, when the iteration identifier exists in the first code node, start from the first code node, and perform the downward recursion processing on at least one target code node in the plurality of code nodes according to the association relationship between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0076] Optionally, the apparatus for determining dependency information of a database storage procedure further comprises a seventh determination module and a fourth processing module. The seventh determination module is configured to determine that the first code node has not been subjected to iteration processing when the iteration identifier does not exist in the first code node; and the fourth processing module is configured to perform iteration processing on the first code node, and start from the first code node to perform the downward recursion processing on at least one target code node in the plurality of code nodes according to the association relationship between the tree node to be processed and the target tree node after the iteration processing on the first code node is completed, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

[0077] Optionally, the apparatus for determining dependency information of a database storage procedure further comprises a third detection module and an eighth determination module. The third detection module is configured to detect whether the code node currently being subjected to the downward recursion processing is a second code node, wherein the second code node is a code node corresponding to a last tree node in the abstract syntax tree; and the eighth determination module is configured to determine that the code nodes corresponding to all tree nodes in the abstract syntax tree have completed the recursion processing when the code node currently being subjected to the downward recursion processing is the second code node.

[0078] Embodiment 3

[0079] According to another aspect of the embodiments of the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores a computer program. The computer program is configured to execute the above-mentioned method for determining dependency information of a database storage procedure when running.

[0080] Embodiment 4

[0081] According to another aspect of the embodiments of the present application, an electronic device is also provided, wherein Figure 5 is a schematic diagram of an optional electronic device according to the embodiments of the present application, as Figure 5 shown, the electronic device comprises one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement a program for running, wherein the program is arranged to perform the above-mentioned method for determining the dependency information of the database stored procedure when running.

[0082] As Figure 5 shown, the embodiments of the present application provide an electronic device, the device comprises a processor, a memory and a program stored in the memory and executable on the processor, and the processor implements the following steps when executing the program:

[0083] code analysis is performed on the source code of the target stored procedure to obtain a plurality of code nodes, wherein the target stored procedure is a set of SQL statements stored in the database for completing a target function, and each code node is used to represent a function or a variable in the source code of the target stored procedure; an abstract syntax tree is generated based on the plurality of code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; target metadata is constructed according to the abstract syntax tree, wherein the target metadata at least includes the association relationship between the plurality of code nodes and the position information of each code node in the source code of the target stored procedure; recursive processing is performed on the plurality of code nodes according to the target metadata to obtain the dependency information of the target stored procedure, wherein the dependency information at least includes first dependency information and second dependency information, the first dependency information is used to represent a stored procedure having a dependency relationship with the target stored procedure, and the second dependency information is used to represent data required to be referenced by the source code of the target stored procedure at runtime.

[0084] Optionally, the processor further implements the following steps when executing the program: the abstract syntax tree is parsed to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree; the association relationship between the plurality of code nodes is determined according to the connection relationship; the level of each tree node in the abstract syntax tree is determined as the line number of the code node corresponding to the tree node in the source code of the target stored procedure; the position information of each code node in the source code of the target stored procedure is determined according to the line number; and the target metadata is generated according to the position information and the association relationship between the plurality of code nodes.

[0085] Optionally, the processor further implements the following steps when executing the program: the calling mode corresponding to each code node is obtained; and the target metadata is generated according to the calling mode, the position information and the association relationship between the plurality of code nodes.

[0086] Optionally, the processor, when executing the program, further implements the following steps: selecting a tree node from the abstract syntax tree as a to-be-processed tree node according to the target metadata, and determining that a tree node associated with the to-be-processed tree node and located at a lower layer of the to-be-processed tree node is a target tree node; determining that a code node corresponding to the to-be-processed tree node is a starting code node; starting from the starting code node, performing downward recursive processing on at least one target code node in the plurality of code nodes according to the association between the to-be-processed tree node and the target tree node, to obtain first node dependency information and / or second node dependency information corresponding to each target code node, wherein the target code node is a code node corresponding to the target tree node, the first node dependency information is used to represent a stored procedure required to be called by the target code node at runtime, and the second node dependency information is used to represent data required to be referenced by the target code node at runtime; determining first dependency information of the target stored procedure according to the first node dependency information corresponding to each target code node; and determining second dependency information of the target stored procedure according to the second node dependency information corresponding to each target code node.

[0087] Optionally, the processor, when executing the program, further implements the following steps: detecting whether the code node currently being subjected to the downward recursive processing is a first code node, wherein the first code node is a code node that needs to call a stored procedure having a dependency relationship with the target stored procedure; when the code node currently being subjected to the downward recursive processing is the first code node, detecting whether an iteration identifier exists in the first code node, wherein the iteration identifier is used to represent that the first code node has completed iteration processing, and the iteration processing is used to perform program code parsing operations on the stored procedure having the dependency relationship with the target stored procedure through the first code node; and when the iteration identifier exists in the first code node, starting from the first code node, performing downward recursive processing on at least one target code node in the plurality of code nodes according to the association between the to-be-processed tree node and the target tree node, to obtain first node dependency information and / or second node dependency information corresponding to each target code node.

[0088] Optionally, the processor, when executing the program, further implements the following steps: when the iteration identifier does not exist in the first code node, determining that the first code node has not been subjected to iteration processing; performing iteration processing on the first code node, and after the iteration processing on the first code node is completed, starting from the first code node, performing downward recursive processing on at least one target code node in the plurality of code nodes according to the association between the to-be-processed tree node and the target tree node, to obtain first node dependency information and / or second node dependency information corresponding to each target code node.

[0089] Optionally, the processor further implements the following steps when executing the program: detecting whether the code node currently being processed in the downward recursion is the second code node, wherein the second code node is a code node corresponding to the last tree node in the abstract syntax tree; and determining that the code nodes corresponding to all the tree nodes in the abstract syntax tree have been processed in recursion when the code node currently being processed in the downward recursion is the second code node.

[0090] Embodiment 5

[0091] According to another aspect of the embodiments of the present application, there is also provided a computer program product comprising computer programs / instructions which, when executed by a processor, implement the above-mentioned method for determining dependency information of a database storage process.

[0092] The above-mentioned embodiment numbers of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.

[0093] In the above-mentioned embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0094] In several embodiments provided in the present application, it should be understood that the disclosed technical contents can be implemented by other ways. Among them, the above-mentioned device embodiments are only schematic, for example, the division of units can be a logical function division, and actual implementation can have another division way, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or modules shown or discussed can be indirect coupling or communication connection through some interfaces, units or modules, which can be electrical or other forms.

[0095] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e. they can be located in one place or distributed on multiple units. Part or all of the units can be selected to achieve the purpose of the present embodiment scheme according to actual needs.

[0096] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be realized in the form of hardware or in the form of software functional unit.

[0097] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a plurality of instructions to make a computer device (which can be a personal computer, a server or a network device, etc.) execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0098] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, and these improvements and refinements should be considered as the protection scope of the present application.

Claims

1. A method for determining the dependency information of a database stored procedure, characterized in that, include: The source code of the target stored procedure is parsed to obtain multiple code nodes. The target stored procedure is a set of SQL statements stored in the database to complete the target function. Each code node is used to represent a function or variable in the source code of the target stored procedure. An abstract syntax tree is generated based on multiple code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; The target metadata is constructed based on the abstract syntax tree, wherein the target metadata includes at least the association between multiple code nodes and the location information of each code node in the source code of the target stored procedure; Based on the target metadata, multiple code nodes are recursively processed to obtain the dependency information of the target stored procedure. The dependency information includes at least first dependency information and second dependency information. The first dependency information is used to characterize the stored procedures that have a dependency relationship with the target stored procedure, and the second dependency information is used to characterize the data that the source code of the target stored procedure needs to reference at runtime. The construction of target metadata based on the abstract syntax tree includes: The abstract syntax tree is parsed to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree. The association relationships between the multiple code nodes are determined based on the connection relationships; The level of each tree node in the abstract syntax tree is determined by the line number of the code node corresponding to that tree node in the source code of the target stored procedure; The location information of each code node in the source code of the target stored procedure is determined based on the line number it is in; The target metadata is generated based on the location information and the relationships between the multiple code nodes; Based on the target metadata, multiple code nodes are recursively processed to obtain the dependency information of the target stored procedure, including: Based on the target metadata, a tree node is randomly selected from the abstract syntax tree as the tree node to be processed, and it is determined that the tree node in the abstract syntax tree that has an association with the tree node to be processed and is located below the tree node to be processed is the target tree node; The code node corresponding to the tree node to be processed is determined as the starting code node; Starting from the initial code node, based on the association between the tree node to be processed and the target tree node, at least one target code node among the multiple code nodes is recursively processed downwards to obtain first node dependency information and / or second node dependency information corresponding to each target code node. The target code node is the code node corresponding to the target tree node. The first node dependency information is used to characterize the stored procedure that the target code node needs to call at runtime, and the second node dependency information is used to characterize the data that the target code node needs to reference at runtime. The first dependency information of the target stored procedure is determined based on the first node dependency information corresponding to each target code node; The second dependency information of the target stored procedure is determined based on the second node dependency information corresponding to each target code node.

2. The method according to claim 1, characterized in that, The target metadata is generated based on the location information and the relationships between the multiple code nodes, including: Obtain the invocation method corresponding to each of the code nodes; The target metadata is generated based on the invocation method, the location information, and the relationships between the multiple code nodes.

3. The method according to claim 1, characterized in that, Starting from the initial code node, based on the association between the tree node to be processed and the target tree node, at least one target code node among the multiple code nodes is recursively processed downwards to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node, including: Detect whether the code node currently undergoing downward recursion is the first code node, wherein the first code node is the code node that needs to call a stored procedure that has a dependency relationship with the target stored procedure; When the code node currently undergoing downward recursive processing is the first code node, it is detected whether there is an iteration identifier in the first code node. The iteration identifier is used to indicate that the first code node has completed the iteration processing. The iteration processing is used to perform program code parsing operations on the stored procedure that has a dependency relationship with the target stored procedure through the first code node. When the iteration identifier exists in the first code node, starting from the first code node, based on the association between the tree node to be processed and the target tree node, at least one of the target code nodes among the multiple code nodes is recursively processed downwards to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

4. The method according to claim 3, characterized in that, The method further includes: If no iteration identifier exists in the first code node, it is determined that the first code node has not undergone iteration processing; The first code node is iteratively processed, and after the iteration of the first code node is completed, starting from the first code node, at least one of the target code nodes among the multiple code nodes is recursively processed downward according to the association relationship between the tree node to be processed and the target tree node, so as to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node.

5. The method according to claim 3, characterized in that, The method further includes: Detect whether the code node currently undergoing downward recursive processing is the second code node, wherein the second code node is the code node corresponding to the last tree node in the abstract syntax tree; When the code node currently undergoing downward recursive processing is the second code node, it is determined that the code nodes corresponding to all tree nodes in the abstract syntax tree have completed recursive processing.

6. A device for determining the dependency information of a database stored procedure, characterized in that, include: The parsing module is used to parse the source code of the target stored procedure to obtain multiple code nodes. The target stored procedure is a set of SQL statements stored in the database to complete the target function. Each code node is used to represent a function or variable in the source code of the target stored procedure. A generation module is used to generate an abstract syntax tree based on multiple code nodes, wherein each code node corresponds to a tree node in the abstract syntax tree; A construction module is used to construct target metadata based on the abstract syntax tree, wherein the target metadata includes at least the association relationships between multiple code nodes and the location information of each code node in the source code of the target stored procedure; The processing module is used to recursively process multiple code nodes based on the target metadata to obtain the dependency information of the target stored procedure. The dependency information includes at least first dependency information and second dependency information. The first dependency information is used to characterize the stored procedures that have a dependency relationship with the target stored procedure, and the second dependency information is used to characterize the data that the source code of the target stored procedure needs to reference at runtime. The construction module further includes: a first parsing module for parsing the abstract syntax tree to obtain the level of each tree node in the abstract syntax tree and the connection relationship between all tree nodes in the abstract syntax tree; a first determining module for determining the association relationship between multiple code nodes based on the connection relationship; a second determining module for determining the level of each tree node in the abstract syntax tree as the line number of the corresponding code node in the source code of the target stored procedure; a third determining module for determining the position information of each code node in the source code of the target stored procedure based on the line number; and a first generating module for generating target metadata based on the position information and the association relationship between multiple code nodes. The processing module includes: a first processing module for randomly selecting a tree node from the abstract syntax tree as the tree node to be processed based on the target metadata, and determining that the tree node in the abstract syntax tree that has an association with the tree node to be processed and is located at the lower level of the tree node to be processed is the target tree node; a fourth determining module for determining the code node corresponding to the tree node to be processed as the starting code node; a second processing module for recursively processing at least one target code node among multiple code nodes, starting from the starting code node, according to the association between the tree node to be processed and the target tree node, to obtain the first node dependency information and / or the second node dependency information corresponding to each target code node, wherein the target code node is the code node corresponding to the target tree node, the first node dependency information is used to characterize the stored procedure that the target code node needs to call at runtime, and the second node dependency information is used to characterize the data that the target code node needs to reference at runtime; a fifth determining module for determining the first dependency information of the target stored procedure based on the first node dependency information corresponding to each target code node; and a sixth determining module for determining the second dependency information of the target stored procedure based on the second node dependency information corresponding to each target code node.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute, at runtime, a method for determining dependency information of the database stored procedure as described in any one of claims 1 to 5.

8. An electronic device, characterized in that, The electronic device includes one or more processors; A memory for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to perform operations on the programs, wherein the programs are configured to execute the method for determining dependency information of a database stored procedure as described in any one of claims 1 to 5.

9. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the method for determining the dependency information of the database stored procedure as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • A control flow graph construction method for object-oriented programming

    CN109408034A

  • Dependence configuration checking method and device, equipment and storage medium

    CN114185926A