Database storage process migration method, device, equipment and storage medium
By constructing and iteratively processing abstract syntax trees of stored procedures and generating migration files, the problem of low migration efficiency from PG database to GBase8a database was solved, automatic migration was realized, efficiency was improved and errors were reduced.
Patent Information
- Application Number
- CN202410741289.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-11
AI Technical Summary
When migrating the stored procedures in the PG database to the GBase8a database, the migration efficiency is too low and requires manual judgment and modification, resulting in a huge workload and the risk of miswriting and misreading.
By constructing an abstract syntax tree set of the stored procedure set to be migrated, recursive iterative processing and syntax transformation are performed to generate intermediate storage objects, and generate migrated stored procedure files based on preset dictionary mapping to achieve automated migration.
It improves the efficiency of stored procedure migration, reduces manual intervention, reduces the risk of miswriting and misreading, and enables rapid processing of repeated SQL logic.
Smart Images

Figure CN118312502B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and storage medium for migrating a database storage process. Background Art
[0002] A database is a warehouse that organizes, stores and manages data according to data structures. It is a collection of large amounts of data that is stored in a computer for a long time, organized, shareable and uniformly managed. It has a large storage space and can store millions, tens of millions or even hundreds of millions of data.
[0003] With the development of computer technology, databases have been widely used in all walks of life. For the storage of massive data, a single database is no longer competent. Therefore, more companies have begun to choose distributed databases. As a relational database product with a distributed architecture, GBase8a database plays an important role in industries such as finance and securities that require complex business analysis. Industries such as finance and securities are often accompanied by complex stored procedure logic. When performing database migration, it involves not only table structure migration and data migration, but also stored procedure migration. A stored procedure is a set of SQL statements to complete a specific function. After compilation, it is stored in the database. Users call and execute it by specifying the name of the stored procedure and giving parameters.
[0004] However, due to the many differences in the structured query languages used by different types of databases, when the stored procedures in the PG series database need to be migrated to the GBase8a database, manual migration is required, making the migration of stored procedures between different types of databases one of the most complicated and time-consuming tasks in the database migration business. Summary of the invention
[0005] The embodiments of the present invention provide a method, apparatus, device and storage medium for migrating a database stored procedure to solve the problem of low efficiency when migrating a stored procedure in a PG series database to a GBase8a database.
[0006] In a first aspect, an embodiment of the present invention provides a method for migrating a database stored procedure, comprising:
[0007] Constructing an abstract syntax tree set of the stored procedure set to be migrated, the abstract syntax tree set including abstract syntax trees of multiple target stored procedures, the target stored procedure being any stored procedure in the stored procedure set to be migrated;
[0008] Recursively iterate the abstract syntax trees of all target stored procedures, and generate intermediate storage objects based on the abstract syntax trees of all target stored procedures, the names of the target stored procedures, the name of the database to which the target stored procedures belong, and the values obtained by the recursive iterative process;
[0009] Iteratively process the intermediate storage object, generate the definition syntax corresponding to the intermediate storage process based on the preset dictionary mapping, call the corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process, and obtain the deep processing storage object;
[0010] The deep processing storage objects are spliced, sorted by line number, and end flag is added to obtain the files of the migrated storage process.
[0011] In a possible implementation, the stored procedure set to be migrated is exported from the PG system database to be migrated, and the intermediate storage object includes the abstract syntax tree of all target stored procedures, the abstract syntax tree of the target stored procedure includes the data item definition module datums and the logic processing module action, and the abstract syntax tree includes the key-value pair relationship of the target stored procedure;
[0012] Iterate the intermediate storage object, generate the definition syntax corresponding to the intermediate storage process based on the preset dictionary mapping, call the corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process, and obtain the deep processing storage object, including:
[0013] Iterate the intermediate storage object, and when the key of the element located is the data item definition module datums, call the data variable to rewrite the logical type; where the element is a node in the abstract syntax tree;
[0014] Extract the corresponding type of the keyword after rewriting the logic, and perform mapping search based on the preset dictionary;
[0015] Add a control group based on the layer corresponding to the abstract syntax tree of the target stored procedure found by mapping, and generate the GBase8a definition syntax corresponding to the intermediate stored procedure;
[0016] Based on the preset mapping relationship, the corresponding processing logic is called to perform syntax transformation on the GBase8a definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
[0017] In a possible implementation, the corresponding processing logic is called based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object, including:
[0018] Iterate the intermediate storage objects. When the key of the element located is the logic processing module action, call the business processing logic to rewrite the logic code.
[0019] The control structure of the element is determined based on the key attribute, and the corresponding GBase8a processing logic is called based on the mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
[0020] In a possible implementation, the logic processing module action is used to define the statement type or control structure of the stored procedure, including a syntax module and a return module. The syntax module includes SQL statements and various control structures, and the return module is used to return results or status values.
[0021] The data item definition module datums is used to centrally define data items at the beginning of a stored procedure.
[0022] In a possible implementation, the deep processing storage object is spliced, sorted by line number, and end flag is added to obtain the file of the migrated storage process, including:
[0023] Create a target list to store a single stored procedure;
[0024] According to the attribute value of the database in the deep processing storage object and the name attribute value in the deep processing storage object, the creation statement of the stored procedure in the GBase8a syntax is spliced and transformed, and the spliced and transformed stored procedure creation statement is added to the target list;
[0025] Extract the row data transformed based on GBase8a syntax from the deep processing storage object after splicing and transformation, sort and combine the row data based on the row number, append them to the target list according to the order of the row number, and append the end flag to the target list;
[0026] Output the target list to a file to obtain the file of the migrated stored procedure;
[0027] By executing the files of the stored procedures to be migrated, the stored procedure set to be migrated is stored in the GBase8a database.
[0028] In a possible implementation, before constructing the abstract syntax tree set of the stored procedure set to be migrated, the following steps are also included:
[0029] Export the stored procedure file to be migrated from the database to be migrated;
[0030] Performing iterative logic processing and line-by-line parsing on the stored procedure file to be migrated, dividing the stored procedure file to be migrated into multiple stored procedure objects; wherein the iterative logic processing includes extracting the name of the stored procedure and the name of the database to which the stored procedure belongs based on the regular matching process;
[0031] All target stored procedure objects are parsed to obtain abstract syntax trees of all target stored procedures.
[0032] In a possible implementation, the stored procedure file to be migrated is subjected to iterative logic processing and line-by-line parsing, and the stored procedure file to be migrated is divided into multiple stored procedure objects, including:
[0033] Define the start process flag variable and the end process flag variable. The start process flag variable is used to define the start of any stored procedure, and the end process flag variable is used to define the end of any stored procedure.
[0034] If the regular expression matches the process definition of the target stored procedure, the name of the target stored procedure and the name of the database to which it belongs are extracted based on the matching pattern, and the name of the target stored procedure and the name of the database to which it belongs are combined into a dictionary and added to the properties of the target stored procedure;
[0035] If the regular expression matches the start creation syntax of the target stored procedure, the start procedure flag variable is added to the start line of the target stored procedure, and the end procedure flag variable is added to the end line;
[0036] After the iteration of the stored procedure files to be migrated is completed, multiple stored procedure objects are obtained.
[0037] In a second aspect, an embodiment of the present invention provides a migration device for a database stored procedure, characterized in that it includes:
[0038] A construction module is used to construct an abstract syntax tree set of a stored procedure set to be migrated, wherein the abstract syntax tree set includes abstract syntax trees of multiple target stored procedures, and the target stored procedure is any stored procedure in the stored procedure set to be migrated;
[0039] A first processing module is used to perform recursive iterative processing on the abstract syntax trees of all target stored procedures, and generate an intermediate storage object based on the abstract syntax trees of all target stored procedures, the names of the target stored procedures, the name of the database to which the target stored procedures belong, and the values obtained by the recursive iterative process;
[0040] The second processing module is used to iteratively process the intermediate storage object, generate the definition syntax corresponding to the intermediate storage process based on the preset dictionary mapping, and call the corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object;
[0041] A generation module is used to perform splicing and transformation, line number sorting, and end flag addition processing on the deep processing storage objects to obtain the files of the migrated storage process.
[0042] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the processor implements the steps of the method described in the first aspect or any possible implementation manner of the first aspect.
[0043] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect or any possible implementation method of the first aspect are implemented.
[0044] The embodiment of the present invention provides a migration method, device, equipment and storage medium for a database stored procedure. First, an abstract syntax tree set of a stored procedure set to be migrated is constructed. Then, the abstract syntax trees of all target stored procedures are recursively iterated, and an intermediate storage object is generated based on the abstract syntax trees of all target stored procedures, the name of the target stored procedure, the name of the database to which the target stored procedure belongs, and the value obtained by the recursive iterative process. Next, the intermediate storage object is iteratively processed, and the definition syntax corresponding to the intermediate stored procedure is generated based on a preset dictionary mapping. The corresponding processing logic is called based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate stored procedure to obtain a deep processing storage object. Finally, the deep processing storage object is spliced, transformed, line number sorted, and end flag bit added to obtain a file of the migrated stored procedure. Since there are many similarities between many migration processes, the traditional migration method requires manual judgment and modification of each stored procedure, which leads to a huge workload. The present invention first obtains the abstract syntax tree set of the stored procedure set to be migrated, and then performs multiple automatic processing on the abstract syntax tree according to the internal connection between the abstract syntax tree and the stored procedure, and finally realizes the automatic migration process. The automatic migration can realize the rapid processing of such repeated SQL logic, thereby improving the efficiency of migration. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0046] Figure 1 It is a flowchart of the implementation of the database storage process migration method provided by the embodiment of the present invention;
[0047] Figure 2 It is a schematic diagram of the structure of a migration device for a database storage process provided by an embodiment of the present invention;
[0048] Figure 3 is a schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.
[0050] In order to make the purpose, technical solutions and advantages of the present invention more clear, specific embodiments will be described below in conjunction with the accompanying drawings.
[0051] To facilitate the understanding of the entire solution, we first introduce the PG series database and GBase8a database.
[0052] PG database refers to a series of database products or variants based on the PostgreSQL database system, such as the GreenPlum database. PostgreSQL is a powerful open source database system. PostgreSQL is a free software object-relational database management system (ORDBMS) with a very complete set of features. It is an object-relational database management system based on POSTGRES, version 4.2, developed by the Department of Computer Science at the University of California. PostgreSQL is a fully transactional security database that supports a variety of data types, such as JSON and JSONB types, array types, and custom types. The PostgreSQL database provides a wealth of interfaces that can easily expand its functionality, such as being able to implement your own index types under the GiST framework.
[0053] GBase8a Nanjing University General Database adopts the distributed federated architecture of MPP + Shared Nothing. Nodes communicate through TCP / IP network. Each node uses local disk to store data and supports symmetric deployment and asymmetric deployment.
[0054] GBase8a Nanjing University General Database product includes three core components and auxiliary function components. The core components include distributed management cluster GCWare, distributed scheduling cluster GCluster and distributed storage computing cluster GNode. The functions of all components are:
[0055] GCWare forms a distributed management cluster and provides consistency services for the cluster. It is mainly responsible for recording and saving information such as cluster structure, node status, node resource status, parallel control and distributed queue locks. When operating multiple copies of data, it records and queries the operable nodes and provides the data consistency status of each node.
[0056] GCluster forms a distributed scheduling cluster and is the unified entrance of the entire cluster. It is mainly responsible for accepting connections from the business end and returning query results to the business end. GCluster will accept SQL, perform parsing optimization, generate distributed execution plans, select operable nodes to perform distributed scheduling, and feed back the results to the business end.
[0057] GNodes form a distributed storage cluster and are the storage and computing units of cluster data. They are mainly responsible for storing cluster data, receiving and executing SQL sent by GCluster and returning the execution results to GCluster, and receiving data from the loading server for data loading.
[0058] GCMonit is used to monitor the running status of GCluster and GNode core components in real time. Once the process status of a service program is found to have changed, the corresponding service startup command will be executed according to the content in the configuration file to ensure the normal operation of the service component.
[0059] GCware_Monit is used to monitor the running status of GCware components in real time. Once the service process status changes, it will execute the corresponding service startup command according to the content in the configuration file to ensure the normal operation of the service component.
[0060] GCRecover&GCSyncServer is used for data synchronization between multiple copies. Once the data files between multiple copies are inconsistent, this process is called for synchronization to ensure the consistency of the data files of multiple copies.
[0061] Since there are many differences in the structured query languages used by different types of databases, when the stored procedures in the PG series database need to be migrated to the GBase8a database, they cannot be processed automatically in batches and need to be migrated manually.
[0062] Manual migration requires manual judgment and modification of each stored procedure, which results in a huge workload. In addition, each migration personnel needs to have a deep understanding of the syntax logic of all the stored procedures involved. This leads to the risk of multiple human errors such as miswriting or misreading.
[0063] In order to solve the problems of the prior art, the embodiments of the present invention provide a method, device, equipment and storage medium for migrating a database stored procedure. The following first introduces the method for migrating a database stored procedure provided by the embodiments of the present invention.
[0064] See also Figure 1 , which shows a flowchart of the implementation of the database storage process migration method provided by an embodiment of the present invention, and is described in detail as follows:
[0065] S110. Construct an abstract syntax tree set of the stored procedure set to be migrated.
[0066] The abstract syntax tree set includes abstract syntax trees of multiple target stored procedures, each target stored procedure corresponds to an abstract syntax tree. The target stored procedure is any stored procedure in the stored procedure set to be migrated.
[0067] An abstract syntax tree (AST) is a tree representation of the abstract syntax structure of source code written in a programming language. Each node of the abstract syntax tree is an element.
[0068] In some embodiments, the set of stored procedures to be migrated is exported from the PG system database to be migrated.
[0069] In this embodiment, the COPY tool can be used to export the stored procedure set and the database model definition language (Data Definition Language, DDL) of the PG system database to be migrated from the PG system database as a whole file. However, the file exported by the COPY tool contains not only the stored procedure set but also the DDL. Therefore, it is necessary to perform data cleaning on the file after exporting the file, that is, to clean the DDL and process the cleaned file into a file containing only the stored procedure set.
[0070] In some embodiments, since the cleaned stored procedure set includes multiple stored procedures, in order to facilitate parsing and generating an abstract syntax tree, the stored procedure set needs to be divided into multiple single-target stored procedures. The specific processing process is as follows:
[0071] First, the stored procedure file to be migrated is subjected to iterative logic processing and line-by-line parsing to divide the stored procedure file to be migrated into multiple stored procedure objects. The iterative logic processing includes extracting the name of the stored procedure and the name of the database to which the stored procedure belongs based on the regular matching process.
[0072] Then, all the objects of the target stored procedures are parsed to obtain the abstract syntax trees of all the target stored procedures.
[0073] In this embodiment, the stored procedure set file can be loaded and parsed line by line, and the data in the stored procedure set is processed into multiple stored procedure objects according to the segmentation rules of regular matching, and each stored procedure object can be regarded as a complete individual. The specific iterative logic processing and line-by-line parsing process is as follows:
[0074] S1110. Define a start process flag variable and an end process flag variable.
[0075] The start process flag variable is used to define the start of any stored procedure, and the end process flag variable is used to define the end of any stored procedure. The process flag variable is used to intercept the start to introduction of a stored procedure.
[0076] Exemplarily, the start process flag variable may be True, and the end process flag variable may be False.
[0077] S1120. If the regular expression matches the process definition of the target stored process, extract the name of the target stored process and the name of the database to which it belongs based on the matching pattern, combine the name of the target stored process and the name of the database to which it belongs into a dictionary, and add it to the properties of the target stored process.
[0078] The target stored procedure is any stored procedure in the stored procedure set to be migrated.
[0079] If the parsing here is missing, the name of the target stored procedure will be matched according to the regular expression and the variable will be assigned. The content of the variable after the assignment will be used as the name of the target stored procedure.
[0080] S1130. If the regular expression matches the start creation syntax of the target stored procedure, a start procedure flag variable is added to the start line of the target stored procedure, and an end procedure flag variable is added to the end line.
[0081] When the regular expression matches the start creation syntax of the target stored procedure, it means that a stored procedure content needs to be processed from this line, and the start procedure flag variable True is added. If the regular expression matches the end syntax of the stored procedure, it means that the stored procedure parsing should end here, and the end procedure flag variable False is added.
[0082] In this process, if the process flag variable of the line is True, the line needs to be preprocessed. If the process flag variable of the line is False, no preprocessing is required.
[0083] Syntax preprocessing refers to the definition of hash distribution columns, random distribution columns, variable assignment, and other processing on the row.
[0084] S1140: After the iteration of the files of the stored procedure to be migrated is completed, multiple stored procedure objects are obtained.
[0085] Based on the above iterative logic processing, N pre-processed stored procedure objects will be obtained after the iteration is completed.
[0086] In some embodiments, after all the target stored procedure objects are obtained, parsing processing may be performed to obtain an abstract syntax tree of the parsed stored procedure.
[0087] Specifically, the object of a single stored procedure is parsed to generate an abstract syntax tree of the stored procedure and stored in a specific dictionary for subsequent data output. The abstract syntax tree includes the key-value pair relationship of the target stored procedure. In addition, when the parsing fails, the stored procedure parsing failure is printed according to the name of the acquired stored procedure as a basis for error analysis.
[0088] S120, recursively iterate the abstract syntax trees of all target stored procedures, and generate an intermediate storage object based on the abstract syntax trees of all target stored procedures, the name of the target stored procedure, the name of the database to which the target stored procedure belongs, and the value obtained by the recursive iterative process.
[0089] In this embodiment, the elements in the abstract syntax tree of each target stored procedure are processed recursively, and the key-value pairs of the abstract syntax tree are checked. Each element is a node of an abstract syntax tree.
[0090] If the key key is equal to 'PLpgSQL_function', it means that a root node of the target stored procedure is found.
[0091] The abstract syntax trees of all target stored procedures, the names of all target stored procedures, the names of the databases to which all target stored procedures belong, and all return values obtained from the abstract syntax trees are passed as parameters to the method for generating intermediate storage objects for initialization processing to generate intermediate storage objects. For the following description, the intermediate storage object is named stmt.
[0092] The parameters are passed to the method that generates the intermediate storage object, which will initialize these parameters and generate an object that can be called by subsequent programs.
[0093] The generated intermediate storage object stmt contains the content of the abstract syntax tree set of the original stored procedure set and the corresponding syntax content newly added by GBase8a.
[0094] S130, iteratively process the intermediate storage object, generate the definition syntax corresponding to the intermediate storage process based on the preset dictionary mapping, call the corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process, and obtain a deep processing storage object.
[0095] When the database to be migrated is a PG database and the one to be migrated is a GBase8a database, the abstract syntax tree of the target stored procedure includes two important modules, namely the data item definition module datums and the logic processing module action.
[0096] The data item definition module datums is used to centrally define data items at the beginning of a stored procedure, including input parameters and variables defined in the statement block of the stored procedure. Input parameters are the parameters passed in when the stored procedure is called externally. Variables defined in the statement block of a stored procedure are such as the i variable in the "for i in result" loop.
[0097] The logic processing module action is used to define the statement type or control structure of the stored procedure, including the syntax module and the return module. The syntax module includes SQL statements and various control structures, including PLpgSQL_stmt_execsql, PLpgSQL_stmt_if, PLpgSQL_stmt_case (i.e. if-else, for loop, case statement), etc., which are used to combine and express business logic and data processing.
[0098] The return module is used to return results or status values.
[0099] In some embodiments, the data item definition module datums automatic rewriting process is as follows:
[0100] First, when iterating the intermediate storage object, when the key of the element is located as the data item definition module datums, the data variable rewrite logic type is called. Then, the corresponding type of the keyword after the rewrite logic is extracted, and the mapping search is performed based on the preset dictionary. Next, the control group is added based on the layer corresponding to the abstract syntax tree of the target storage process found by the mapping, and the GBase8a definition syntax corresponding to the intermediate storage process is generated.
[0101] Specifically, first, by iterating the intermediate storage object stmt, when the key of the element is located as 'datums', the data variable is called to rewrite the logical type. The types are numeric, floating point, string, byte, and date, which can also be increased or decreased according to the configuration file. Then, the corresponding value of typename is extracted, and the mapping search is performed based on the preset dictionary. Next, a control group is added to the layer corresponding to the abstract syntax tree of the target stored procedure, and the corresponding GBase8a definition syntax is generated after searching according to the preset dictionary mapping. Nodes at the same level are only added without modification, and the original tree structure is retained for comparison to facilitate error correction.
[0102] In some embodiments, the process of automatically rewriting the business logic of the logic processing module action is as follows:
[0103] First, when iterating the intermediate storage object, when the key of the element is located as the logic processing module action, the business processing logic is called to rewrite the logic code. The control structure of the element is determined based on the key attribute, and the corresponding GBase8a processing logic is called based on the mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
[0104] Specifically, first, by iterating the intermediate storage object stmt, when the key of the element is located as 'action', the business processing logic is called to rewrite the logic code. Then, the control structure of the element is determined according to the key attribute, and then the corresponding GBase8a processing logic is called according to the mapping relationship to perform syntax transformation.
[0105] The following uses a for loop as an example to illustrate that when the key attribute iterated and matched under the action element is PLpgSQL_stmt_for i, the corresponding for loop processing logic is called for transformation.
[0106] S140: perform splicing and transformation, line number sorting, and end flag addition processing on the deep processing storage object to obtain a file of the migrated storage process.
[0107] In some embodiments, the files of the migrated stored procedures may be obtained based on the following steps, specifically:
[0108] First, create a target list for storing a single stored procedure, which can be a.
[0109] Then, according to the attribute value of the database in the deep processing storage object and the name attribute value in the deep processing storage object, the creation statement of the stored procedure in the GBase8a syntax is spliced and transformed, and the spliced and transformed stored procedure creation statement is added to the target list a.
[0110] Next, extract the row data transformed based on GBase8a syntax in the deep processing storage object after splicing and transformation, sort and combine the row data based on the row number, append them to the target list a according to the order of the row number, and append the end flag to the target list a.
[0111] Finally, the target list a is output as a file to obtain the file of the migrated stored procedure.
[0112] After obtaining the file of the migrated stored procedure, the GBase8a database can create the stored procedure of the PG series database into the GBase8a database by executing the file.
[0113] The automated migration method provided by the present invention has stable and efficient stored procedure logic processing capabilities, and can provide fixed processing logic and modification solutions for various SQL logics. This means that it is no longer necessary for each migration personnel to have a deep understanding of all the stored procedure syntax logic involved. It is only necessary to add the processing logic encountered that is not added to the migration tool once.
[0114] The embodiment of the present invention provides a migration method, device, equipment and storage medium for a database stored procedure. First, an abstract syntax tree set of a stored procedure set to be migrated is constructed. Then, the abstract syntax trees of all target stored procedures are recursively iterated, and an intermediate storage object is generated based on the abstract syntax trees of all target stored procedures, the name of the target stored procedure, the name of the database to which the target stored procedure belongs, and the value obtained by the recursive iterative process. Next, the intermediate storage object is iteratively processed, and the definition syntax corresponding to the intermediate stored procedure is generated based on a preset dictionary mapping. The corresponding processing logic is called based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate stored procedure to obtain a deep processing storage object. Finally, the deep processing storage object is spliced, transformed, line number sorted, and end flag bit added to obtain a file of the migrated stored procedure. Since there are many similarities between many migration processes, the traditional migration method requires manual judgment and modification of each stored procedure, which leads to a huge workload. The present invention first obtains the abstract syntax tree set of the stored procedure set to be migrated, and then performs multiple automatic processing on the abstract syntax tree according to the internal connection between the abstract syntax tree and the stored procedure, and finally realizes the automatic migration process. The automatic migration can realize the rapid processing of such repeated SQL logic, thereby improving the efficiency of migration.
[0115] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0116] Based on the database storage process migration method provided in the above embodiment, the present invention also provides a specific implementation of a database storage process migration device applied to the database storage process migration method. Please refer to the following embodiment.
[0117] like Figure 2 As shown, a database storage process migration device 200 is provided, and the device includes:
[0118] A construction module 210 is used to construct an abstract syntax tree set of a stored procedure set to be migrated, wherein the abstract syntax tree set includes abstract syntax trees of multiple target stored procedures, and the target stored procedure is any stored procedure in the stored procedure set to be migrated;
[0119] The first processing module 220 is used to perform recursive iterative processing on the abstract syntax trees of all target stored procedures, and generate an intermediate storage object based on the abstract syntax trees of all target stored procedures, the names of the target stored procedures, the name of the database to which the target stored procedures belong, and the values obtained by the recursive iterative process;
[0120] The second processing module 230 is used to iteratively process the intermediate storage object, generate the definition syntax corresponding to the intermediate storage process based on the preset dictionary mapping, and call the corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object;
[0121] The generation module 240 is used to perform splicing and transformation, line number sorting and end flag addition processing on the deep processing storage object to obtain the file of the migrated storage process.
[0122] In a possible implementation, the stored procedure set to be migrated is exported from the PG system database to be migrated, and the intermediate storage object includes the abstract syntax tree of all target stored procedures, the abstract syntax tree of the target stored procedure includes the data item definition module datums and the logic processing module action, and the abstract syntax tree includes the key-value pair relationship of the target stored procedure;
[0123] The second processing module 230 is used to iteratively process the intermediate storage object, and when the key of the element located is the data item definition module datums, the data variable is called to rewrite the logical type; wherein the element is a node in the abstract syntax tree;
[0124] Extract the corresponding type of the keyword after rewriting the logic, and perform mapping search based on the preset dictionary;
[0125] Add a control group based on the layer corresponding to the abstract syntax tree of the target stored procedure found by mapping, and generate the GBase8a definition syntax corresponding to the intermediate stored procedure;
[0126] Based on the preset mapping relationship, the corresponding processing logic is called to perform syntax transformation on the GBase8a definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
[0127] In a possible implementation, the second processing module 230 is used to iteratively process the intermediate storage object, and when the key of the element located is the logic processing module action, the business processing logic is called to rewrite the logic code;
[0128] The control structure of the element is determined based on the key attribute, and the corresponding GBase8a processing logic is called based on the mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
[0129] In a possible implementation, the logic processing module action is used to define the statement type or control structure of the stored procedure, including a syntax module and a return module. The syntax module includes SQL statements and various control structures, and the return module is used to return results or status values.
[0130] The data item definition module datums is used to centrally define data items at the beginning of a stored procedure.
[0131] In one possible implementation, the generating module 240 is used to create a target list for storing a single stored procedure;
[0132] According to the attribute value of the database in the deep processing storage object and the name attribute value in the deep processing storage object, the creation statement of the stored procedure in the GBase8a syntax is spliced and transformed, and the spliced and transformed stored procedure creation statement is added to the target list;
[0133] Extract the row data transformed based on GBase8a syntax from the deep processing storage object after splicing and transformation, sort and combine the row data based on the row number, append them to the target list according to the order of the row number, and append the end flag to the target list;
[0134] Output the target list to a file to obtain the file of the migrated stored procedure;
[0135] By executing the files of the stored procedures to be migrated, the stored procedure set to be migrated is stored in the GBase8a database.
[0136] In a possible implementation, the construction module 210 is used to export the file of the stored procedure to be migrated from the database to be migrated;
[0137] Performing iterative logic processing and line-by-line parsing on the stored procedure file to be migrated, dividing the stored procedure file to be migrated into multiple stored procedure objects; wherein the iterative logic processing includes extracting the name of the stored procedure and the name of the database to which the stored procedure belongs based on the regular matching process;
[0138] All target stored procedure objects are parsed to obtain abstract syntax trees of all target stored procedures.
[0139] In a possible implementation, the construction module 210 is used to define a start process flag variable and an end process flag variable, the start process flag variable is used to define the start of any stored process, and the end process flag variable is used to define the end of any stored process;
[0140] If the regular expression matches the process definition of the target stored procedure, the name of the target stored procedure and the name of the database to which it belongs are extracted based on the matching pattern, and the name of the target stored procedure and the name of the database to which it belongs are combined into a dictionary and added to the properties of the target stored procedure;
[0141] If the regular expression matches the start creation syntax of the target stored procedure, the start procedure flag variable is added to the start line of the target stored procedure, and the end procedure flag variable is added to the end line;
[0142] After the iteration of the stored procedure files to be migrated is completed, multiple stored procedure objects are obtained.
[0143] Figure 3 Schematic diagram of an electronic device provided by an embodiment of the present invention. Figure 3 As shown, the electronic device 3 of this embodiment includes: a processor 30, a memory 31, and a computer program 32 stored in the memory 31 and executable on the processor 30. When the processor 30 executes the computer program 32, the steps in the above-mentioned migration method embodiments of each database storage process are implemented, for example Figure 1 Alternatively, when the processor 30 executes the computer program 32, the functions of each module in the above-mentioned device embodiments are realized, for example, Figure 2 The functions of modules 210 to 240 are shown.
[0144] Exemplarily, the computer program 32 may be divided into one or more modules, which are stored in the memory 31 and executed by the processor 30 to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program 32 in the electronic device 3. For example, the computer program 32 may be divided into Figure 2Modules 210 to 240 are shown.
[0145] The electronic device 3 may include, but is not limited to, a processor 30 and a memory 31. Those skilled in the art will appreciate that Figure 3 It is only an example of the electronic device 3 and does not constitute a limitation of the electronic device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0146] The processor 30 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0147] The memory 31 may be an internal storage unit of the electronic device 3, such as a hard disk or memory of the electronic device 3. The memory 31 may also be an external storage device of the electronic device 3, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 3. Further, the memory 31 may also include both an internal storage unit and an external storage device of the electronic device 3. The memory 31 is used to store the computer program and other programs and data required by the electronic device. The memory 31 may also be used to temporarily store data that has been output or is to be output.
[0148] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0149] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0150] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0151] In the embodiments provided by the present invention, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0152] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0153] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0154] If the integrated module / unit 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 present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the migration method embodiment of each database storage process can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium.
[0155] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A method for migrating a database stored procedure. It is characterized in that include: Constructing an abstract syntax tree set of a stored procedure set to be migrated, wherein the abstract syntax tree set includes abstract syntax trees of multiple target stored procedures, the abstract syntax trees include key-value pair relationships of target stored procedures, and the target stored procedure is any stored procedure in the stored procedure set to be migrated; wherein the stored procedure set to be migrated is exported from a PG system database to be migrated; Recursively iterate the abstract syntax trees of all the target stored procedures, and generate an intermediate storage object based on the abstract syntax trees of all the target stored procedures, the names of the target stored procedures, the name of the database to which the target stored procedures belong, and the values obtained by the recursive iterative process; wherein the intermediate storage object includes the abstract syntax trees of all the target stored procedures, the abstract syntax trees of the target stored procedures include data item definition modules datums and logic processing modules action, and the abstract syntax trees include key-value pair relationships of the target stored procedures; Iteratively process the intermediate storage object, and when the key of the element located is the data item definition module datums, call the data variable to rewrite the logical type; wherein the element is a node in the abstract syntax tree; Extract the corresponding type of the keyword after rewriting the logic, and perform mapping search based on the preset dictionary; Add a control group based on the layer corresponding to the abstract syntax tree of the target stored procedure found by mapping, and generate the GBase8a definition syntax corresponding to the intermediate stored procedure; Based on the preset mapping relationship, the corresponding processing logic is called to perform syntax transformation on the GBase8a definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object; The deep processing storage object is spliced, restructured, sorted by line number, and end flag is added to obtain a file of the migrated storage process.
2. The method for migrating a database stored procedure according to claim 1, It is characterized in that The calling of corresponding processing logic based on the preset mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object includes: Iterate the intermediate storage object, and when the key of the element located is the logic processing module action, call the business processing logic to rewrite the logic code; The control structure of the element is determined based on the key attribute, and the corresponding GBase8a processing logic is called based on the mapping relationship to perform syntax transformation on the definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object.
3. The method for migrating a database stored procedure as claimed in claim 2, It is characterized in that The logic processing module action is used to define the statement type or control structure of the stored procedure, including a grammar module and a return module. The grammar module includes SQL statements and various control structures, and the return module is used to return results or status values; The data item definition module datums is used to centrally define data items when a stored procedure starts.
4. The method for migrating a database stored procedure according to claim 1, It is characterized in that The step of performing splicing, transformation, line number sorting, and adding an end flag bit processing on the deep processing storage object to obtain a file of the migrated storage process includes: Create a target list to store a single stored procedure; According to the attribute value of the database in the deep processing storage object and the name attribute value in the deep processing storage object, the creation statement of the stored procedure in the GBase8a syntax is spliced and transformed, and the spliced and transformed stored procedure creation statement is added to the target list; Extracting row data transformed based on GBase8a syntax from the deep processing storage object after splicing and transformation, sorting and combining the row data based on the row numbers, appending them to the target list according to the order of the row numbers, and appending the end flag to the target list; Outputting the target list as a file to obtain a file of the migrated stored procedure; By executing the files of the migrated stored procedures, the stored procedure set to be migrated is stored in the GBase8a database.
5. The method for migrating a database stored procedure according to claim 1, It is characterized in that Before constructing the abstract syntax tree set of the stored procedure set to be migrated, the following step is also included: Export the stored procedure file to be migrated from the database to be migrated; Performing iterative logic processing and line-by-line parsing on the file of the stored procedure to be migrated, dividing the file of the stored procedure to be migrated into multiple stored procedure objects; wherein the iterative logic processing includes extracting the name of the stored procedure and the name of the database to which the stored procedure belongs based on the regular matching process; All the target stored procedure objects are parsed to obtain abstract syntax trees of all the target stored procedures.
6. The method for migrating a database stored procedure as claimed in claim 5, It is characterized in that The iterative logic processing and line-by-line parsing of the stored procedure file to be migrated to divide the stored procedure file to be migrated into multiple stored procedure objects includes: Define a start process flag variable and an end process flag variable, wherein the start process flag variable is used to define the start of any stored process, and the end process flag variable is used to define the end of any stored process; If the regular expression matches the process definition of the target stored process, the name of the target stored process and the name of the database to which it belongs are extracted based on the matching pattern, and the name of the target stored process and the name of the database to which it belongs are combined into a dictionary and added to the properties of the target stored process; If the regular expression matches the start creation syntax of the target stored procedure, then the start process flag variable is added to the start line of the target stored procedure, and the end process flag variable is added to the end line; After the iteration of the files of the stored procedure to be migrated is completed, multiple stored procedure objects are obtained.
7. A migration device for a database stored procedure, It is characterized in that include: A construction module is used to construct an abstract syntax tree set of a stored procedure set to be migrated, wherein the abstract syntax tree set includes abstract syntax trees of multiple target stored procedures, and the abstract syntax trees include key-value pair relationships of target stored procedures, and the target stored procedure is any stored procedure in the stored procedure set to be migrated; wherein the stored procedure set to be migrated is exported from a PG system database to be migrated; A first processing module is used to perform recursive iterative processing on the abstract syntax trees of all the target stored procedures, and generate an intermediate storage object based on the abstract syntax trees of all the target stored procedures, the names of the target stored procedures, the name of the database to which the target stored procedures belong, and the values obtained by the recursive iterative process; wherein the intermediate storage object includes the abstract syntax trees of all the target stored procedures, the abstract syntax trees of the target stored procedures include a data item definition module datums and a logic processing module action, and the abstract syntax tree includes a key-value pair relationship of the target stored procedure; The second processing module is used to iteratively process the intermediate storage object. When the key of the element located is the data item definition module datums, the data variable rewrite logic type is called; wherein the element is a node in the abstract syntax tree; the corresponding type of the keyword after the rewriting logic is extracted, and a mapping search is performed based on a preset dictionary; a control group is added based on the layer corresponding to the abstract syntax tree of the target storage process found by mapping, and the GBase8a definition syntax corresponding to the intermediate storage process is generated; based on the preset mapping relationship, the corresponding processing logic is called to perform syntax transformation on the GBase8a definition syntax corresponding to the intermediate storage process to obtain a deep processing storage object; A generation module is used to perform splicing and transformation, line number sorting and end flag addition processing on the deep processing storage object to obtain a file of the migrated storage process.
8. An electronic device, It is characterized in that The method comprises a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
