WO2023030461A1 - Distributed database detection method and apparatus - Google Patents

Distributed database detection method and apparatus Download PDF

Info

Publication number
WO2023030461A1
WO2023030461A1 PCT/CN2022/116588 CN2022116588W WO2023030461A1 WO 2023030461 A1 WO2023030461 A1 WO 2023030461A1 CN 2022116588 W CN2022116588 W CN 2022116588W WO 2023030461 A1 WO2023030461 A1 WO 2023030461A1
Authority
WO
WIPO (PCT)
Prior art keywords
statement
select
sql
table structure
generate
Prior art date
Application number
PCT/CN2022/116588
Other languages
French (fr)
Chinese (zh)
Inventor
陈双
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2023030461A1 publication Critical patent/WO2023030461A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • Embodiments of the present disclosure relate to the communication field, and in particular, to a distributed database detection method and device.
  • SQL Structured Query Language
  • the embodiment of the present disclosure provides a distributed database detection method and device to at least solve the problem that SQL statements in related technologies cannot be enumerated and traversed, and the artificially designed SQL syntax is relatively simple, which may easily cause the possibility of omission of test syntax and cannot meet the requirements.
  • a distributed database detection method including:
  • the distributed database is detected according to the table structure and the SQL statement.
  • a distributed database detection device including:
  • a construction module configured to construct a table structure according to the complexity factor
  • a generation module configured to obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
  • the detection module is configured to detect the distributed database according to the table structure and the SQL statement.
  • a computer-readable storage medium where a computer program is stored in the storage medium, wherein the computer program is set to execute any one of the above method embodiments when running in the steps.
  • an electronic device including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to perform any of the above Steps in the method examples.
  • FIG. 1 is a block diagram of a hardware structure of a mobile terminal of a distributed database detection method according to an embodiment of the present disclosure
  • FIG. 2 is a flowchart of a distributed database detection method according to an embodiment of the present disclosure
  • Fig. 3 is the flow chart of the generation method of the SELECT statement according to the present embodiment
  • Fig. 4 is a block diagram of a distributed database detection device according to the present embodiment.
  • Fig. 5 is a block diagram 1 of a distributed database detection device according to this preferred embodiment
  • Fig. 6 is a second block diagram of a distributed database detection device according to this preferred embodiment.
  • Fig. 7 is a third block diagram of a distributed database detection device according to this preferred embodiment.
  • FIG. 1 is a block diagram of a hardware structure of a mobile terminal according to a distributed database detection method according to an embodiment of the present disclosure.
  • a mobile terminal may include one or more (only shown in FIG. 1 a) a processor 102 (the processor 102 may include but not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned mobile terminal may also include a memory for communication Functional transmission device 106 and input and output device 108 .
  • a processor 102 may include but not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA
  • a memory 104 for storing data
  • the above-mentioned mobile terminal may also include a memory for communication Functional transmission device 106 and input and output device 108 .
  • FIG. 1 is only for illustration, and it does not limit the structure of the above mobile terminal.
  • the mobile terminal may also include more or fewer components than those shown in FIG. 1 , or have a different configuration from that shown in FIG. 1 .
  • the memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the distributed database detection method in the embodiment of the present disclosure, and the processor 102 runs the computer program stored in the memory 104, thereby Executing various functional applications and slicing processing of the service chain address pool is to realize the above-mentioned method.
  • the memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
  • the memory 104 may further include a memory that is remotely located relative to the processor 102, and these remote memories may be connected to the mobile terminal through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
  • the transmission device 106 is used to receive or transmit data via a network.
  • the specific example of the above network may include a wireless network provided by the communication provider of the mobile terminal.
  • the transmission device 106 includes a network interface controller (NIC for short), which can be connected to other network devices through a base station so as to communicate with the Internet.
  • the transmission device 106 may be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet in a wireless manner.
  • RF Radio Frequency
  • FIG. 1 is a flowchart of a distributed database detection method according to an embodiment of the present disclosure, as shown in Figure 2, the process includes the following steps:
  • Step S202 obtaining the complexity factor of SQL
  • Step S204 constructing a table structure according to the complexity factor
  • the above step S204 may specifically include: obtaining the field, field type, field length, distribution strategy, and partition strategy from the parameter dictionary table; The strategy and the partition strategy are combined to obtain a combination result; the table structure of the distributed database and the table structure of the heterogeneous database are constructed according to the combination.
  • the table structure is created through a CREATE statement, the CREATE statement includes table fields, table partitions, table distribution keys, and table indexes, and the CREATE statement is one of the SQL statements. Create syntax rules are as follows:
  • Step S206 obtaining the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generating an SQL statement according to the table structure and the basic elements;
  • Step S208 detecting the distributed database according to the table structure and the SQL statement.
  • the above step S208 may specifically include: injecting the table structure of the distributed database and the SQL statement into the distributed database, and simultaneously injecting the table structure of the heterogeneous database and the heterogeneous database, and generate the first result file of the distributed database and the second result file of the heterogeneous database; compare the first result file with the second result file to obtain the comparison result; if the If the comparison result is that the first result file is the same as the second result file, it is determined that the distributed database is normal; if the comparison result is that the first result file is different from the second result file, it is determined that the Distributed database exceptions described above.
  • the table structure is constructed according to the complexity factor, and the SQL statement is generated according to the table structure and basic elements, and the random creation of the table structure to the addition, deletion, modification and query of the corresponding data is realized, so that It can flexibly generate SQL statements and cope with complex application scenarios of distributed databases.
  • step S206 may specifically include:
  • the above S2062 may specifically include:
  • the SQL statement is a SELECT statement, generate the first SELECT statement according to the basic elements; generate the SELECT LIST of the SELECT statement according to the table structure and the complexity factor, specifically, if from the table structure
  • the selected SELECT LIST contains nested subqueries, and the number of nesting levels is determined according to the complexity factor; SELECT nesting is performed according to the number of nesting levels until the nested subqueries are not included, and the SELECT LIST is obtained by combination , wherein, the SELECT LIST is a component of the expression SELECT_expr of the SELECT statement; the FROM of the SELECT statement is determined according to the first SELECT statement, specifically, the FROM is determined according to the SQL complexity factor Composition structure; if the tab_reference in the FROM is a physical table, obtain the table name of the physical table, and generate the FROM according to the table name of the physical table; if the tab_reference in the FROM is a table based on the query result, determine that
  • the SQL statement is an INSERT statement, determine the composition of the VALUE contained in the INSERT statement according to the complexity factor, if the VALUES value_list is composed of specific values, determine the VALUES value_list according to the data type value range of the field in the table structure If the VALUES value_list is determined by the SELECT query result, generate the SELECT statement to form the VALUES value_list; determine the tbl_name according to the table structure; generate the INSERT statement according to the grammatical rules of the INSERT statement, wherein the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list; that is, the SQL statement is an INSERT statement, the INSERT statement includes VALUE and SELECT, and the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list, wherein, tbl_name is the table name, which is determined
  • VALUES value_list is a specific value or is composed of a select query statement.
  • the composition of value is determined according to the complexity factor. If the value is composed of specific values, the generation rule of the specific value is determined according to the value range of the data type of the field in the table structure. The value range of the data type is obtained from the parameter dictionary. Randomly generate a value that meets the requirements within the value range of the field data type; if the value is determined by the SELECT query result, call the SELECT generator to generate a select statement to form a value_list;
  • the SQL statement is an UPDATE statement, determine the assignment_list of the UPDATE statement according to the table structure, wherein the VALUE corresponding to the assignment_list is composed of a specific value or a query result of a select statement; determine the FROM and CONDITION of the UPDATE statement, and according to the UPDATE statement
  • the grammatical rules of the UPDATE statement generate the UPDATE statement, the grammatical rule of the UPDATE statement is: update tbl_name set assignment_list where condition; the grammatical rule of the UPDATE statement formed by the SET unit is: update tbl_name set assignment_list where condition, assignment_list represents the column name, the column name is determined according to the table structure, the VALUE corresponding to the assignment_list is composed of a specific value or the query result of the select statement, if it is obtained from the query result of the select statement, call step S5, call step S4 for the condition, and then form a complete UPDATE statement;
  • the SQL statement is a DELETE statement
  • determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, the specific method of determination is similar to that of FROM and CONDITION in the SELECT statement, and will not be repeated here.
  • the grammatical rule of the DELETE statement generates the DELETE statement, wherein the grammatical rule of the DELETE statement is: DELETE FROM tbl_name where CONDITION;
  • the SQL statement is a DELETE statement
  • determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
  • the SQL statement is an ALTER statement, determine the tbl_name of the ALTER statement according to the table structure; determine the alter_option of the ALTER statement according to the complexity factor, generate the ALTER statement according to the grammatical rules of the ALTER statement, Wherein, the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option; the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option, wherein, tbl_name is the table name determined when creating the table structure, alter_option includes the attribute of modifying the table structure, alter_option Including the data type, partition, and index in the parameter dictionary, determining the number of columns to add or delete according to the complexity factor, whether to modify the name of the variable column, whether to add or delete indexes, and partitions, to generate the ALTER statement;
  • the SQL statement is a DROP statement
  • obtain the table name from the table structure replace the table name with tbl_name according to the grammatical rules of the DROP statement, and generate the DROP statement, wherein the grammatical rule of the DROP statement is drop table tbl_name.
  • a parameter dictionary is created, which covers all field types, distribution strategies, partition strategies, all supported functions, grammar rules, grammar constraints, and field type value ranges.
  • the method of automatically generating the table structure Randomly combine the fields, field types, field lengths, distribution strategies, and partition strategies from the parameter dictionary table to construct the table structure according to the requirements of the distributed database table structure, and generate the table structure of the heterogeneous database at the same time; SELECT , INSERT, UPDATE, and DELETE statements are automatically generated as follows: get functions, grammar rules, grammar constraints, and field ranges from the parameter dictionary, generate SQL complexity factors from the complexity module, and generate SQL from the SQL generator.
  • the INSERT statement is automatically created according to the randomly generated table structure.
  • the value of the INSERT is randomly obtained within the boundary value range, and an illegal value is added for each field type at the same time; the random generation method of the SELECT statement is to obtain any function from the parameter dictionary, The grammatical rules of the function, combined with the complexity factor of the randomly generated SELECT query statement, automatically generates the query SQL.
  • the query SQL involves a SELECT LIST composed of simple fields, a SELECT LIST containing functions and expressions, and a SELECT LIST containing multiple table fields; UPDATE
  • the statement includes updating all table fields and traversing field boundary values. This embodiment can generate as many different SQLs as possible, covering different SQL statements, avoiding the omission of test cases, and increasing the reliability of the distributed database.
  • the complexity of the SQL is determined, the grammatical rules and grammatical rule constraints are obtained from the parameter dictionary, random field types and field range values are selected, and automatically generated by the SQL generator module Generate SQL. Inject the constructed table structure and SQL into the object under test and the heterogeneous database at the same time and generate a result file. The result comparer compares the two result comparison files to ensure the correctness of the result of the object under test.
  • the generation of SQL statements in this embodiment includes the generation of DDL and DML, and the generation of DDL includes the generation of CREATE, ALTER, and DROP statements of distributed database tables.
  • the CREATE statement includes table fields, table partitions, and table distribution keys;
  • the ALTER statement includes fields, indexes, partitions, table indexes, and column attributes;
  • the DROP statement includes table names.
  • the DML generation includes SELECT, UPDATE, INSERT, DELETE generation;
  • SELECT generation includes SELECT LIST, FROM and CONDITION generation;
  • the SELECT generation includes subqueries and functions, the FROM generation includes subqueries and associated tables, and the CONDITION generation contains subqueries;
  • Fig. 3 is a flow chart of the generation method of the SELECT statement according to the present embodiment, as shown in Fig. 3, comprising the following steps:
  • Step S301 obtain the SQL complexity factor, control the SQL complexity, the SQL generator obtains the SQL basic elements from the parameter dictionary according to the complexity factor, and generates a SELECT statement (corresponding to the first SELECT statement above, and the SELECT statement is composed of: SELECT SELECT_expr FROM tab_reference CONDITION);
  • Step S302 generate the SELECT LIST of the SELECT statement according to the table structure
  • the SELECT LIST is a component of the expression SELECT_expr, randomly generate field values and several functions according to the complexity factor combined with the grammatical rules obtained from the parameter dictionary, if the selected SELECT LIST contains For nested subquery, nested SELECT is generated. The number of nesting layers is determined by the complexity factor.
  • the SELECT LIST structure is determined, including: column name, function, and subquery;
  • Step S303 determine the FROM of the SELECT statement, execute FROM generation, determine the FROM composition structure by the SQL complexity factor, the table tab_reference in the FROM includes a physical table or a table (virtual table) based on the query result, if it is a physical table, obtain the physical table The table name of the table and the table name of the physical table generate FROM; if FROM contains a table based on the query result, FROM involves a subquery, then call step S301 to generate a FROM composed of a SELECT statement, and use the SELECT query result of the executed SELECT statement as The tab_reference of FROM; if it is determined that FROM includes the association between tables, then obtain the association table information from the CREATE generation module, and call step S301, generate a SELECT statement based on the association table, and generate a FROM formed by the SELECT statement;
  • Step S304 determine the CONDITION of the SQL statement according to the complexity factor, wherein the SQL condition includes a logical expression, execute CONDITION generation, the SQL condition is determined by the complexity factor and step S301, the CONDITION includes a logical expression, and the condition in the expression Consists of a SELECT statement or a specific value, where the specific value is directly generated according to the field range in the parameter dictionary;
  • Step S305 generate all query statements according to the SELECT statement generated in step S302, the FROM determined in step S303, and the CONDITION generated in step S304, and all statement blocks are nested and spliced into a complete SQL query statement (corresponding to the second SELECT above statement) output.
  • FIG. 4 is a block diagram of a distributed database detection device according to this embodiment. As shown in FIG. 4 , it includes:
  • Obtaining module 42 configured to obtain the complexity factor of SQL
  • a construction module 44 configured to construct a table structure according to the complexity factor
  • the generation module 46 is configured to obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
  • the detection module 48 is configured to detect the distributed database according to the table structure and the SQL statement.
  • Fig. 5 is a block diagram one of a distributed database detection device according to this preferred embodiment. As shown in Fig. 5, the construction module 44 includes:
  • the first obtaining submodule 52 is configured to obtain fields, field types, field lengths, distribution strategies and partition strategies from the parameter dictionary table;
  • the combination submodule 54 is configured to combine the field, the field type, the field length, the distribution strategy and the partition strategy to obtain a combination result;
  • the construction sub-module 56 is configured to construct the table structure of the distributed database and the table structure of the heterogeneous database according to the combination.
  • Fig. 6 is a block diagram two of a distributed database detection device according to this preferred embodiment.
  • the detection module 48 includes:
  • the injection sub-module 62 is configured to inject the table structure of the distributed database and the SQL statement into the distributed database, and simultaneously inject the table structure of the heterogeneous database and the SQL statement into the heterogeneous database, and generate The first result file of the distributed database and the second result file of the heterogeneous database;
  • the comparison submodule 64 is configured to compare the first result file with the second result file to obtain a comparison result
  • the first determination sub-module 66 is configured to determine that the distributed database is normal if the comparison result is that the first result file is the same as the second result file;
  • the second determination sub-module 68 is configured to determine that the distributed database is abnormal if the comparison result is that the first result file is different from the second result file.
  • Fig. 7 is a block diagram three of a distributed database detection device according to this preferred embodiment, as shown in Fig. 7, the generating module 46 includes:
  • the second acquiring submodule 72 is configured to acquire functions, grammar rules, grammar constraints, and field ranges from the parameter dictionary, wherein the basic elements include the functions, the grammar rules, the grammar constraints, and the field range;
  • the generating submodule 74 is configured to generate the SQL statement according to the complexity factor, the table structure, the function, the grammatical rule, the grammatical restriction and the field range.
  • the generating submodule 74 is further configured to:
  • the SQL statement is a SELECT statement, generate the first SELECT statement according to the basic elements; generate the SELECT LIST of the SELECT statement according to the table structure and the complexity factor, wherein the SELECT LIST is the SELECT A component of the expression SELECT_expr of the statement; determine the FROM of the SELECT statement according to the first SELECT statement, determine the CONDITION of the SELECT statement according to the complexity factor; generate the SELECT according to the grammatical rules of the SELECT statement statement, the grammatical rule of the SELECT statement is SELECT SELECT_expr FROM tab_reference CONDITION.
  • the SQL statement is an INSERT statement, determine the composition of the VALUE contained in the INSERT statement according to the complexity factor, if the VALUES value_list is composed of specific values, determine the VALUES value_list according to the data type value range of the field in the table structure If the VALUES value_list is determined by the SELECT query result, generate the SELECT statement to form the VALUES value_list; determine the tbl_name according to the table structure; generate the INSERT statement according to the grammatical rules of the INSERT statement, wherein the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list;
  • the SQL statement is an UPDATE statement
  • the grammatical rules of the UPDATE statement are generated, and the grammatical rules of the UPDATE statement are: update tbl_name set assignment_list where condition;
  • the SQL statement is a DELETE statement
  • determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
  • the SQL statement is a DELETE statement
  • determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
  • the SQL statement is an ALTER statement
  • determine the alter_option of the ALTER statement according to the complexity factor generate the ALTER statement according to the grammatical rules of the ALTER statement, Among them, the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option;
  • the SQL statement is a DROP statement
  • obtain the table name from the table structure replace the table name with tbl_name according to the grammatical rules of the DROP statement, and generate the DROP statement, wherein the grammatical rule of the DROP statement is drop table tbl_name.
  • the generating submodule 74 is further configured to:
  • the number of nested layers is determined according to the complexity factor
  • SELECT nesting is performed according to the number of nesting layers until the nested sub-queries are not included, and the SELECT LIST is obtained through combination.
  • the generating submodule 74 is further configured to:
  • If the tab_reference in the FROM is a physical table, obtain the table name of the physical table, and generate the FROM according to the table name of the physical table;
  • the tab_reference in the FROM is a table based on query results
  • Embodiments of the present disclosure also provide a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps in any one of the above method embodiments when running.
  • the above-mentioned computer-readable storage medium may include but not limited to: U disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM) , mobile hard disk, magnetic disk or optical disk and other media that can store computer programs.
  • ROM read-only memory
  • RAM random access memory
  • mobile hard disk magnetic disk or optical disk and other media that can store computer programs.
  • Embodiments of the present disclosure also provide an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
  • the electronic device may further include a transmission device and an input and output device, wherein the transmission device is connected to the processor, and the input and output device is connected to the processor.
  • each module or each step of the above-mentioned disclosure can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network composed of multiple computing devices In fact, they can be implemented in program code executable by a computing device, and thus, they can be stored in a storage device to be executed by a computing device, and in some cases, can be executed in an order different from that shown here. Or described steps, or they are fabricated into individual integrated circuit modules, or multiple modules or steps among them are fabricated into a single integrated circuit module for implementation. As such, the present disclosure is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Quality & Reliability (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Embodiments of the present disclosure provide a distributed database detection method and apparatus. The method comprises: obtaining a complexity factor of an SQL; constructing a table structure according to the complexity factor; obtaining a basic element of the SQL from a parameter dictionary according to the complexity factor, and generating an SQL statement according to the table structure and the basic element; and detecting a distributed database according to the table structure and the SQL statement, which can solve the problems in the related art that the SQL statement cannot be enumerated and traversed, an SQL grammar designed artificially is also relatively simple, a test grammar is easy to miss, and an actual complex application scenario of the distributed database cannot be met. The table structure is constructed according to the complexity factor, and the SQL statement is generated according to the table structure and the basic element, such that the addition, deletion, modification and checking of corresponding data from random creation of the table structure are implemented, and the SQL statement can be flexibly generated to deal with the complex application scenario of the distributed database.

Description

一种分布式数据库检测方法及装置A distributed database detection method and device
相关申请的交叉引用Cross References to Related Applications
本公开基于2021年09月02日提交的发明名称为“一种分布式数据库检测方法及装置”的中国专利申请CN202111028813.8,并且要求该专利申请的优先权,通过引用将其所公开的内容全部并入本公开。This disclosure is based on the Chinese patent application CN202111028813.8 filed on September 2, 2021 with the title of "a distributed database detection method and device", and claims the priority of this patent application, and the disclosed content is incorporated by reference All are incorporated into this disclosure.
技术领域technical field
本公开实施例涉及通信领域,具体而言,涉及一种分布式数据库检测方法及装置。Embodiments of the present disclosure relate to the communication field, and in particular, to a distributed database detection method and device.
背景技术Background technique
随着国产分布式数据库的快速发展,结构化查询语句(Structured Query Language,简称为SQL)语法兼容性和使用方法面临巨大挑战。同时,分布式数据库使用的场景越来越多,对数据库支持的功能和性能也提出更高的要求。由于不同的业务表表结构不同,业务逻辑复杂多变,导致SQL语句的写法也是多种多样的,手动编写的测试SQL或常规SQL生成工具自动生成的SQL无法做到枚举遍历,且设计的SQL语法也较为简单,容易产生测试语法遗漏的可能无法满足实际分布式数据库复杂的应用场景。With the rapid development of domestic distributed databases, the syntax compatibility and usage of Structured Query Language (SQL) are facing great challenges. At the same time, distributed databases are used in more and more scenarios, and higher requirements are placed on the functions and performance supported by the database. Due to the different structures of different business tables and the complex and changeable business logic, there are also various ways to write SQL statements. Manually written test SQL or SQL automatically generated by conventional SQL generation tools cannot be enumerated and traversed, and the designed The SQL syntax is also relatively simple, which is prone to omissions in the test syntax and may not be able to meet the complex application scenarios of the actual distributed database.
针对相关技术的SQL语句无法做到枚举遍历,人工设计的SQL语法也较为简单,容易造成测试语法遗漏且无法满足实际分布式数据库复杂的应用场景的问题,尚未提出解决方案。The SQL statements of related technologies cannot be enumerated and traversed, and the artificially designed SQL syntax is relatively simple, which may easily cause the omission of test syntax and fail to meet the complex application scenarios of the actual distributed database. No solution has been proposed yet.
发明内容Contents of the invention
本公开实施例提供了一种分布式数据库检测方法及装置,以至少解决相关技术的SQL语句无法做到枚举遍历,人工设计的SQL语法也较为简单,容易造成测试语法遗漏的可能且无法满足实际分布式数据库复杂的应用场景的问题。The embodiment of the present disclosure provides a distributed database detection method and device to at least solve the problem that SQL statements in related technologies cannot be enumerated and traversed, and the artificially designed SQL syntax is relatively simple, which may easily cause the possibility of omission of test syntax and cannot meet the requirements. The problem of complex application scenarios of actual distributed databases.
根据本公开的一个实施例,提供了一种分布式数据库检测方法,包括:According to an embodiment of the present disclosure, a distributed database detection method is provided, including:
获取SQL的复杂度因子;Get the complexity factor of SQL;
根据所述复杂度因子构造表结构;Constructing a table structure according to the complexity factor;
根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;Obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
根据所述表结构与所述SQL语句对分布式数据库进行检测。The distributed database is detected according to the table structure and the SQL statement.
根据本公开的另一个实施例,提供了一种分布式数据库检测装置,包括:According to another embodiment of the present disclosure, a distributed database detection device is provided, including:
获取模块,设置为获取SQL的复杂度因子;Get the module, set to get the complexity factor of SQL;
构造模块,设置为根据所述复杂度因子构造表结构;A construction module, configured to construct a table structure according to the complexity factor;
生成模块,设置为根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;A generation module configured to obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
检测模块,设置为根据所述表结构与所述SQL语句对分布式数据库进行检测。The detection module is configured to detect the distributed database according to the table structure and the SQL statement.
根据本公开的又一个实施例,还提供了一种计算机可读的存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行上述任一项方法实施例中的步 骤。According to yet another embodiment of the present disclosure, there is also provided a computer-readable storage medium, where a computer program is stored in the storage medium, wherein the computer program is set to execute any one of the above method embodiments when running in the steps.
根据本公开的又一个实施例,还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行上述任一项方法实施例中的步骤。According to yet another embodiment of the present disclosure, there is also provided an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to perform any of the above Steps in the method examples.
附图说明Description of drawings
图1是本公开实施例的分布式数据库检测方法的移动终端的硬件结构框图;FIG. 1 is a block diagram of a hardware structure of a mobile terminal of a distributed database detection method according to an embodiment of the present disclosure;
图2是根据本公开实施例的分布式数据库检测方法的流程图;2 is a flowchart of a distributed database detection method according to an embodiment of the present disclosure;
图3是根据本实施例的SELECT语句的生成方法的流程图;Fig. 3 is the flow chart of the generation method of the SELECT statement according to the present embodiment;
图4是根据本实施例的分布式数据库检测装置的框图;Fig. 4 is a block diagram of a distributed database detection device according to the present embodiment;
图5是根据本优选实施例的分布式数据库检测装置的框图一;Fig. 5 is a block diagram 1 of a distributed database detection device according to this preferred embodiment;
图6是根据本优选实施例的分布式数据库检测装置的框图二;Fig. 6 is a second block diagram of a distributed database detection device according to this preferred embodiment;
图7是根据本优选实施例的分布式数据库检测装置的框图三。Fig. 7 is a third block diagram of a distributed database detection device according to this preferred embodiment.
具体实施方式Detailed ways
下文中将参考附图并结合实施例来详细说明本公开的实施例。Hereinafter, embodiments of the present disclosure will be described in detail with reference to the drawings and in combination with the embodiments.
需要说明的是,本公开的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。It should be noted that the terms "first" and "second" in the specification and claims of the present disclosure and the above drawings are used to distinguish similar objects, but not necessarily used to describe a specific sequence or sequence.
本公开实施例中所提供的方法实施例可以在移动终端、计算机终端或者类似的运算装置中执行。以运行在移动终端上为例,图1是本公开实施例的分布式数据库检测方法的移动终端的硬件结构框图,如图1所示,移动终端可以包括一个或多个(图1中仅示出一个)处理器102(处理器102可以包括但不限于微处理器MCU或可编程逻辑器件FPGA等的处理装置)和用于存储数据的存储器104,其中,上述移动终端还可以包括用于通信功能的传输设备106以及输入输出设备108。本领域普通技术人员可以理解,图1所示的结构仅为示意,其并不对上述移动终端的结构造成限定。例如,移动终端还可包括比图1中所示更多或者更少的组件,或者具有与图1所示不同的配置。The method embodiments provided in the embodiments of the present disclosure may be executed in mobile terminals, computer terminals or similar computing devices. Taking running on a mobile terminal as an example, FIG. 1 is a block diagram of a hardware structure of a mobile terminal according to a distributed database detection method according to an embodiment of the present disclosure. As shown in FIG. 1 , a mobile terminal may include one or more (only shown in FIG. 1 a) a processor 102 (the processor 102 may include but not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned mobile terminal may also include a memory for communication Functional transmission device 106 and input and output device 108 . Those skilled in the art can understand that the structure shown in FIG. 1 is only for illustration, and it does not limit the structure of the above mobile terminal. For example, the mobile terminal may also include more or fewer components than those shown in FIG. 1 , or have a different configuration from that shown in FIG. 1 .
存储器104可用于存储计算机程序,例如,应用软件的软件程序以及模块,如本公开实施例中的分布式数据库检测方法对应的计算机程序,处理器102通过运行存储在存储器104内的计算机程序,从而执行各种功能应用以及业务链地址池切片处理,即实现上述的方法。存储器104可包括高速随机存储器,还可包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其他非易失性固态存储器。在一些实例中,存储器104可进一步包括相对于处理器102远程设置的存储器,这些远程存储器可以通过网络连接至移动终端。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the distributed database detection method in the embodiment of the present disclosure, and the processor 102 runs the computer program stored in the memory 104, thereby Executing various functional applications and slicing processing of the service chain address pool is to realize the above-mentioned method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory that is remotely located relative to the processor 102, and these remote memories may be connected to the mobile terminal through a network. Examples of the aforementioned networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
传输装置106用于经由一个网络接收或者发送数据。上述的网络具体实例可包括移动终端的通信供应商提供的无线网络。在一个实例中,传输装置106包括一个网络适配器(Network Interface Controller,简称为NIC),其可通过基站与其他网络设备相连从而可与互联网进行通讯。在一个实例中,传输装置106可以为射频(Radio Frequency,简称为RF)模块,其用于通过无线方式与互联网进行通讯。The transmission device 106 is used to receive or transmit data via a network. The specific example of the above network may include a wireless network provided by the communication provider of the mobile terminal. In one example, the transmission device 106 includes a network interface controller (NIC for short), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet in a wireless manner.
在本实施例中提供了一种运行于上述移动终端或网络架构的分布式数据库检测方法,应 用于终端,所述终端通过双连接(Dual Connection,简称为DC)接入源区域的当前主节点MN小区与当前辅节点SN小区,图2是根据本公开实施例的分布式数据库检测方法的流程图,如图2所示,该流程包括如下步骤:In this embodiment, a distributed database detection method running on the above-mentioned mobile terminal or network architecture is provided, which is applied to a terminal, and the terminal accesses the current master node of the source area through a dual connection (Dual Connection, referred to as DC) MN cell and current secondary node SN cell, Figure 2 is a flowchart of a distributed database detection method according to an embodiment of the present disclosure, as shown in Figure 2, the process includes the following steps:
步骤S202,获取SQL的复杂度因子;Step S202, obtaining the complexity factor of SQL;
步骤S204,根据所述复杂度因子构造表结构;Step S204, constructing a table structure according to the complexity factor;
本实施例中,上述步骤S204具体可以包括:从参数字典表中获取字段、字段类型、字段长度、分发策略以及分区策略;将所述字段、所述字段类型、所述字段长度、所述分发策略以及分区策略进行组合,得到组合结果;根据所述组合构建所述分布式数据库的表结构与异构数据库的表结构。具体的,通过CREATE语句创建所述表结构,所述CREATE语句包括表字段、表分区、表分发键、表索引,CREATE语句为所述SQL语句的一种。Create语法规则如下:In this embodiment, the above step S204 may specifically include: obtaining the field, field type, field length, distribution strategy, and partition strategy from the parameter dictionary table; The strategy and the partition strategy are combined to obtain a combination result; the table structure of the distributed database and the table structure of the heterogeneous database are constructed according to the combination. Specifically, the table structure is created through a CREATE statement, the CREATE statement includes table fields, table partitions, table distribution keys, and table indexes, and the CREATE statement is one of the SQL statements. Create syntax rules are as follows:
CREATE TABLE[IF NOT EXISTS]tbl_name(create_definition,...)[partition_options][distributed_option],其中,[]表示可选,create_definition表示表定义,包括字段、字段类型、索引等,partition_options表示分区策略,distributed_option表示分发策略。CREATE TABLE[IF NOT EXISTS]tbl_name(create_definition,...)[partition_options][distributed_option], where [] means optional, create_definition means table definition, including fields, field types, indexes, etc., partition_options means partition strategy, distributed_option Indicates the distribution strategy.
步骤S206,根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;Step S206, obtaining the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generating an SQL statement according to the table structure and the basic elements;
步骤S208,根据所述表结构与所述SQL语句对分布式数据库进行检测。Step S208, detecting the distributed database according to the table structure and the SQL statement.
本实施例中,上述步骤S208具体可以包括:将所述分布式数据库的表结构与所述SQL语句注入分布式数据库,同时将所述异构数据库的表结构与所述SQL语句所述异构数据库中,并生成所述分布式数据库的第一结果文件与所述异构数据库的第二结果文件;将所述第一结果文件与所述第二结果文件进行对比,得到对比结果;若所述对比结果为所述第一结果文件与所述第二结果文件相同,确定所述分布式数据库正常;若所述对比结果为所述第一结果文件与所述第二结果文件不同,确定所述分布式数据库异常。In this embodiment, the above step S208 may specifically include: injecting the table structure of the distributed database and the SQL statement into the distributed database, and simultaneously injecting the table structure of the heterogeneous database and the heterogeneous database, and generate the first result file of the distributed database and the second result file of the heterogeneous database; compare the first result file with the second result file to obtain the comparison result; if the If the comparison result is that the first result file is the same as the second result file, it is determined that the distributed database is normal; if the comparison result is that the first result file is different from the second result file, it is determined that the Distributed database exceptions described above.
通过上述步骤S202至S208,获取SQL的复杂度因子;根据所述复杂度因子构造表结构;根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;根据所述表结构与所述SQL语句对分布式数据库进行检测,可以解决相关技术的SQL语句无法做到枚举遍历,人工设计的SQL语法也较为简单,容易造成测试语法遗漏且无法满足实际分布式数据库复杂的应用场景的问题,根据复杂度因子构建表结构,根据表结构与基本元素生成SQL语句,实现从表结构的随机创建到对应数据的增删改查,使得可以灵活地生成SQL语句,可以应对分布式数据库复杂的应用场景。Through the above steps S202 to S208, obtain the complexity factor of SQL; construct a table structure according to the complexity factor; obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and according to the table structure and the The above basic elements generate SQL statements; according to the table structure and the SQL statement, the distributed database is detected, which can solve the problem that the SQL statement of the related technology cannot be enumerated and traversed, and the artificially designed SQL syntax is relatively simple, which is easy to cause test The grammar is missing and cannot meet the complex application scenarios of the actual distributed database. The table structure is constructed according to the complexity factor, and the SQL statement is generated according to the table structure and basic elements, and the random creation of the table structure to the addition, deletion, modification and query of the corresponding data is realized, so that It can flexibly generate SQL statements and cope with complex application scenarios of distributed databases.
本实施例中,上述步骤S206具体可以包括:In this embodiment, the above step S206 may specifically include:
S2061,从所述参数字典中获取函数、语法规则、语法限制条件以及字段范围,其中,所述基本元素包括所述函数、所述语法规则、所述语法限制条件以及所述字段范围;S2061. Acquire functions, grammar rules, grammar constraints and field ranges from the parameter dictionary, wherein the basic elements include the functions, the grammar rules, the grammar constraints and the field ranges;
S2062,根据所述复杂度因子、所述表结构、所述函数、所述语法规则、所述语法限制条件以及所述字段范围生成所述SQL语句。S2062. Generate the SQL statement according to the complexity factor, the table structure, the function, the grammar rule, the grammar constraint and the field range.
在一实施例中,上述S2062具体可以包括:In an embodiment, the above S2062 may specifically include:
若所述SQL语句为SELECT语句,根据所述基本元素生成第一SELECT语句;根据所述表结构与所述复杂度因子生成所述SELECT语句的SELECT LIST,具体的,若从所述表结构中选 取的SELECT LIST包含嵌套子查询,根据所述复杂度因子确定嵌套层数;根据所述嵌套层数执行SELECT嵌套,直到不包含所述嵌套子查询,组合得到所述SELECT LIST,其中,所述SELECT LIST为所述SELECT语句的表达式SELECT_expr的组成部分;根据所述第一SELECT语句确定所述SELECT语句的FROM,具体的,根据所述SQL复杂度因子确定所述FROM的组成结构;若所述FROM中的tab_reference为物理表,获取物理表的表名,根据物理表的表名生成所述FROM;若FROM中的tab_reference为基于查询结果的表,在确定所述FROM涉及子查询的情况下,生成所述第一SELECT语句构成的所述FROM,将执行所述第一SELECT语句的SELECT查询结果作为所述FROM的tab_reference;在确定所述FROM包含表与表之间的关联的情况下,获取关联表信息,生成基于关联表的第二SELECT语句,生成所述第二SELECT语句构成的所述FROM;根据所述复杂度因子确定所述SELECT语句的CONDI TION;根据所述SELECT语句的语法规则生成所述SELECT语句,所述SELECT语句的所述语法规则为SELECT SELECT_expr FROM tab_reference CONDITION;即所述SQL语句为SELECT语句,根据所述复杂度因子、所述表结构、所述函数、所述语法规则、所述语法限制条件以及所述字段范围创建所述SELECT语句,所述SELECT语句的所述语法规则为SELECT SELECT_expr FROM tab_reference CONDITION,所述SELECT SELECT_expr包括所述函数所述CONDITION为所述语法限制条件,所述SELECT SELECT_expr与所述CONDITION包含所述函数;If the SQL statement is a SELECT statement, generate the first SELECT statement according to the basic elements; generate the SELECT LIST of the SELECT statement according to the table structure and the complexity factor, specifically, if from the table structure The selected SELECT LIST contains nested subqueries, and the number of nesting levels is determined according to the complexity factor; SELECT nesting is performed according to the number of nesting levels until the nested subqueries are not included, and the SELECT LIST is obtained by combination , wherein, the SELECT LIST is a component of the expression SELECT_expr of the SELECT statement; the FROM of the SELECT statement is determined according to the first SELECT statement, specifically, the FROM is determined according to the SQL complexity factor Composition structure; if the tab_reference in the FROM is a physical table, obtain the table name of the physical table, and generate the FROM according to the table name of the physical table; if the tab_reference in the FROM is a table based on the query result, determine that the FROM involves In the case of a sub-query, the FROM composed of the first SELECT statement is generated, and the SELECT query result of executing the first SELECT statement is used as the tab_reference of the FROM; In the case of association, obtain the association table information, generate the second SELECT statement based on the association table, and generate the FROM formed by the second SELECT statement; determine the CONDITION of the SELECT statement according to the complexity factor; The grammatical rule of the SELECT statement generates the SELECT statement, the grammatical rule of the SELECT statement is SELECT SELECT_expr FROM tab_reference CONDITION; that is, the SQL statement is a SELECT statement, according to the complexity factor, the table structure, the Create the SELECT statement based on the function, the grammatical rule, the grammatical restriction and the field range, the grammatical rule of the SELECT statement is SELECT SELECT_expr FROM tab_reference CONDITION, and the SELECT SELECT_expr includes the function described CONDITION is the grammatical restriction, the SELECT SELECT_expr and the CONDITION include the function;
若所述SQL语句为INSERT语句,根据所述复杂度因子确定INSERT语句包含的VALUE的构成,若VALUES value_list由具体值构成,根据所述表结构中字段的数据类型取值范围确定所述VALUES value_list;若VALUES value_list由SELECT查询结果确定,生成SELECT语句构成所述VALUES value_list;根据所述表结构确定tbl_name;根据INSERT语句的语法规则生成所述INSERT语句,其中,INSERT语句的语法规则为:INSERT INTO tbl_name VALUES value_list;即所述SQL语句为INSERT语句,INSERT语句包含VALUE和SELECT,INSERT语句的语法规则为:INSERT INTO tbl_name VALUES value_list,其中,tbl_name为表名,在创建所述表结构时确定)。VALUES value_list为具体值或者由select查询语句构成。根据复杂度因子确定value的构成,若value值由具体值构成,则具体值的生成规则根据所述表结构中字段的数据类型取值范围确定,数据类型取值范围从参数字典中获取,在字段数据类型取值范围内随机生成符合要求的数值;若value值由SELECT查询结果确定,则调用SELECT生成器生成select语句构成value_list;If the SQL statement is an INSERT statement, determine the composition of the VALUE contained in the INSERT statement according to the complexity factor, if the VALUES value_list is composed of specific values, determine the VALUES value_list according to the data type value range of the field in the table structure If the VALUES value_list is determined by the SELECT query result, generate the SELECT statement to form the VALUES value_list; determine the tbl_name according to the table structure; generate the INSERT statement according to the grammatical rules of the INSERT statement, wherein the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list; that is, the SQL statement is an INSERT statement, the INSERT statement includes VALUE and SELECT, and the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list, wherein, tbl_name is the table name, which is determined when the table structure is created). VALUES value_list is a specific value or is composed of a select query statement. The composition of value is determined according to the complexity factor. If the value is composed of specific values, the generation rule of the specific value is determined according to the value range of the data type of the field in the table structure. The value range of the data type is obtained from the parameter dictionary. Randomly generate a value that meets the requirements within the value range of the field data type; if the value is determined by the SELECT query result, call the SELECT generator to generate a select statement to form a value_list;
若所述SQL语句为UPDATE语句,根据所述表结构确定UPDATE语句的assignment_list,其中,assignment_list对应的VALUE由具体值或者由select语句查询结果构成;确定UPDATE语句的FROM与CONDITION,根据所述UPDATE语句的语法规则生成所述UPDATE语句,所述UPDATE语句的语法规则为:update tbl_name set assignment_list where condition;所述UPDATE语句由SET单元构成UPDATE语句的语法规则为:update tbl_name set assignment_list where condition,assignment_list表示列名,列名根据表结构确定,assignment_list对应的VALUE由具体值或者由select语句查询结果构成,若为select语句查询结果得到,则调用步骤S5,condition调用步骤S4,然后组成一条完整的UPDATE语句;If the SQL statement is an UPDATE statement, determine the assignment_list of the UPDATE statement according to the table structure, wherein the VALUE corresponding to the assignment_list is composed of a specific value or a query result of a select statement; determine the FROM and CONDITION of the UPDATE statement, and according to the UPDATE statement The grammatical rules of the UPDATE statement generate the UPDATE statement, the grammatical rule of the UPDATE statement is: update tbl_name set assignment_list where condition; the grammatical rule of the UPDATE statement formed by the SET unit is: update tbl_name set assignment_list where condition, assignment_list represents the column name, the column name is determined according to the table structure, the VALUE corresponding to the assignment_list is composed of a specific value or the query result of the select statement, if it is obtained from the query result of the select statement, call step S5, call step S4 for the condition, and then form a complete UPDATE statement;
若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,确定的具体方式与SELECT语句中FROM与CONDITION确定的方式类似,在此 不再赘述,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, the specific method of determination is similar to that of FROM and CONDITION in the SELECT statement, and will not be repeated here. According to the The grammatical rule of the DELETE statement generates the DELETE statement, wherein the grammatical rule of the DELETE statement is: DELETE FROM tbl_name where CONDITION;
若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
若所述SQL语句为ALTER语句,根据所述表结构确定所述ALTER语句的tbl_name;根据所述复杂度因子确定所述ALTER语句的alter_option,根据所述ALTER语句的语法规则生成所述ALTER语句,其中,ALTER语句的语法规则为ALTER TABLE tbl_name alter_option;ALTER语句的语法规则为ALTER TABLE tbl_name alter_option,其中,tbl_name为创建所述表结构时确定的表名,alter_option包括修改所述表结构的属性,alter_option包括参数字典中的数据类型、分区、索引,根据所述复杂度因子确定增删列的个数,是否修改变列的名称,是否增删索引、分区,以生成所述ALTER语句;If the SQL statement is an ALTER statement, determine the tbl_name of the ALTER statement according to the table structure; determine the alter_option of the ALTER statement according to the complexity factor, generate the ALTER statement according to the grammatical rules of the ALTER statement, Wherein, the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option; the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option, wherein, tbl_name is the table name determined when creating the table structure, alter_option includes the attribute of modifying the table structure, alter_option Including the data type, partition, and index in the parameter dictionary, determining the number of columns to add or delete according to the complexity factor, whether to modify the name of the variable column, whether to add or delete indexes, and partitions, to generate the ALTER statement;
若所述SQL语句为DROP语句,从所述表结构中获取表名,根据DROP语句的语法规则将所述表名替换tbl_name,生成所述DROP语句,其中,所述DROP语句的语法规则为drop table tbl_name。If the SQL statement is a DROP statement, obtain the table name from the table structure, replace the table name with tbl_name according to the grammatical rules of the DROP statement, and generate the DROP statement, wherein the grammatical rule of the DROP statement is drop table tbl_name.
本实施例中,创建参数字典,参数字典涵盖全字段类型、分发策略、分区策略、支持的所有函数、语法规则、语法限制条件、字段类型值范围。自动生成表结构方法:从参数字典表中任意获取字段、字段类型、字段长度、分发策略、分区策略进行随机组合按照分布式数据库表结构要求构建表结构,同时生成异构数据库的表结构;SELECT、INSERT、UPDATE、DELETE语句自动生成方法为:从参数字典中获取函数、语法规则、语法限制条件、字段范围,由复杂度模块生成SQL复杂度因子、由SQL生成器生成SQL。在分布式数据库根据随机生成的表结构自动创建INSERT语句,INSERT的值在边界值范围内随机获取、同时为每种字段类型添加非法值;SELECT语句随机生成方法为从参数字典中获取任意函数、函数的语法规则,结合随机生成的SELECT查询语句复杂度因子,自动生成查询SQL,查询SQL涉及简单字段组成的SELECT LIST、含有函数及表达式的SELECT LIST、含有多张表字段的SELECT LIST;UPDATE语句包含更新全表字段、遍历字段边界值。本实施例能尽可能的生成不同SQL,涵盖不同SQL语句,避免测试用例的遗漏,增加分布式数据库的可靠性。In this embodiment, a parameter dictionary is created, which covers all field types, distribution strategies, partition strategies, all supported functions, grammar rules, grammar constraints, and field type value ranges. The method of automatically generating the table structure: Randomly combine the fields, field types, field lengths, distribution strategies, and partition strategies from the parameter dictionary table to construct the table structure according to the requirements of the distributed database table structure, and generate the table structure of the heterogeneous database at the same time; SELECT , INSERT, UPDATE, and DELETE statements are automatically generated as follows: get functions, grammar rules, grammar constraints, and field ranges from the parameter dictionary, generate SQL complexity factors from the complexity module, and generate SQL from the SQL generator. In the distributed database, the INSERT statement is automatically created according to the randomly generated table structure. The value of the INSERT is randomly obtained within the boundary value range, and an illegal value is added for each field type at the same time; the random generation method of the SELECT statement is to obtain any function from the parameter dictionary, The grammatical rules of the function, combined with the complexity factor of the randomly generated SELECT query statement, automatically generates the query SQL. The query SQL involves a SELECT LIST composed of simple fields, a SELECT LIST containing functions and expressions, and a SELECT LIST containing multiple table fields; UPDATE The statement includes updating all table fields and traversing field boundary values. This embodiment can generate as many different SQLs as possible, covering different SQL statements, avoiding the omission of test cases, and increasing the reliability of the distributed database.
本实施例根据SQL复杂度控制模块随机生成的复杂度因子确定SQL的复杂度,从参数字典中获取语法规则及语法规则限制条件,选取随机的字段类型及字段范围值,通过SQL生成器模块自动生成SQL。将构造出的表结构和SQL同时注入到被测对象和异构数据库并生成结果文件,结果比对器对比二者的结果比对文件确保被测对象结果的正确性。In this embodiment, according to the complexity factor generated randomly by the SQL complexity control module, the complexity of the SQL is determined, the grammatical rules and grammatical rule constraints are obtained from the parameter dictionary, random field types and field range values are selected, and automatically generated by the SQL generator module Generate SQL. Inject the constructed table structure and SQL into the object under test and the heterogeneous database at the same time and generate a result file. The result comparer compares the two result comparison files to ensure the correctness of the result of the object under test.
本实施例中的SQL语句生成包括DDL、DML的生成,所述DDL生成包含分布式数据库表的CREATE、ALTER、DROP语句生成。CREATE语句包括表字段、表分区、表分发键;ALTER语句包含字段、索引、分区、表索引、列属性;DROP语句包含表名。所述DML生成包含SELECT、UPDATE、INSERT、DELETE生成;SELECT生成包含SELECT LIST、FROM及CONDITION生成;所述SELECT生成包含子查询和函数,所述FROM生成包含子查询和关联表,所述CONDITION生成包含子查询;The generation of SQL statements in this embodiment includes the generation of DDL and DML, and the generation of DDL includes the generation of CREATE, ALTER, and DROP statements of distributed database tables. The CREATE statement includes table fields, table partitions, and table distribution keys; the ALTER statement includes fields, indexes, partitions, table indexes, and column attributes; the DROP statement includes table names. The DML generation includes SELECT, UPDATE, INSERT, DELETE generation; SELECT generation includes SELECT LIST, FROM and CONDITION generation; the SELECT generation includes subqueries and functions, the FROM generation includes subqueries and associated tables, and the CONDITION generation contains subqueries;
若SQL语句为SELECT语句,图3是根据本实施例的SELECT语句的生成方法的流程图,如图3所示,包括如下步骤:If the SQL statement is a SELECT statement, Fig. 3 is a flow chart of the generation method of the SELECT statement according to the present embodiment, as shown in Fig. 3, comprising the following steps:
步骤S301,获取SQL复杂度因子,控制SQL复杂度,SQL生成器根据复杂度因子从参数字典中获取SQL基本元素,生成SELECT语句(对应上述的第一SELECT语句,SELECT语句构成:SELECT SELECT_expr FROM tab_reference CONDITION);Step S301, obtain the SQL complexity factor, control the SQL complexity, the SQL generator obtains the SQL basic elements from the parameter dictionary according to the complexity factor, and generates a SELECT statement (corresponding to the first SELECT statement above, and the SELECT statement is composed of: SELECT SELECT_expr FROM tab_reference CONDITION);
步骤S302,根据表结构生成SELECT语句的SELECT LIST,SELECT LIST为表达式SELECT_expr的组成部分,根据复杂度因子结合从参数字典中获取的语法规则随机生成字段值、若干函数,若选取的SELECT LIST含有嵌套子查询,则嵌套执行SELECT生成,嵌套层数由复杂度因子确定,经过组合确定SELECT LIST结构,包括:列名、函数、子查询;Step S302, generate the SELECT LIST of the SELECT statement according to the table structure, the SELECT LIST is a component of the expression SELECT_expr, randomly generate field values and several functions according to the complexity factor combined with the grammatical rules obtained from the parameter dictionary, if the selected SELECT LIST contains For nested subquery, nested SELECT is generated. The number of nesting layers is determined by the complexity factor. After combination, the SELECT LIST structure is determined, including: column name, function, and subquery;
步骤S303,确定SELECT语句的FROM,执行FROM生成,由SQL复杂度因子确定FROM组成结构,FROM中的表tab_reference包括物理表或基于查询结果的表(虚拟的表),若为物理表,获取物理表的表名,物理表的表名生成FROM;若FROM含有基于查询结果的表,则FROM涉及子查询,则调用步骤S301,生成SELECT语句构成的FROM,将执行SELECT语句的SELECT查询结果当作FROM的tab_reference;若确定FROM包含表与表之间的关联,则从CREATE生成模块中获取关联表信息,并调用步骤S301的,生成基于关联表的SELECT语句,生成SELECT语句构成的FROM;Step S303, determine the FROM of the SELECT statement, execute FROM generation, determine the FROM composition structure by the SQL complexity factor, the table tab_reference in the FROM includes a physical table or a table (virtual table) based on the query result, if it is a physical table, obtain the physical table The table name of the table and the table name of the physical table generate FROM; if FROM contains a table based on the query result, FROM involves a subquery, then call step S301 to generate a FROM composed of a SELECT statement, and use the SELECT query result of the executed SELECT statement as The tab_reference of FROM; if it is determined that FROM includes the association between tables, then obtain the association table information from the CREATE generation module, and call step S301, generate a SELECT statement based on the association table, and generate a FROM formed by the SELECT statement;
步骤S304,根据复杂度因子确定SQL语句的CONDITION,其中,所述SQL条件包括逻辑表达式,执行CONDITION生成,SQL条件由复杂度因子和步骤S301确定,CONDITION包括逻辑表达式,表达式中的条件由SELECT语句构成或者具体值构成,其中,具体值是根据参数字典中的字段范围直接生成的;Step S304, determine the CONDITION of the SQL statement according to the complexity factor, wherein the SQL condition includes a logical expression, execute CONDITION generation, the SQL condition is determined by the complexity factor and step S301, the CONDITION includes a logical expression, and the condition in the expression Consists of a SELECT statement or a specific value, where the specific value is directly generated according to the field range in the parameter dictionary;
步骤S305,根据步骤S302生成的SELECT语句的、步骤S303确定的FROM以及步骤S304生成的CONDITION生成所有查询语句构成,并将所有语句块嵌套拼接成一条完整的SQL查询语句(对应上述第二SELECT语句)输出。Step S305, generate all query statements according to the SELECT statement generated in step S302, the FROM determined in step S303, and the CONDITION generated in step S304, and all statement blocks are nested and spliced into a complete SQL query statement (corresponding to the second SELECT above statement) output.
根据本公开的另一个实施例,提供了一种分布式数据库检测装置,图4是根据本实施例的分布式数据库检测装置的框图,如图4所示,包括:According to another embodiment of the present disclosure, a distributed database detection device is provided. FIG. 4 is a block diagram of a distributed database detection device according to this embodiment. As shown in FIG. 4 , it includes:
获取模块42,设置为获取SQL的复杂度因子;Obtaining module 42, configured to obtain the complexity factor of SQL;
构造模块44,设置为根据所述复杂度因子构造表结构;A construction module 44, configured to construct a table structure according to the complexity factor;
生成模块46,设置为根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;The generation module 46 is configured to obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
检测模块48,设置为根据所述表结构与所述SQL语句对分布式数据库进行检测。The detection module 48 is configured to detect the distributed database according to the table structure and the SQL statement.
图5是根据本优选实施例的分布式数据库检测装置的框图一,如图5所示,所述构造模块44包括:Fig. 5 is a block diagram one of a distributed database detection device according to this preferred embodiment. As shown in Fig. 5, the construction module 44 includes:
第一获取子模块52,设置为从参数字典表中获取字段、字段类型、字段长度、分发策略以及分区策略;The first obtaining submodule 52 is configured to obtain fields, field types, field lengths, distribution strategies and partition strategies from the parameter dictionary table;
组合子模块54,设置为将所述字段、所述字段类型、所述字段长度、所述分发策略以及分区策略进行组合,得到组合结果;The combination submodule 54 is configured to combine the field, the field type, the field length, the distribution strategy and the partition strategy to obtain a combination result;
构建子模块56,设置为根据所述组合构建所述分布式数据库的表结构与异构数据库的表结构。The construction sub-module 56 is configured to construct the table structure of the distributed database and the table structure of the heterogeneous database according to the combination.
图6是根据本优选实施例的分布式数据库检测装置的框图二,如图6所示,所述检测模块48包括:Fig. 6 is a block diagram two of a distributed database detection device according to this preferred embodiment. As shown in Fig. 6, the detection module 48 includes:
注入子模块62,设置为将所述分布式数据库的表结构与所述SQL语句注入分布式数据库,同时将所述异构数据库的表结构与所述SQL语句所述异构数据库中,并生成所述分布式数据库的第一结果文件与所述异构数据库的第二结果文件;The injection sub-module 62 is configured to inject the table structure of the distributed database and the SQL statement into the distributed database, and simultaneously inject the table structure of the heterogeneous database and the SQL statement into the heterogeneous database, and generate The first result file of the distributed database and the second result file of the heterogeneous database;
对比子模块64,设置为将所述第一结果文件与所述第二结果文件进行对比,得到对比结果;The comparison submodule 64 is configured to compare the first result file with the second result file to obtain a comparison result;
第一确定子模块66,设置为若所述对比结果为所述第一结果文件与所述第二结果文件相同,确定所述分布式数据库正常;The first determination sub-module 66 is configured to determine that the distributed database is normal if the comparison result is that the first result file is the same as the second result file;
第二确定子模块68,设置为若所述对比结果为所述第一结果文件与所述第二结果文件不同,确定所述分布式数据库异常。The second determination sub-module 68 is configured to determine that the distributed database is abnormal if the comparison result is that the first result file is different from the second result file.
图7是根据本优选实施例的分布式数据库检测装置的框图三,如图7所示,所述生成模块46包括:Fig. 7 is a block diagram three of a distributed database detection device according to this preferred embodiment, as shown in Fig. 7, the generating module 46 includes:
第二获取子模块72,设置为从所述参数字典中获取函数、语法规则、语法限制条件以及字段范围,其中,所述基本元素包括所述函数、所述语法规则、所述语法限制条件以及所述字段范围;The second acquiring submodule 72 is configured to acquire functions, grammar rules, grammar constraints, and field ranges from the parameter dictionary, wherein the basic elements include the functions, the grammar rules, the grammar constraints, and the field range;
生成子模块74,设置为根据所述复杂度因子、所述表结构、所述函数、所述语法规则、所述语法限制条件以及所述字段范围生成所述SQL语句。The generating submodule 74 is configured to generate the SQL statement according to the complexity factor, the table structure, the function, the grammatical rule, the grammatical restriction and the field range.
在一实施例中,所述生成子模块74,还设置为:In one embodiment, the generating submodule 74 is further configured to:
若所述SQL语句为SELECT语句,根据所述基本元素生成第一SELECT语句;根据所述表结构与所述复杂度因子生成所述SELECT语句的SELECT LIST,其中,所述SELECT LIST为所述SELECT语句的表达式SELECT_expr的组成部分;根据所述第一SELECT语句确定所述SELECT语句的FROM,根据所述复杂度因子确定所述SELECT语句的CONDITION;根据所述SELECT语句的语法规则生成所述SELECT语句,所述SELECT语句的所述语法规则为SELECT SELECT_expr FROM tab_reference CONDITION。If the SQL statement is a SELECT statement, generate the first SELECT statement according to the basic elements; generate the SELECT LIST of the SELECT statement according to the table structure and the complexity factor, wherein the SELECT LIST is the SELECT A component of the expression SELECT_expr of the statement; determine the FROM of the SELECT statement according to the first SELECT statement, determine the CONDITION of the SELECT statement according to the complexity factor; generate the SELECT according to the grammatical rules of the SELECT statement statement, the grammatical rule of the SELECT statement is SELECT SELECT_expr FROM tab_reference CONDITION.
若所述SQL语句为INSERT语句,根据所述复杂度因子确定INSERT语句包含的VALUE的构成,若VALUES value_list由具体值构成,根据所述表结构中字段的数据类型取值范围确定所述VALUES value_list;若VALUES value_list由SELECT查询结果确定,生成SELECT语句构成所述VALUES value_list;根据所述表结构确定tbl_name;根据INSERT语句的语法规则生成所述INSERT语句,其中,INSERT语句的语法规则为:INSERT INTO tbl_name VALUES value_list;If the SQL statement is an INSERT statement, determine the composition of the VALUE contained in the INSERT statement according to the complexity factor, if the VALUES value_list is composed of specific values, determine the VALUES value_list according to the data type value range of the field in the table structure If the VALUES value_list is determined by the SELECT query result, generate the SELECT statement to form the VALUES value_list; determine the tbl_name according to the table structure; generate the INSERT statement according to the grammatical rules of the INSERT statement, wherein the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list;
若所述SQL语句为UPDATE语句,根据所述表结构确定UPDATE语句的assignment_list,其中,assignment_list对应的VALUE由具体值或者由select语句查询结果构成;确定UPDATE语句的FROM与CONDITION,根据所述UPDATE语句的语法规则生成所述UPDATE语句,所述UPDATE语句的语法规则为:update tbl_name set assignment_list where condition;If the SQL statement is an UPDATE statement, determine the assignment_list of the UPDATE statement according to the table structure, wherein the VALUE corresponding to the assignment_list is composed of a specific value or a query result of a select statement; determine the FROM and CONDITION of the UPDATE statement, and according to the UPDATE statement The grammatical rules of the UPDATE statement are generated, and the grammatical rules of the UPDATE statement are: update tbl_name set assignment_list where condition;
若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
若所述SQL语句为ALTER语句,根据所述表结构确定所述ALTER语句的tbl_name;根据所述复杂度因子确定所述ALTER语句的alter_option,根据所述ALTER语句的语法规则生成所述ALTER语句,其中,ALTER语句的语法规则为ALTER TABLE tbl_name alter_option;If the SQL statement is an ALTER statement, determine the tbl_name of the ALTER statement according to the table structure; determine the alter_option of the ALTER statement according to the complexity factor, generate the ALTER statement according to the grammatical rules of the ALTER statement, Among them, the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option;
若所述SQL语句为DROP语句,从所述表结构中获取表名,根据DROP语句的语法规则将所述表名替换tbl_name,生成所述DROP语句,其中,所述DROP语句的语法规则为drop table tbl_name。If the SQL statement is a DROP statement, obtain the table name from the table structure, replace the table name with tbl_name according to the grammatical rules of the DROP statement, and generate the DROP statement, wherein the grammatical rule of the DROP statement is drop table tbl_name.
在一实施例中,所述生成子模块74,还设置为:In one embodiment, the generating submodule 74 is further configured to:
若从所述表结构中选取的SELECT LIST包含嵌套子查询,根据所述复杂度因子确定嵌套层数;If the SELECT LIST selected from the table structure includes nested subqueries, the number of nested layers is determined according to the complexity factor;
根据所述嵌套层数执行SELECT嵌套,直到不包含所述嵌套子查询,组合得到所述SELECT LIST。SELECT nesting is performed according to the number of nesting layers until the nested sub-queries are not included, and the SELECT LIST is obtained through combination.
在一实施例中,所述生成子模块74,还设置为:In one embodiment, the generating submodule 74 is further configured to:
根据所述SQL复杂度因子确定所述FROM的组成结构;Determine the composition structure of the FROM according to the SQL complexity factor;
若所述FROM中的tab_reference为物理表,获取物理表的表名,根据物理表的表名生成所述FROM;If the tab_reference in the FROM is a physical table, obtain the table name of the physical table, and generate the FROM according to the table name of the physical table;
若FROM中的tab_reference为基于查询结果的表,在确定所述FROM涉及子查询的情况下,生成所述第一SELECT语句构成的所述FROM,将执行所述第一SELECT语句的SELECT查询结果作为所述FROM的tab_reference;在确定所述FROM包含表与表之间的关联的情况下,获取关联表信息,生成基于关联表的第二SELECT语句,生成所述第二SELECT语句构成的所述FROM。If the tab_reference in the FROM is a table based on query results, when it is determined that the FROM involves a subquery, generate the FROM composed of the first SELECT statement, and use the SELECT query result of executing the first SELECT statement as The tab_reference of the FROM; when it is determined that the FROM includes a table-to-table association, obtain the association table information, generate a second SELECT statement based on the association table, and generate the FROM formed by the second SELECT statement .
本公开的实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述任一项方法实施例中的步骤。Embodiments of the present disclosure also provide a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps in any one of the above method embodiments when running.
在一个示例性实施例中,上述计算机可读存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、移动硬盘、磁碟或者光盘等各种可以存储计算机程序的介质。In an exemplary embodiment, the above-mentioned computer-readable storage medium may include but not limited to: U disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM) , mobile hard disk, magnetic disk or optical disk and other media that can store computer programs.
本公开的实施例还提供了一种电子装置,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。Embodiments of the present disclosure also provide an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
在一个示例性实施例中,上述电子装置还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。In an exemplary embodiment, the electronic device may further include a transmission device and an input and output device, wherein the transmission device is connected to the processor, and the input and output device is connected to the processor.
本实施例中的具体示例可以参考上述实施例及示例性实施方式中所描述的示例,本实施例在此不再赘述。For specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and exemplary implementation manners, and details will not be repeated here in this embodiment.
显然,本领域的技术人员应该明白,上述的本公开的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路 模块来实现。这样,本公开不限制于任何特定的硬件和软件结合。Obviously, those skilled in the art should understand that each module or each step of the above-mentioned disclosure can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network composed of multiple computing devices In fact, they can be implemented in program code executable by a computing device, and thus, they can be stored in a storage device to be executed by a computing device, and in some cases, can be executed in an order different from that shown here. Or described steps, or they are fabricated into individual integrated circuit modules, or multiple modules or steps among them are fabricated into a single integrated circuit module for implementation. As such, the present disclosure is not limited to any specific combination of hardware and software.
以上所述仅为本公开的优选实施例而已,并不用于限制本公开,对于本领域的技术人员来说,本公开可以有各种更改和变化。凡在本公开的原则之内,所作的任何修改、等同替换、改进等,均应包含在本公开的保护范围之内。The above descriptions are only preferred embodiments of the present disclosure, and are not intended to limit the present disclosure. For those skilled in the art, the present disclosure may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims (10)

  1. 一种分布式数据库检测方法,包括:A distributed database detection method, comprising:
    获取结构化查询语句SQL的复杂度因子;Obtain the complexity factor of the structured query statement SQL;
    根据所述复杂度因子构造表结构;Constructing a table structure according to the complexity factor;
    根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句;Obtain the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generate an SQL statement according to the table structure and the basic elements;
    根据所述表结构与所述SQL语句对分布式数据库进行检测。The distributed database is detected according to the table structure and the SQL statement.
  2. 根据权利要求1所述的方法,其中,根据所述复杂度因子构造表结构包括:The method according to claim 1, wherein constructing a table structure according to the complexity factor comprises:
    从参数字典表中获取字段、字段类型、字段长度、分发策略以及分区策略;Obtain the field, field type, field length, distribution strategy and partition strategy from the parameter dictionary table;
    将所述字段、所述字段类型、所述字段长度、所述分发策略以及分区策略进行组合,得到组合结果;Combining the field, the field type, the field length, the distribution strategy and the partition strategy to obtain a combination result;
    根据所述组合构建所述分布式数据库的表结构与异构数据库的表结构。The table structure of the distributed database and the table structure of the heterogeneous database are constructed according to the combination.
  3. 根据权利要求2所述的方法,其中,根据所述表结构与所述SQL语句对分布式数据库进行检测包括:The method according to claim 2, wherein detecting the distributed database according to the table structure and the SQL statement comprises:
    将所述分布式数据库的表结构与所述SQL语句注入分布式数据库,同时将所述异构数据库的表结构与所述SQL语句所述异构数据库中,并生成所述分布式数据库的第一结果文件与所述异构数据库的第二结果文件;Inject the table structure of the distributed database and the SQL statement into the distributed database, and at the same time inject the table structure of the heterogeneous database and the SQL statement into the heterogeneous database, and generate the first a result file and a second result file of the heterogeneous database;
    将所述第一结果文件与所述第二结果文件进行对比,得到对比结果;comparing the first result file with the second result file to obtain a comparison result;
    若所述对比结果为所述第一结果文件与所述第二结果文件相同,确定所述分布式数据库正常;If the comparison result is that the first result file is the same as the second result file, it is determined that the distributed database is normal;
    若所述对比结果为所述第一结果文件与所述第二结果文件不同,确定所述分布式数据库异常。If the comparison result is that the first result file is different from the second result file, it is determined that the distributed database is abnormal.
  4. 根据权利要求1所述的方法,其中,根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据所述表结构与所述基本元素生成SQL语句包括:The method according to claim 1, wherein obtaining the basic elements of the SQL from the parameter dictionary according to the complexity factor, and generating the SQL statement according to the table structure and the basic elements comprises:
    从所述参数字典中获取函数、语法规则、语法限制条件以及字段范围,其中,所述基本元素包括所述函数、所述语法规则、所述语法限制条件以及所述字段范围;Acquiring functions, grammar rules, grammar constraints, and field ranges from the parameter dictionary, wherein the basic elements include the functions, the grammar rules, the grammar constraints, and the field ranges;
    根据所述复杂度因子、所述表结构、所述函数、所述语法规则、所述语法限制条件以及所述字段范围生成所述SQL语句。The SQL statement is generated according to the complexity factor, the table structure, the function, the grammatical rule, the grammatical restriction condition and the field range.
  5. 根据权利要求4所述的方法,其中,根据所述复杂度因子、所述表结构、所述函数、所述语法规则、所述语法限制条件以及所述字段范围生成所述SQL语句包括:The method according to claim 4, wherein generating the SQL statement according to the complexity factor, the table structure, the function, the grammatical rule, the grammatical restriction and the field range comprises:
    若所述SQL语句为SELECT语句,根据所述基本元素生成第一SELECT语句;根据所述表结构与所述复杂度因子生成所述SELECT语句的SELECT LIST,其中,所述SELECT LIST为所述SELECT语句的表达式SELECT_expr的组成部分;根据所述第一SELECT语句确定所述SELECT语句的FROM,根据所述复杂度因子确定所述SELECT语句的CONDITION;根据所述SELECT语句的语法规则生成所述SELECT语句,所述SELECT语句的所述语法规则为SELECT SELECT_expr FROM tab_reference CONDITION;If the SQL statement is a SELECT statement, generate the first SELECT statement according to the basic elements; generate the SELECT LIST of the SELECT statement according to the table structure and the complexity factor, wherein the SELECT LIST is the SELECT A component of the expression SELECT_expr of the statement; determine the FROM of the SELECT statement according to the first SELECT statement, determine the CONDITION of the SELECT statement according to the complexity factor; generate the SELECT according to the grammatical rules of the SELECT statement statement, the grammatical rule of the SELECT statement is SELECT SELECT_expr FROM tab_reference CONDITION;
    若所述SQL语句为INSERT语句,根据所述复杂度因子确定INSERT语句包含的VALUE的构成,若VALUES value_list由具体值构成,根据所述表结构中字段的数据类型取值范围确 定所述VALUES value_list;若VALUES value_list由SELECT查询结果确定,生成SELECT语句构成所述VALUES value_list;根据所述表结构确定tbl_name;根据INSERT语句的语法规则生成所述INSERT语句,其中,INSERT语句的语法规则为:INSERT INTO tbl_name VALUES value_list;If the SQL statement is an INSERT statement, determine the composition of the VALUE contained in the INSERT statement according to the complexity factor, if the VALUES value_list is composed of specific values, determine the VALUES value_list according to the data type value range of the field in the table structure If the VALUES value_list is determined by the SELECT query result, generate the SELECT statement to form the VALUES value_list; determine the tbl_name according to the table structure; generate the INSERT statement according to the grammatical rules of the INSERT statement, wherein the grammatical rule of the INSERT statement is: INSERT INTO tbl_name VALUES value_list;
    若所述SQL语句为UPDATE语句,根据所述表结构确定UPDATE语句的assignment_list,其中,assignment_list对应的VALUE由具体值或者由select语句查询结果构成;确定UPDATE语句的FROM与CONDITION,根据所述UPDATE语句的语法规则生成所述UPDATE语句,所述UPDATE语句的语法规则为:update tbl_name set assignment_list where condition;If the SQL statement is an UPDATE statement, determine the assignment_list of the UPDATE statement according to the table structure, wherein the VALUE corresponding to the assignment_list is composed of a specific value or a query result of a select statement; determine the FROM and CONDITION of the UPDATE statement, and according to the UPDATE statement The grammatical rules of the UPDATE statement are generated, and the grammatical rules of the UPDATE statement are: update tbl_name set assignment_list where condition;
    若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
    若所述SQL语句为DELETE语句,根据所述表结构确定tbl_name,确定DELETE语句的FROM与CONDITION,根据所述DELETE语句的语法规则生成所述DELETE语句,其中,所述DELETE语句的语法规则为:DELETE FROM tbl_name where CONDITION;If the SQL statement is a DELETE statement, determine tbl_name according to the table structure, determine the FROM and CONDITION of the DELETE statement, and generate the DELETE statement according to the grammatical rules of the DELETE statement, wherein the grammatical rules of the DELETE statement are: DELETE FROM tbl_name where CONDITION;
    若所述SQL语句为ALTER语句,根据所述表结构确定所述ALTER语句的tbl_name;根据所述复杂度因子确定所述ALTER语句的alter_option,根据所述ALTER语句的语法规则生成所述ALTER语句,其中,ALTER语句的语法规则为ALTER TABLE tbl_name alter_option;If the SQL statement is an ALTER statement, determine the tbl_name of the ALTER statement according to the table structure; determine the alter_option of the ALTER statement according to the complexity factor, generate the ALTER statement according to the grammatical rules of the ALTER statement, Among them, the grammatical rule of the ALTER statement is ALTER TABLE tbl_name alter_option;
    若所述SQL语句为DROP语句,从所述表结构中获取表名,根据DROP语句的语法规则将所述表名替换tbl_name,生成所述DROP语句,其中,所述DROP语句的语法规则为drop table tbl_name。If the SQL statement is a DROP statement, obtain the table name from the table structure, replace the table name with tbl_name according to the grammatical rules of the DROP statement, and generate the DROP statement, wherein the grammatical rule of the DROP statement is drop table tbl_name.
  6. 根据权利要求5所述的方法,其中,根据所述表结构与所述复杂度因子生成所述SELECT语句的SELECT LIST包括:The method according to claim 5, wherein, generating the SELECT LIST of the SELECT statement according to the table structure and the complexity factor comprises:
    若从所述表结构中选取的SELECT LIST包含嵌套子查询,根据所述复杂度因子确定嵌套层数;If the SELECT LIST selected from the table structure includes nested subqueries, the number of nested layers is determined according to the complexity factor;
    根据所述嵌套层数执行SELECT嵌套,直到不包含所述嵌套子查询,组合得到所述SELECT LIST。SELECT nesting is performed according to the number of nesting layers until the nested sub-queries are not included, and the SELECT LIST is obtained through combination.
  7. 根据权利要求5所述的方法,其中,根据所述第一SELECT语句确定所述SELECT语句的FROM包括:The method according to claim 5, wherein determining the FROM of the SELECT statement according to the first SELECT statement comprises:
    根据所述SQL复杂度因子确定所述FROM的组成结构;Determine the composition structure of the FROM according to the SQL complexity factor;
    若所述FROM中的tab_reference为物理表,获取物理表的表名,根据物理表的表名生成所述FROM;If the tab_reference in the FROM is a physical table, obtain the table name of the physical table, and generate the FROM according to the table name of the physical table;
    若FROM中的tab_reference为基于查询结果的表,在确定所述FROM涉及子查询的情况下,生成所述第一SELECT语句构成的所述FROM,将执行所述第一SELECT语句作为所述FROM的tab_reference;在确定所述FROM包含表与表之间的关联的情况下,获取关联表信息,生成基于关联表的第二SELECT语句,生成所述第二SELECT语句构成的所述FROM。If the tab_reference in FROM is a table based on query results, in the case that it is determined that the FROM involves a subquery, generate the FROM composed of the first SELECT statement, and execute the first SELECT statement as the FROM tab_reference; if it is determined that the FROM includes an association between tables, obtain association table information, generate a second SELECT statement based on the association table, and generate the FROM formed by the second SELECT statement.
  8. 一种分布式数据库检测装置,包括:A distributed database detection device, comprising:
    获取模块,设置为获取结构化查询语句SQL的复杂度因子;The acquisition module is set to acquire the complexity factor of structured query statement SQL;
    构造模块,设置为根据所述复杂度因子构造表结构;A construction module, configured to construct a table structure according to the complexity factor;
    生成模块,设置为根据所述复杂度因子从参数字典中获取所述SQL的基本元素,并根据 所述表结构与所述基本元素生成SQL语句;Generate module, be arranged to obtain the basic element of described SQL from parameter dictionary according to described complexity factor, and generate SQL statement according to described table structure and described basic element;
    检测模块,设置为根据所述表结构与所述SQL语句对分布式数据库进行检测。The detection module is configured to detect the distributed database according to the table structure and the SQL statement.
  9. 一种计算机可读的存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行所述权利要求1至7任一项中所述的方法。A computer-readable storage medium, wherein a computer program is stored in the storage medium, wherein the computer program is configured to perform the method described in any one of claims 1 to 7 when running.
  10. 一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行所述权利要求1至7任一项中所述的方法。An electronic device, comprising a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to perform the method described in any one of claims 1 to 7.
