A distributed database generation method, device, terminal and storage medium
Automating the distributed database table structure and SQL optimization through the random forest model and deep learning algorithm solves the shortcomings of traditional distributed databases in distributed key selection and SQL optimization, improves system performance and resource utilization, and meets the needs of dynamic business changes. Concurrency requirements.
Patent Information
- Application Number
- CN202410874247.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-02
AI Technical Summary
Traditional distributed databases rely on static rules or manual experience in the selection of table distribution keys, and are difficult to adapt to business database changes and system load changes, resulting in difficulty or decline in performance improvement and waste of resources. Existing centralized database optimization methods cannot be directly applied and reduce the cost. Improves the performance and concurrency capabilities of distributed databases.
Use the random forest model and deep learning algorithm to automate the optimization of distributed database table structures and SQL statements. By obtaining target centralized database data, generate distributed database table structures, and optimize SQL statements based on deep learning to create distributed databases and reduce costs. Manually analyze costs to improve system performance and resource utilization.
Automate distribution key selection and SQL optimization of distributed databases, reduce manual errors, improve development efficiency and system performance, meet the concurrency requirements of dynamic business changes, reduce resource waste, and improve the overall performance and availability of distributed databases.
Smart Images

Figure CN118410032B
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic digital data processing, and in particular to a distributed database generation method, device, terminal and storage medium. Background Art
[0002] With the rapid development of cloud computing and distributed technologies, more and more businesses are developing and using distributed databases. Compared with traditional centralized databases, distributed databases enable businesses to better cope with data management needs in complex environments such as large data volumes, high concurrency, and multiple regions, thereby improving the overall performance, scalability, and availability of the system.
[0003] Data sharding is an important technology used in distributed databases. Reasonable selection of distribution keys for business tables plays a critical role in the performance and business concurrency of distributed databases. In traditional distributed database business transformation, the distribution key selection method for tables is mainly based on static rules or manual experience, which is difficult to adapt to the dynamic changes in data access modes and system loads in current business database changes and transformations, resulting in performance failure or even performance degradation or resource waste.
[0004] Therefore, the existing system optimization technologies and methods for centralized databases cannot be fully applied to distributed databases, resulting in a decrease in the performance efficiency of business systems, a large amount of computing resources in distributed systems being wasted, and the distributed concurrency cannot be improved. Summary of the invention
[0005] The present application provides a distributed database generation method, device, terminal and storage medium to solve the problem of low efficiency of manual distributed database transformation and operation and maintenance in the prior art.
[0006] In a first aspect, the present application provides a distributed database generation method, comprising:
[0007] Obtain database data of a target centralized database;
[0008] Inputting the database data of the target centralized database into a random forest model, and outputting a distributed database table structure; the random forest model is constructed based on a random forest algorithm;
[0009] Optimizing SQL statements based on database data of the target centralized database and a deep learning algorithm;
[0010] A distributed database corresponding to the target centralized database is created according to the distributed database table structure and the optimized SQL statement.
[0011] In a second aspect, the present application provides a distributed database generation device, including:
[0012] A data acquisition module, used to acquire database data of a target centralized database;
[0013] A conversion module, used to input the database data of the target centralized database into a random forest model, and output a distributed database table structure; the random forest model is constructed based on a random forest algorithm;
[0014] An optimization module, used for optimizing SQL statements based on database data of the target centralized database and a deep learning algorithm;
[0015] A creation module is used to create a distributed database corresponding to the target centralized database according to the distributed database table structure and the optimized SQL statement.
[0016] In a third aspect, the present application provides a terminal 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 steps of the method described in the first aspect or any possible implementation of the first aspect are implemented.
[0017] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps of the method described in the first aspect or any possible implementation of the first aspect.
[0018] The present application provides a distributed database generation method, device, terminal and storage medium, which obtains the database data of the target centralized database; inputs the database data of the target centralized database into a random forest model, and outputs a distributed database table structure; the random forest model is constructed based on the random forest algorithm; based on the database data of the target centralized database and a deep learning algorithm, SQL statements are optimized; according to the distributed database table structure and the optimized SQL statements, a distributed database corresponding to the target centralized database is created. The present application creates a distributed database corresponding to the target centralized database based on the distributed database table structure determined by the random forest model and the SQL statements optimized by the deep learning model, which can reduce the manual analysis and optimization costs in the traditional conversion process, and can improve system performance and resource utilization through the dual optimization of the table structure and the SQL statements. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0020] Figure 1 It is a flow chart of the implementation of the distributed database generation method provided in the embodiment of the present application;
[0021] Figure 2 It is a flowchart for implementing table sharding adjustment provided in an embodiment of the present application;
[0022] Figure 3 It is a structural diagram of a distributed database generation device provided in an embodiment of the present application;
[0023] Figure 4 It is a schematic diagram of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] 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 application. However, it should be clear to those skilled in the art that the present application may also 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 application.
[0025] In order to make the purpose, technical solutions and advantages of the present application clearer, specific embodiments will be described below in conjunction with the accompanying drawings.
[0026] In the process of converting a traditional centralized database to a distributed database, it is often necessary to manually analyze a large number of table structures and business models to determine the table distribution keys used by the business, which reduces the efficiency of business system performance and wastes a large amount of computing resources in the distributed system, and the distributed capacity concurrency cannot be improved. Therefore, the present application provides a distributed database generation method that uses intelligent technology to analyze and recommend data distribution keys in a distributed database system and automatically adjust and optimize them.
[0027] In particular, in response to the needs of business transformation from traditional centralized databases to distributed database application development scenarios, the distributed database using sharding architecture in the industry solves the problem that the distribution key selection method for distributed tables is mainly based on static rules or manual analysis experience. By adopting automatic distribution key optimization recommendations, the cost of manual optimization is reduced, and the performance and operation efficiency of distributed database systems are improved. The main technologies are: 1) By using artificial intelligence technology to automate the distribution keys of business tables in distributed databases; 2) Optimizing distributed database SQL through artificial intelligence technology; 3) Solving the problem of online transformation of distributed tables and distribution keys of distributed databases through stream operators. Its advantages include: 1) Providing automated transformation analysis for business tables using distributed database scenarios to reduce manual analysis errors; 2) Improving the experience and efficiency of developers using distributed databases for business development; 3) Solving the problem of automatic optimization of tables based on distribution key SQL during the operation of distributed databases to meet the ability of dynamic business development. The specific distributed database generation method is as follows:
[0028] Figure 1 The implementation flow chart of the distributed database generation method provided in the embodiment of the present application is detailed as follows:
[0029] In step 101, database data of a target centralized database is obtained.
[0030] In an embodiment of the present application, database data of a target centralized database is collected in real time or by discrete scripts, and the database data can be obtained from metadata dictionary tables and dynamic statistical view queries provided in various databases for subsequent operation calls. The database data may include table structure definitions in data dictionary tables, field types, field data distribution, table data volume statistics, table indexes and primary and foreign key information, index statistics, real-time SQL collection, historical SQL execution statistics, SQL execution plans, etc. The historical SQL execution statistics may include multiple centralized SQL tables, multiple centralized SQL statements, and the execution time of each centralized SQL statement.
[0031] In a possible implementation, step 101 may include:
[0032] Connect with the target centralized database based on JDBC to collect database data of the target centralized database in real time;
[0033] or,
[0034] Based on the written script, the database data of the target centralized database is collected offline.
[0035] Optionally, the database library of the target centralized database can be acquired by real-time acquisition and offline script acquisition.
[0036] During real-time collection, the real-time data collection end establishes a connection with the target centralized database based on JDBC. There is no need to install any agent process on the collection end. The collection time requires a normal business operation cycle, and the connecting user needs to have read permissions for the data dictionary and system views in the database.
[0037] When collecting offline scripts, offline data collection requires writing scripts to collect corresponding DB data. The data collection cycle such as session business SQL also needs to collect a normal business cycle so that the entire business access method can be traversed.
[0038] The database data obtained in the embodiment of the present application includes table structure data and SQL data, which provide data support for subsequent table structure generation and optimization, and SQL statement generation and optimization.
[0039] In step 102, the database data of the target centralized database is input into a random forest model, and a distributed database table structure is output; the random forest model is constructed based on a random forest algorithm.
[0040] In the embodiment of the present application, the training of the random forest model is to construct a random forest model on the collected source database data items in units of tables through the supervised learning random forest algorithm, and to establish a decision tree in units of table objects to analyze field attributes one by one. Among them, the field type mapping relationship of the basic table definition from the source database to the target database and the definition grammatical structure of the distributed table are pre-stored in the background library of this system. The database data of the target centralized database obtained in step 101 is input into the random forest model, and the dictionaries are automatically matched one by one to convert the distributed database table structure and the structural script statements in the table structure.
[0041] After obtaining the distributed database table structure, this application also needs to optimize the distributed database table structure. The specific optimization process is as follows:
[0042] Automatically map and match table structure field types based on the collected source data table (Data Definition Language, DDL), remove unnecessary definition syntax items in the structure definition, simplify the report structure definition, and use table indexes as independent analysis items in addition to primary keys. The optimization principles for table field types are as follows:
[0043] (1) The table field types are converted to simple data types. For example, according to the statistical analysis of the source data table, the date field in the source data table is defined as a string or the integer data is defined as a string. It can be directly converted to a date field or an integer field, and ensure that the migrated data can be converted normally.
[0044] (2) The data storage length is minimized according to the field statistics. If a character type field is defined as too long, it is converted to a column to store the actual longest field space + 1.
[0045] (3) Reduce the use of bytea, text, blob, and clob data types. For such large objects, according to statistical information, the column field length can be accommodated by varchar and will be converted to varchar type.
[0046] Based on the collected data field statistics, we comprehensively analyze the distribution of each field, preliminarily determine the appropriate distribution key field, and add the field to the distributed by hash distributed table definition after the table structure conversion. Among them, the preliminary optimal table distribution field selection principle is:
[0047] (1) The primary key is preferred as the shard key, and the field with relatively even distribution of statistical information fields is selected as the shard key;
[0048] (2) For tables without primary keys, foreign keys are preferred as distribution keys;
[0049] (3) For tables that have neither primary keys nor foreign keys, unique indexes are preferred as distribution keys;
[0050] (4) For tables where none of the above fields exist, the table field data obtained through statistical analysis is distributed relatively evenly and stored in the target DN.
[0051] Based on the above preset mapping rule process and preliminary analysis, a preliminary distributed table structure definition based on the target database is obtained.
[0052] Reconstruct the DDL statements based on the collected index statistics. The main reconstruction principles are:
[0053] (1) Index usage frequency. If the index usage frequency is not high, no conversion is performed.
[0054] (2) For primary keys or unique indexes, you need to ensure that the automatically selected shard key is included in the defined composite field; otherwise, the creation will fail.
[0055] (3) Recommend indexes based on the collected SQL execution plan information and add necessary indexes.
[0056] According to the above rules, the conversion and adjustment of the distributed table structure are completed, and the optimization of the distributed table structure is preliminarily completed.
[0057] In step 103, SQL statements are optimized based on the database data of the target centralized database and the deep learning algorithm.
[0058] In an embodiment of the present application, the distributed SQL is optimized using a deep learning algorithm and the database data of the target centralized database obtained in step 101 .
[0059] In the embodiment of the present application, the rules for distributed SQL optimization include: 1) avoiding full table scans; 2) avoiding using * to query any fields that are not used; 3) avoiding table queries and association conditions; 4) avoiding large transaction DML operations, such SQL statements are batch split; 5) avoiding using not in subquery operations; 6) trying to use shard fields for table association or condition fields; 7) trying to minimize redistribution and brodcast operator operations between DN nodes.
[0060] In a possible implementation, before step 103, the method may further include:
[0061] Create multiple distributed SQL tasks using database data from the target centralized database;
[0062] For each distributed SQL task, perform semantic analysis on the distributed SQL task, input the semantically analyzed distributed SQL task into a first deep learning model, and output a distributed SQL query statement corresponding to the distributed SQL task, where the first deep learning model is constructed based on a deep learning algorithm;
[0063] Use template interpolation algorithm to create distributed SQL templates;
[0064] Insert each distributed SQL query statement into the distributed SQL template respectively, obtain the distributed SQL statement corresponding to each distributed SQL query statement, and use the corresponding distributed SQL statement as the first distributed SQL statement;
[0065] Accordingly, step 101 may include:
[0066] Based on the deep learning algorithm, each first distributed SQL statement is optimized.
[0067] Among them, the template interpolation algorithm is a method for generating SQL. The characteristic of this method is to first create a general SQL template, leave the part to be generated blank, and then fill in the blank position to form a complete SQL statement.
[0068] Optionally, before optimizing the distributed SQL, it is also necessary to generate the distributed SQL according to the database data of the acquired target centralized database. The specific generation process includes:
[0069] Create multiple distributed SQL tasks using the database data of the acquired target centralized database, each SQL task is intended to generate a corresponding distributed SQL query statement from the acquired database data. For any distributed SQL task, map the distributed SQL task as input to an executable program to obtain the distributed SQL task after semantic parsing, wherein the executable program may be in the form of a logical expression, an SQL query statement, a Python program, a JAVA program, etc. Input the semantically parsed distributed SQL task into a first deep learning model constructed based on a deep learning algorithm, and output the distributed SQL query statement corresponding to the distributed SQL task. Create a general distributed SQL template using a template interpolation algorithm, insert each distributed SQL query statement into the general distributed SQL template, obtain the distributed SQL statement corresponding to each distributed SQL query statement, and define each corresponding distributed SQL statement as a first distributed SQL statement.
[0070] Among them, the calculation process inside the first deep learning model is as follows:
[0071] The semantically parsed distributed SQL task is input into the first deep learning model, and the encoder in the first deep learning model is used to encode it into the model's internal expression. Then the decoder of the first deep learning model is used to decode the model's internal expression into the target expression, such as SQL query statements, Python programs, etc.
[0072] It can also be parsed using a given syntax, either into a corresponding abstract syntax tree or into a custom SQL syntax. The abstract syntax tree is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in a tree-like structure, with each node on the tree representing a structure in the source code. The syntax of the SQL language is usually defined by the abstract syntax description language (ASDL).
[0073] Accordingly, the converted distributed SQL statements are rewritten and optimized.
[0074] In a possible implementation, optimizing each first distributed SQL statement based on a deep learning algorithm may include:
[0075] For any first distributed SQL statement, execute the following steps:
[0076] Parsing the first distributed SQL statement using a syntax structure tree and an SQL parser to obtain characteristic keywords corresponding to the first distributed SQL statement, wherein the characteristic keywords include table field data types, data distribution, SQL query frequency, SQL execution time, data access mode, table join fields, and usage of indexes;
[0077] Inputting feature keywords into a second deep learning model and outputting a distributed table, wherein the second deep learning model is constructed based on a deep learning algorithm;
[0078] Based on the distributed table, perform N query rewriting on the first distributed SQL statement according to the SQL rule to obtain N second distributed SQL statements;
[0079] In a distributed database environment, simulate and execute N second distributed SQL statements to obtain a reconstructed distributed SQL table;
[0080] The first distributed SQL statement is optimized based on the reconstructed distributed SQL table.
[0081] Optionally, for any first distributed SQL statement, the first distributed SQL statement and the object are parsed through the syntax structure tree and the SQL parser to obtain corresponding feature keywords, which include but are not limited to query association table field data type, data distribution, SQL query frequency, SQL execution time, data access mode, table join fields, index usage, etc. Among them, the fields include table sharding fields, where, join, group, order by and having.
[0082] Then, the feature keywords are input into the second deep learning model built based on the deep learning algorithm, the distributed table sharding key is selected, and the distributed table is output. At the same time, based on the distributed table, the first distributed SQL statement is queried and rewritten N times according to the established SQL rules to obtain N rewritten second distributed SQL statements. Each second distributed SQL statement can be used as a neural network intelligent body.
[0083] For the data migration transformation environment, simulate the execution of N second distributed SQL statements. For the already distributed database environment, it can be performed in the same environment to obtain the reconstructed distributed SQL table, record the execution results and execution plan of the reconstructed distributed SQL table, and optimize the corresponding first distributed SQL statement based on the reconstructed distributed SQL table.
[0084] In a possible implementation, the database data of the target centralized database includes a plurality of centralized SQL tables; and optimizing the first distributed SQL statement based on the reconstructed distributed SQL table may include:
[0085] Calculate the hash value of the reconstructed distributed SQL table and the hash value of the initial SQL table respectively, where the initial SQL table is a centralized SQL table in the target centralized database corresponding to the first distributed SQL statement;
[0086] Determine whether the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table;
[0087] If the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table, the hash value is calculated for each distributed SQL statement in the reconstructed distributed SQL table, and the distributed SQL statement with the smallest hash value is selected from the hash values of all distributed SQL statements as the target SQL statement;
[0088] If the hash value of the reconstructed distributed SQL table is different from the hash value of the initial SQL table, all distributed SQL statements in the reconstructed distributed SQL table are executed respectively, and the distributed SQL statement with the shortest execution time is retained, and the distributed SQL statement with the shortest execution time is used as the target SQL statement;
[0089] The target SQL statement is used as the optimized first distributed SQL statement.
[0090] Optionally, after obtaining the reconstructed distributed SQL table, the hash value of the reconstructed distributed SQL table and the hash value of the initial SQL table are calculated respectively, wherein the initial SQL table is a centralized SQL table in the target centralized database corresponding to the corresponding first distributed SQL statement. It is determined whether the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table. If they are the same, the hash value is calculated for each distributed SQL statement in the reconstructed distributed SQL table, and the distributed SQL statement with the smallest hash value among all distributed SQL statements is retained as the target SQL statement; if they are not the same, a batch test is performed, and all distributed SQL statements in the reconstructed distributed SQL table are executed respectively, and the distributed SQL statement with the shortest execution time and the corresponding execution plan are retained, and the distributed SQL statement with the shortest execution time is used as the target SQL statement. Finally, the target SQL statement is used as the first distributed SQL statement after optimization.
[0091] In a possible implementation, the database data of the target centralized database includes the execution time of each centralized SQL statement; based on taking the target SQL statement as the optimized first distributed SQL statement, it may include:
[0092] Determine whether the execution time of the target SQL statement is not greater than the initial execution time, and whether the target SQL statement is reconstructible, the initial execution time being the execution time of a centralized SQL statement in the target centralized database corresponding to the execution time of the first distributed SQL statement;
[0093] If the execution time of the target SQL statement is greater than the initial execution time, and / or the target SQL statement cannot be reconstructed, return to parse the first distributed SQL statement using the syntax structure tree and the SQL parser, obtain the characteristic keyword step corresponding to the first distributed SQL statement and re-execute;
[0094] If the execution time of the target SQL statement is not greater than the initial execution time and the target SQL statement can be reconstructed, the target SQL statement is used as the optimized first distributed SQL statement.
[0095] Optionally, determine whether the execution time of the target SQL statement is not greater than the initial execution time, and whether the target SQL statement can be reconstructed. If the execution time is greater than the initial execution time, and / or cannot be reconstructed, re-parse the first distributed SQL statement and re-acquire feature keywords; if the execution time is not greater than the initial execution time, and the target SQL statement can be reconstructed, use the target SQL statement as the optimized first distributed SQL statement.
[0096] The initial execution time is the execution time of the centralized SQL statement in the target centralized database corresponding to the execution time of the first distributed SQL statement.
[0097] In a possible implementation, before optimizing the first distributed SQL statement based on the reconstructed distributed SQL table, the method may further include:
[0098] Filter out abnormal distributed SQL statements in the reconstructed distributed SQL table, where the abnormal distributed SQL statements are distributed SQL statements whose execution results in the reconstructed distributed SQL table are inconsistent with the initial execution results, where the initial execution results are the execution results of the centralized SQL statements in the target centralized database corresponding to the first distributed SQL statement;
[0099] Accordingly, optimizing the first distributed SQL statement based on the reconstructed distributed SQL table may include:
[0100] The first distributed SQL statement is optimized based on the filtered and reconstructed SQL table.
[0101] Optionally, after obtaining the reconstructed distributed SQL table, it is necessary to filter out abnormal distributed SQL statements in the reconstructed distributed SQL table, wherein the abnormal distributed SQL statements are distributed SQL statements whose execution results in the reconstructed distributed SQL table are inconsistent with the initial execution results, and the initial execution result is the execution result of the centralized statement in the target centralized database corresponding to the first distributed SQL statement.
[0102] In step 104, a distributed database corresponding to the target centralized database is created according to the distributed database table structure and the optimized SQL statement.
[0103] In the embodiment of the present application, a distributed database corresponding to the target centralized database is created according to the distributed database table structure obtained in step 102 and the distributed SQL statement optimized in step 103.
[0104] Based on the summary of the intelligent analysis results, the database administrator needs to click to confirm the real-time operation of automatically optimizing and adjusting the sharding key of the distributed table to reduce the controllability of the business impact time. Specifically, in order to automatically optimize and adjust the distribution key and index information of the distributed table for the system, this application will not automatically update the target library directly when monitoring and analyzing the unreasonable distribution keys and indexes of the table. The administrator needs to perform selective confirmation and implementation to ensure the stability of the business database and the controllability of the changes. Continuously monitor the operating status of the distributed database system, and adjust the distribution key selection strategy according to real-time data to adapt to changes in the load and access patterns of the distributed database system.
[0105] For specific table sharding adjustment implementation process, refer to Figure 2 As shown:
[0106] The user confirms whether to execute the recommended distributed table creation or transformation. The distributed SQL optimization suggestion transformation requires the business level to confirm whether to modify the program, which cannot be implemented in the distributed database system. For the distributed database system that has been running online transactions, there is already a table sharding adjustment process. In order to ensure data consistency, the adjustment of the distributed table will add a read-only lock, making the distributed table unable to be written. Therefore, the distributed database system will determine whether to automatically transform the table structure based on the user's choice: If so, it will determine whether it is a new distributed library environment. If it is a new distributed library environment, adjust the table sharding, directly create a distributed table in the target library, and end directly after completion; if it is already online, this distributed database system will create a distributed table structure with the same name as the original distributed table with the suffix _swap in the target distributed library, and then lock the original distributed table as read-only. The table data will be redistributed in the DN node through the stream execution plan according to the new distribution field, and the corresponding data will be inserted into the new table with _swap. After the data is redistributed, the original distributed table is renamed to a table with _bak, and the new distributed table is changed to the original distributed table name. The table lock is released, and the business can write to the distributed table normally. If not, just end it.
[0107] In the embodiment of the present application, the distributed database system is required to support data exchange between DN nodes. For distributed databases that do not support data flow between DN nodes, automatic processing cannot be achieved, and data migration operations need to be implemented manually. Specifically, referring to the above process, for distributed tables with small data volumes, data migration can be performed by insert a_1 select*from a, and then rename back to the original distributed table. For large data volumes, data migration can be achieved by direct import and export.
[0108] The present application provides a distributed database generation method, which obtains database data of a target centralized database; inputs the database data of the target centralized database into a random forest model, and outputs a distributed database table structure; the random forest model is constructed based on a random forest algorithm; based on the database data of the target centralized database and a deep learning algorithm, SQL statements are optimized; and according to the distributed database table structure and the optimized SQL statements, a distributed database corresponding to the target centralized database is created. The present application creates a distributed database corresponding to the target centralized database based on the distributed database table structure determined by the random forest model and the SQL statements optimized by the deep learning model, which can reduce the manual analysis and optimization costs in the traditional conversion process, and can improve system performance and resource utilization through the dual optimization of the table structure and the SQL statements.
[0109] It should be understood that the size of the serial numbers of the steps in the above embodiments does not 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 embodiments of the present application.
[0110] The following is an embodiment of the device of the present application. For details not described in detail, please refer to the corresponding method embodiment described above.
[0111] Figure 3 The following is a schematic diagram of the structure of a distributed database generation device provided in an embodiment of the present application. For ease of explanation, only the parts related to the embodiment of the present application are shown, which are described in detail as follows:
[0112] like Figure 3 As shown, the distributed database generating device 3 includes: .
[0113] A data acquisition module 31 is used to acquire database data of a target centralized database;
[0114] The conversion module 32 is used to input the database data of the target centralized database into the random forest model and output the distributed database table structure; the random forest model is constructed based on the random forest algorithm;
[0115] An optimization module 33, used for optimizing SQL statements based on database data of a target centralized database and a deep learning algorithm;
[0116] The creation module 34 is used to create a distributed database corresponding to the target centralized database according to the distributed database table structure and the optimized SQL statement.
[0117] The present application provides a distributed database generation device, which obtains database data of a target centralized database; inputs the database data of the target centralized database into a random forest model, and outputs a distributed database table structure; the random forest model is constructed based on a random forest algorithm; based on the database data of the target centralized database and a deep learning algorithm, SQL statements are optimized; and according to the distributed database table structure and the optimized SQL statements, a distributed database corresponding to the target centralized database is created. The present application creates a distributed database corresponding to the target centralized database based on the distributed database table structure determined by the random forest model and the SQL statements optimized by the deep learning model, which can reduce the manual analysis and optimization costs in the traditional conversion process, and can improve system performance and resource utilization through the dual optimization of the table structure and the SQL statements.
[0118] In a possible implementation, the device may further include a statement generation module, the statement generation module being configured to:
[0119] Create multiple distributed SQL tasks using database data from the target centralized database;
[0120] For each distributed SQL task, perform semantic analysis on the distributed SQL task, input the semantically analyzed distributed SQL task into a first deep learning model, and output a distributed SQL query statement corresponding to the distributed SQL task, where the first deep learning model is constructed based on a deep learning algorithm;
[0121] Use template interpolation algorithm to create distributed SQL templates;
[0122] Insert each distributed SQL query statement into the distributed SQL template respectively, obtain the distributed SQL statement corresponding to each distributed SQL query statement, and use the corresponding distributed SQL statement as the first distributed SQL statement;
[0123] Accordingly, the optimization module can be used to:
[0124] Based on the deep learning algorithm, each first distributed SQL statement is optimized.
[0125] In one possible implementation, the optimization module may be used to:
[0126] For any first distributed SQL statement, execute the following steps:
[0127] Parsing the first distributed SQL statement using a syntax structure tree and an SQL parser to obtain characteristic keywords corresponding to the first distributed SQL statement, wherein the characteristic keywords include table field data types, data distribution, SQL query frequency, SQL execution time, data access mode, table join fields, and usage of indexes;
[0128] Inputting feature keywords into a second deep learning model and outputting a distributed table, wherein the second deep learning model is constructed based on a deep learning algorithm;
[0129] Based on the distributed table, perform N query rewriting on the first distributed SQL statement according to the SQL rule to obtain N second distributed SQL statements;
[0130] In a distributed database environment, simulate and execute N second distributed SQL statements to obtain a reconstructed distributed SQL table;
[0131] The first distributed SQL statement is optimized based on the reconstructed distributed SQL table.
[0132] In a possible implementation, the database data of the target centralized database may include multiple centralized SQL tables; the optimization module may also be used to:
[0133] Calculate the hash value of the reconstructed distributed SQL table and the hash value of the initial SQL table respectively, where the initial SQL table is a centralized SQL table in the target centralized database corresponding to the first distributed SQL statement;
[0134] Determine whether the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table;
[0135] If the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table, the hash value is calculated for each distributed SQL statement in the reconstructed distributed SQL table, and the distributed SQL statement with the smallest hash value is selected from the hash values of all distributed SQL statements as the target SQL statement;
[0136] If the hash value of the reconstructed distributed SQL table is different from the hash value of the initial SQL table, all distributed SQL statements in the reconstructed distributed SQL table are executed respectively, and the distributed SQL statement with the shortest execution time is retained, and the distributed SQL statement with the shortest execution time is used as the target SQL statement;
[0137] The target SQL statement is used as the optimized first distributed SQL statement.
[0138] In a possible implementation, the database data of the target centralized database may include the execution time of each centralized SQL statement; the optimization module may also be used to:
[0139] Determine whether the execution time of the target SQL statement is not greater than the initial execution time, and whether the target SQL statement is reconstructible, the initial execution time being the execution time of a centralized SQL statement in the target centralized database corresponding to the execution time of the first distributed SQL statement;
[0140] If the execution time of the target SQL statement is greater than the initial execution time, and / or the target SQL statement cannot be reconstructed, return to parse the first distributed SQL statement using the syntax structure tree and the SQL parser, obtain the characteristic keyword step corresponding to the first distributed SQL statement and re-execute;
[0141] If the execution time of the target SQL statement is not greater than the initial execution time and the target SQL statement can be reconstructed, the target SQL statement is used as the optimized first distributed SQL statement.
[0142] In a possible implementation, the optimization module may also be used to:
[0143] Filter out abnormal distributed SQL statements in the reconstructed distributed SQL table, where the abnormal distributed SQL statements are distributed SQL statements whose execution results in the reconstructed distributed SQL table are inconsistent with the initial execution results, where the initial execution results are the execution results of the centralized SQL statements in the target centralized database corresponding to the first distributed SQL statement;
[0144] Accordingly, the optimization module can also be used to:
[0145] The first distributed SQL statement is optimized based on the filtered and reconstructed SQL table.
[0146] In a possible implementation, the data acquisition module may:
[0147] Connect with the target centralized database based on JDBC to collect database data of the target centralized database in real time;
[0148] or,
[0149] Based on the written script, the database data of the target centralized database is collected offline.
[0150] Figure 4 is a schematic diagram of a terminal provided in an embodiment of the present application. Figure 4 As shown, the terminal 4 of this embodiment includes: a processor 40, a memory 41, and a computer program 42 stored in the memory 41 and executable on the processor 40. When the processor 40 executes the computer program 42, the steps in the above-mentioned distributed database generation method embodiments are implemented, for example Figure 1 Alternatively, when the processor 40 executes the computer program 42, the functions of each module / unit in the above-mentioned device embodiments are realized, for example Figure 3 The functions of each module are shown.
[0151] Exemplarily, the computer program 42 may be divided into one or more modules / units, which are stored in the memory 41 and executed by the processor 40 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 42 in the terminal 4. For example, the computer program 42 may be divided into Figure 3 The modules shown.
[0152] The terminal 4 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal 4 may include, but is not limited to, a processor 40 and a memory 41. Those skilled in the art will appreciate that Figure 4It is only an example of terminal 4 and does not constitute a limitation on terminal 4. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal may also include input and output devices, network access devices, buses, etc.
[0153] The processor 40 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.
[0154] The memory 41 may be an internal storage unit of the terminal 4, such as a hard disk or memory of the terminal 4. The memory 41 may also be an external storage device of the terminal 4, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal 4. Further, the memory 41 may also include both an internal storage unit and an external storage device of the terminal 4. The memory 41 is used to store the computer program and other programs and data required by the terminal. The memory 41 may also be used to temporarily store data that has been output or is to be output.
[0155] 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.
[0156] 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.
[0157] Those of ordinary skill 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 this application.
[0158] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminals and methods can be implemented in other ways. For example, the device / terminal 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.
[0159] 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.
[0160] In addition, each functional unit in each embodiment of the present application 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.
[0161] 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 application 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 above-mentioned distributed database generation method embodiments 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 capable of carrying 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. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0162] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person 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 application, and should all be included in the protection scope of the present application.
Claims
1. A distributed database generation method, It is characterized in that include: Obtain database data of a target centralized database; Inputting the database data of the target centralized database into a random forest model and outputting a distributed database table structure; The random forest model is constructed based on the random forest algorithm; Optimizing SQL statements based on database data of the target centralized database and a deep learning algorithm; Creating a distributed database corresponding to the target centralized database according to the distributed database table structure and the optimized SQL statement; The step of inputting the database data of the target centralized database into a random forest model and outputting a distributed database table structure includes: The random forest model is constructed on the database data in units of tables by using the random forest algorithm, and a decision tree is established in units of table objects to analyze field attributes one by one, wherein the field type mapping relationship of the basic table definition from the source database to the target database and the definition grammatical structure of the distributed table are pre-stored in the target centralized database; Inputting the database data of the target centralized database into the random forest model, automatically matching dictionaries one by one, and converting to obtain a distributed database table structure and structural script statements in the table structure; Wherein, before performing SQL statement optimization based on the database data of the target centralized database and the deep learning algorithm, the method further includes: Creating a plurality of distributed SQL tasks using database data of the target centralized database; For each distributed SQL task, perform semantic parsing on the distributed SQL task, input the semantically parsed distributed SQL task into a first deep learning model, and output a distributed SQL query statement corresponding to the distributed SQL task, wherein the first deep learning model is constructed based on a deep learning algorithm; Use template interpolation algorithm to create distributed SQL templates; Inserting each distributed SQL query statement into the distributed SQL template respectively, obtaining a distributed SQL statement corresponding to each distributed SQL query statement, and using each corresponding distributed SQL statement as a first distributed SQL statement; Accordingly, the SQL statement optimization based on the database data of the target centralized database and the deep learning algorithm includes: Based on deep learning algorithms, optimize each first distributed SQL statement; The step of optimizing each first distributed SQL statement based on a deep learning algorithm includes: For any first distributed SQL statement, execute the following steps: Parsing the first distributed SQL statement using a syntax structure tree and an SQL parser to obtain characteristic keywords corresponding to the first distributed SQL statement, wherein the characteristic keywords include table field data types, data distribution, SQL query frequency, SQL execution time, data access mode, table join fields, and usage of indexes; Inputting the feature keyword into a second deep learning model and outputting a distributed table, wherein the second deep learning model is constructed based on a deep learning algorithm; Based on the distributed table, perform N query rewriting on the first distributed SQL statement according to the SQL rule to obtain N second distributed SQL statements; In a distributed database environment, simulate and execute N second distributed SQL statements to obtain a reconstructed distributed SQL table; Optimizing the first distributed SQL statement based on the reconstructed distributed SQL table; The database data of the target centralized database includes a plurality of centralized SQL tables; and the step of optimizing the first distributed SQL statement based on the reconstructed distributed SQL table includes: Calculating a hash value of the reconstructed distributed SQL table and a hash value of an initial SQL table respectively, wherein the initial SQL table is a centralized SQL table in the target centralized database corresponding to the first distributed SQL statement; Determine whether the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table; If the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table, then calculating the hash value for each distributed SQL statement in the reconstructed distributed SQL table, and selecting the distributed SQL statement with the smallest hash value from the hash values of all distributed SQL statements as the target SQL statement; If the hash value of the reconstructed distributed SQL table is different from the hash value of the initial SQL table, all distributed SQL statements in the reconstructed distributed SQL table are executed respectively, the distributed SQL statement with the shortest execution time is retained, and the distributed SQL statement with the shortest execution time is used as the target SQL statement; Using the target SQL statement as the optimized first distributed SQL statement; The database data of the target centralized database includes the execution time of each centralized SQL statement; the method based on taking the target SQL statement as the optimized first distributed SQL statement includes: Determine whether the execution time of the target SQL statement is not greater than the initial execution time, and whether the target SQL statement is reconstructible, wherein the initial execution time is the execution time of a centralized SQL statement in the target centralized database corresponding to the execution time of the first distributed SQL statement; If the execution time of the target SQL statement is greater than the initial execution time, and / or the target SQL statement cannot be reconstructed, returning to the step of parsing the first distributed SQL statement using the syntax structure tree and the SQL parser to obtain the characteristic keyword corresponding to the first distributed SQL statement and re-executing the step; If the execution time of the target SQL statement is not greater than the initial execution time and the target SQL statement can be reconstructed, the target SQL statement is used as the optimized first distributed SQL statement.
2. The distributed database generation method according to claim 1, It is characterized in that Before optimizing the first distributed SQL statement based on the reconstructed distributed SQL table, the method further includes: Filter out abnormal distributed SQL statements in the reconstructed distributed SQL table, wherein the abnormal distributed SQL statements are distributed SQL statements in the reconstructed distributed SQL table whose execution results are inconsistent with initial execution results, and the initial execution results are execution results of centralized SQL statements in the target centralized database corresponding to the first distributed SQL statement; Accordingly, optimizing the first distributed SQL statement based on the reconstructed distributed SQL table includes: The first distributed SQL statement is optimized based on the filtered and reconstructed SQL table.
3. The distributed database generation method according to claim 1, It is characterized in that The step of obtaining database data of a target centralized database includes: Connecting to the target centralized database based on JDBC to collect database data of the target centralized database in real time; or, Based on the written script, the database data of the target centralized database is collected offline.
4. A distributed database generation device, It is characterized in that include: A data acquisition module, used to acquire database data of a target centralized database; A conversion module, used to input the database data of the target centralized database into a random forest model, and output a distributed database table structure; the random forest model is constructed based on a random forest algorithm; An optimization module, used for optimizing SQL statements based on database data of the target centralized database and a deep learning algorithm; A creation module, used to create a distributed database corresponding to the target centralized database according to the distributed database table structure and the optimized SQL statement; Wherein, the conversion module is used for: The random forest model is constructed on the database data in units of tables by using the random forest algorithm, and a decision tree is established in units of table objects to analyze field attributes one by one, wherein the field type mapping relationship of the basic table definition from the source database to the target database and the definition grammatical structure of the distributed table are pre-stored in the target centralized database; Inputting the database data of the target centralized database into the random forest model, automatically matching dictionaries one by one, and converting to obtain a distributed database table structure and structural script statements in the table structure; The device further comprises a statement generating module, and the statement generating module is used for: Creating a plurality of distributed SQL tasks using database data of the target centralized database; For each distributed SQL task, perform semantic parsing on the distributed SQL task, input the semantically parsed distributed SQL task into a first deep learning model, and output a distributed SQL query statement corresponding to the distributed SQL task, wherein the first deep learning model is constructed based on a deep learning algorithm; Use template interpolation algorithm to create distributed SQL templates; Inserting each distributed SQL query statement into the distributed SQL template respectively, obtaining a distributed SQL statement corresponding to each distributed SQL query statement, and using each corresponding distributed SQL statement as a first distributed SQL statement; Accordingly, the optimization module is used for: Based on deep learning algorithms, optimize each first distributed SQL statement; Wherein, the optimization module is used for: For any first distributed SQL statement, execute the following steps: Parsing the first distributed SQL statement using a syntax structure tree and an SQL parser to obtain characteristic keywords corresponding to the first distributed SQL statement, wherein the characteristic keywords include table field data types, data distribution, SQL query frequency, SQL execution time, data access mode, table join fields, and usage of indexes; Inputting the feature keyword into a second deep learning model and outputting a distributed table, wherein the second deep learning model is constructed based on a deep learning algorithm; Based on the distributed table, perform N query rewriting on the first distributed SQL statement according to the SQL rule to obtain N second distributed SQL statements; In a distributed database environment, simulate and execute N second distributed SQL statements to obtain a reconstructed distributed SQL table; Optimizing the first distributed SQL statement based on the reconstructed distributed SQL table; The database data of the target centralized database includes a plurality of centralized SQL tables; the optimization module is used for: Calculating a hash value of the reconstructed distributed SQL table and a hash value of an initial SQL table respectively, wherein the initial SQL table is a centralized SQL table in the target centralized database corresponding to the first distributed SQL statement; Determine whether the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table; If the hash value of the reconstructed distributed SQL table is the same as the hash value of the initial SQL table, then calculating the hash value for each distributed SQL statement in the reconstructed distributed SQL table, and selecting the distributed SQL statement with the smallest hash value from the hash values of all distributed SQL statements as the target SQL statement; If the hash value of the reconstructed distributed SQL table is different from the hash value of the initial SQL table, all distributed SQL statements in the reconstructed distributed SQL table are executed respectively, the distributed SQL statement with the shortest execution time is retained, and the distributed SQL statement with the shortest execution time is used as the target SQL statement; Using the target SQL statement as the optimized first distributed SQL statement; The database data of the target centralized database includes the execution time of each centralized SQL statement; and the optimization module is used for: Determine whether the execution time of the target SQL statement is not greater than the initial execution time, and whether the target SQL statement is reconstructible, wherein the initial execution time is the execution time of a centralized SQL statement in the target centralized database corresponding to the execution time of the first distributed SQL statement; If the execution time of the target SQL statement is greater than the initial execution time, and / or the target SQL statement cannot be reconstructed, returning to the step of parsing the first distributed SQL statement using the syntax structure tree and the SQL parser to obtain the characteristic keyword corresponding to the first distributed SQL statement and re-executing the step; If the execution time of the target SQL statement is not greater than the initial execution time and the target SQL statement can be reconstructed, the target SQL statement is used as the optimized first distributed SQL statement.
5. A terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the steps of the distributed database generation method as described in any one of claims 1 to 3 are implemented.
6. 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 distributed database generation method as described in any one of claims 1 to 3 are implemented.