PCT/CN2022/116588 2021-09-02 2022-09-01 Distributed database detection method and apparatus WO2023030461A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111028813.8A CN115757083A (en) 2021-09-02 2021-09-02 Distributed database detection method and device
CN202111028813.8 2021-09-02

Publications (1)

Publication Number Publication Date
WO2023030461A1 true WO2023030461A1 (en) 2023-03-09

Family

ID=85332342

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/116588 WO2023030461A1 (en) 2021-09-02 2022-09-01 Distributed database detection method and apparatus

Country Status (2)

Country Link
CN (1) CN115757083A (en)
WO (1) WO2023030461A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117648326A (en) * 2024-01-29 2024-03-05 中邮消费金融有限公司 Dynamic sub-table method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007249531A (en) * 2006-03-15 2007-09-27 Hitachi Software Eng Co Ltd Table structure determination and notification system
CN103810171A (en) * 2012-11-06 2014-05-21 深圳市金蝶中间件有限公司 Method and system for generating random test data within limited range
CN109271326A (en) * 2018-11-28 2019-01-25 优刻得科技股份有限公司 Test method and its device, the equipment and storage medium of cloud database
CN109614315A (en) * 2018-11-06 2019-04-12 武汉达梦数据库有限公司 A kind of automatic generation method and system of data synchronism detection use-case

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2007249531A (en) * 2006-03-15 2007-09-27 Hitachi Software Eng Co Ltd Table structure determination and notification system
CN103810171A (en) * 2012-11-06 2014-05-21 深圳市金蝶中间件有限公司 Method and system for generating random test data within limited range
CN109614315A (en) * 2018-11-06 2019-04-12 武汉达梦数据库有限公司 A kind of automatic generation method and system of data synchronism detection use-case
CN109271326A (en) * 2018-11-28 2019-01-25 优刻得科技股份有限公司 Test method and its device, the equipment and storage medium of cloud database

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117648326A (en) * 2024-01-29 2024-03-05 中邮消费金融有限公司 Dynamic sub-table method, device, equipment and storage medium
CN117648326B (en) * 2024-01-29 2024-05-10 中邮消费金融有限公司 Dynamic sub-table method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN115757083A (en) 2023-03-07

Similar Documents

Publication Publication Date Title
US10659467B1 (en) Distributed storage and distributed processing query statement reconstruction in accordance with a policy
US20170147644A1 (en) Query optimization using join cardinality
CN112559554B (en) Query statement optimization method and device
US8700605B1 (en) Estimating rows returned by recursive queries using fanout
CN100550019C (en) OODB Object Oriented Data Base access method and system
US9286393B2 (en) Performing a function on rows of data determined from transitive relationships between columns
US11556534B2 (en) Subquery predicate generation to reduce processing in a multi-table join
US9892143B2 (en) Association index linking child and parent tables
US8812492B2 (en) Automatic and dynamic design of cache groups
CN105320681B (en) Database content merging method and device
US20130198218A1 (en) Database Table Partitioning Allowing Overlaps Used in Full Text Query
US20130151561A1 (en) Fuzzy full text search
EP3012747B1 (en) Tcam-based table query processing method and apparatus
WO2023030461A1 (en) Distributed database detection method and apparatus
US10324933B2 (en) Technique for processing query in database management system
CN108549666B (en) Data table sorting method, device, equipment and storage medium
CN116341007A (en) Data query method, system, equipment and storage medium
CN112416966A (en) Ad hoc query method, apparatus, computer device and storage medium
US12079179B2 (en) Systems, methods, and media for accessing derivative properties from a post relational database utilizing a logical schema instruction that includes a base object identifier
CN116126865B (en) Proxy method and device for mixed use of multiple databases
CA2885244A1 (en) Leapfrog tree-join
WO2024032820A1 (en) Data processing method and apparatus, and computer device and storage medium
CN117609303A (en) Multi-table joint query method, device, equipment and storage medium
KR102216886B1 (en) Apparatus for Processing Query by Using Dynamic Schema and Computer-Readable Recording Medium with Program therefor
CN118193526A (en) Method and device for generating sql by index

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22863595

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 22863595

Country of ref document: EP

Kind code of ref document: A1