Query sample generation method and device, electronic equipment and medium

By searching the target data table in the target database and generating query samples using a binary search algorithm, the resource consumption problem of the log method in the existing technology is solved, and efficient query sample generation is achieved, improving the availability of samples and reducing time complexity.

CN121542327APending Publication Date: 2026-02-17CHINA CONSTRUCTION BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511624762.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-07
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing technologies that obtain SQL query samples by parsing database logs require enabling log parameters, which consumes system resources and has low availability of query samples, especially when applied across databases.

Method used

By fully searching and extracting target parameter values ​​from the target data table in the target database, and generating query samples using a preset binary search algorithm, query samples are generated directly from the target database without setting database parameters.

Benefits of technology

It reduces system resource consumption, improves the availability of query samples, and significantly reduces the number of queries and time complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121542327A_ABST
    Figure CN121542327A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a query sample generation method and device, electronic equipment and a medium, and relates to the technical field of databases, one specific implementation mode of the method comprises the steps that the total data size corresponding to a target data table in an original query statement is obtained, and the target data table is stored in a target database; segmenting the target data table based on the total data volume corresponding to the target data table and a preset segmentation data volume to obtain at least one segmentation table corresponding to the target data table; based on a preset binary query algorithm, parameter query is conducted on the first segment table, a first target parameter value is obtained, a first query sample of the target database is generated according to the first target parameter value, and the first segment table is any segment table in the at least one segment table. In the process, database parameters do not need to be set, and the corresponding query sample is directly generated for the target database, so that occupation of system operation resources can be avoided, and the availability of the query sample can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, specifically to a query sample generation method, apparatus, electronic device, and medium. Background Technology

[0002] In the development and maintenance of software systems, database stress testing is a crucial step in evaluating system performance, stability, and load-bearing capacity. One of the core preparatory tasks for database stress testing is to prepare a large number of Structured Query Language (SQL) query statements that can retrieve valid data as test samples.

[0003] Currently, the main method for automating the acquisition of SQL query samples is through logs. This involves parsing the SQL execution logs recorded during database operation, filtering out previously executed SQL statements from the logs, and using these as query samples for testing the current database.

[0004] However, obtaining query samples through logs requires setting the database to enable logging, and enabling logging consumes certain system resources. If the query samples extracted from the logs are used in other databases with the same structure, it will result in low availability of the query samples. Summary of the Invention

[0005] This application provides a query sample generation method, apparatus, electronic device, and medium to solve the problems in related technologies. By directly searching and extracting target parameter values ​​from the target data table of the target database based on the original query statement, query samples are generated according to the target parameter values. This process does not require setting database parameters, effectively reducing the occupation of system operating resources, and directly generating the corresponding query samples for the target database, which can effectively improve the usability of query samples.

[0006] In a first aspect, embodiments of this application provide a query sample generation method, which includes: obtaining the total data volume corresponding to a target data table in an original query statement, wherein the target data table is stored in a target database; segmenting the target data table based on the total data volume corresponding to the target data table and a preset segmented data volume to obtain at least one segmented table corresponding to the target data table; performing a parameter query on the first segmented table based on a preset binary search algorithm to obtain a first target parameter value, thereby generating a first query sample of the target database based on the first target parameter value, wherein the first segmented table is any segmented table among at least one segmented table.

[0007] In some embodiments, obtaining the total amount of data corresponding to the target data table in the original query statement includes: using a preset parsing tool to obtain the target query conditions in the original query statement, the target query conditions including target field names; obtaining the table name of the target data table based on the target field names; and obtaining the total amount of data corresponding to the target data table based on the table name of the target data table.

[0008] In some embodiments, segmenting the target data table based on the total data volume and the preset segmented data volume to obtain at least one segmented table corresponding to the target data table includes: sorting each data item in the target data table based on the total data volume to obtain a sorted target data table; and segmenting the sorted target data table based on the preset segmented data volume to obtain at least one segmented table corresponding to the sorted data table.

[0009] In some embodiments, performing parameter queries on a first segmented table based on a preset binary search algorithm to obtain a first target parameter value includes: performing a binary search on the first segmented table based on the preset binary search algorithm to obtain at least one sub-segmented table; querying the number of target parameters in the first sub-segmented table that satisfy the query conditions in the segmented query statement based on the segmented query statement of the first sub-segmented table, wherein the first sub-segmented table is any one of the at least one sub-segmented table, and the segmented query statement is obtained by adjusting the original query statement based on the first sub-segmented table; determining the data volume of the first sub-segmented table if the number of target parameters is greater than a first preset value; determining the data position of the target parameter in the first sub-segmented table if the data volume of the first sub-segmented table is a second preset value; and obtaining the first target parameter value based on the data position of the target parameter and the segmented field name in the segmented query statement.

[0010] In some embodiments, generating a first query sample of the target database based on a first target parameter value includes: assigning a value to the original query statement using the first target parameter value to obtain the first query sample.

[0011] In some embodiments, a first query sample of a target database is generated based on a first target parameter value. Then, the method includes: in response to a query statement execution instruction, executing the first query sample in the target database to obtain an execution result; if the execution result satisfies a preset query result, saving the first query sample to a sample set; and based on a preset binary search algorithm, obtaining a second target parameter value obtained after performing a parameter query on a second segment table, so as to generate a second query sample based on the second target parameter value, wherein the second segment table is any segment table other than the first segment table in at least one segment table.

[0012] Secondly, embodiments of this application provide a query sample generation apparatus, the apparatus comprising: The acquisition unit is used to acquire the total amount of data corresponding to the target data table in the original query statement. The target data table is stored in the target database. The segmentation unit is used to segment the target data table based on the total data volume and the preset segment data volume, so as to obtain at least one segmented table corresponding to the target data table. The generation unit is used to perform parameter query on the first segment table based on a preset binary search algorithm to obtain the first target parameter value, so as to generate the first query sample of the target database based on the first target parameter value. The first segment table is any segment table in at least one segment table.

[0013] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory for storing a computer program capable of running on the processor, wherein, when the processor runs the computer program, it performs the method described in any embodiment of the first aspect.

[0014] Fourthly, embodiments of this application provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to perform the methods described in any embodiment of the first aspect.

[0015] Fifthly, embodiments of this application provide a computer program product including a computer program that, when executed by a processor, performs the method described in any embodiment of the first aspect.

[0016] This application provides a query sample generation method. The method involves obtaining the total data volume of a target data table in the original query statement, where the target data table is stored in a target database. Based on the total data volume and a preset segmented data volume, the target data table is segmented to obtain at least one segmented table. A preset binary search algorithm is used to perform parameter queries on the first segmented table to obtain a first target parameter value. A first query sample for the target database is then generated based on this first target parameter value. The first segmented table can be any one of the at least one segmented table. This process eliminates the need to set database parameters, directly generating the corresponding query sample for the target database. This avoids consuming system resources and effectively improves the availability of the query sample. Furthermore, the segmentation and binary search methods significantly reduce the number of queries, effectively lowering the time complexity.

[0017] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0018] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are merely embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort, and this application can be applied to other similar scenarios based on the provided drawings.

[0019] Figure 1 This is a schematic diagram illustrating the structure of the first type of two-table joint query for target parameter values ​​provided in an embodiment of this application; Figure 2 This is a schematic diagram illustrating the structure of the second type of two-table joint query for target parameter values ​​provided in the embodiments of this application; Figure 3 A flowchart illustrating the first query sample generation method provided in this application embodiment; Figure 4 A flowchart illustrating the second query sample generation method provided in this application embodiment; Figure 5 A flowchart illustrating the third query sample generation method provided in this application embodiment; Figure 6 This is a schematic diagram of the structure of a binary search algorithm provided in an embodiment of this application; Figure 7 A schematic diagram of a search process provided in an embodiment of this application; Figure 8 A flowchart illustrating a query sample generation method provided in this application embodiment; Figure 9 This application provides an exemplary two-table binary search structure diagram. Figure 10 This application provides an exemplary structural diagram of a two-table binary search result. Figure 11 This is a schematic diagram of the structure of a query sample generation device provided in an embodiment of this application; Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0020] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. The described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0021] It should be noted that the terms "system," "device," "unit," and / or "module" used in this application are methods of distinguishing different components, elements, parts, sections, or assemblies at different levels. However, if other terms can achieve the same purpose, they can be replaced by other expressions.

[0022] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.

[0023] In the development and maintenance of software systems, database stress testing is a crucial step in evaluating system performance, stability, and load-bearing capacity. One of the core preparatory tasks for database stress testing is to prepare a large number of structured query language (SQL) queries that can retrieve valid data as test samples.

[0024] Currently, the main method for automating the acquisition of SQL query samples is through logs. This involves parsing the SQL execution logs recorded during database operation, filtering out previously executed SQL statements from the logs, and using these as query samples for testing the current database.

[0025] However, obtaining query samples through logs requires setting the database to enable logging, and enabling logging consumes certain system resources. If the query samples extracted from the logs are used in other databases with the same structure, it will result in low availability of the query samples.

[0026] To address the issue of log-based query methods consuming system resources, another approach to obtaining query samples involves directly searching and extracting target parameter values ​​from the target database. These target parameter values ​​are then assigned to the original query statement (a parameterized SQL query statement where parameters (such as question marks or natural number codes) are used in the target query conditions instead of hard-coded values ​​in the query). This yields the query samples needed for testing. The search typically involves traversing the entire data table to find the target parameter values ​​that satisfy the query conditions.

[0027] Specifically, taking a join query of two data tables as an example, such as Figure 1 As shown, Figure 1 This is a schematic diagram illustrating the structure of the first type of two-table joint query for target parameter values ​​provided in this application embodiment. (Refer to...) Figure 1The two tables are named A and B. For a join between tables A and B, the original query could be "select A.name, B.id from A, B where A.column1=? and B.column2=? and A.column3=B.column4". Generating the query sample involves replacing the "?" with the found target parameter value. The search for the target parameter value typically involves a Cartesian product traversal of the two tables. That is, fixing one record c in table A, iterating through each record in table B, and finding a record d in table B that satisfies the query condition with record c in table A, indicating that the target parameter value has been found. Figure 2 The diagram shows the structure of the target parameter value in the second type of two-table join query. Replacing "c" and "d" with the "?" in the original query statement yields a query sample, such as "select A.name,B.id from A, B where A.column1=c and B.column2=d and A.column3=B.column4". Continue this search process until the desired number of query samples are obtained.

[0028] As can be seen, for a join query of two tables, it is necessary to traverse both tables to check the existence of the target parameter value. Each check requires a data query operation, so the maximum number of queries is expected to be the amount of data in table A multiplied by the amount of data in table B. Obviously, this method has a high time complexity.

[0029] To address the aforementioned issues, this application proposes a query sample generation method. The method involves segmenting the target data table based on its total data volume and a preset number of segments. Then, a binary search approach is used to query the segmented tables for target parameter values, generating query samples based on these values. This process eliminates the need to set database parameters, directly generating corresponding query samples for the target database. This avoids consuming system resources and effectively improves the usability of the query samples. Furthermore, the segmentation and binary search methods significantly reduce the number of queries, effectively lowering time complexity.

[0030] The following section provides a detailed description of a query sample generation method provided in this application, with reference to the accompanying drawings.

[0031] Figure 3 A flowchart illustrating a query sample generation method provided in an embodiment of this application is shown. Figure 3 As shown, the query sample generation method includes steps 101-103.

[0032] Step 101: Obtain the total amount of data corresponding to the target data table in the original query statement. The target data table is stored in the target database.

[0033] In the embodiments of this application, the original query statement refers to the parameterized SQL query statement before the parameters are assigned values. It generally includes a parameterized query form containing a question mark or natural number encoding, such as `select * from A where a = ?`. The question mark represents the parameter to be assigned a value. MySQL databases generally use this syntax. For Oracle databases, parameters are generally expressed as a colon followed by a number, such as `select * from A where a = :1 and b = :2`.

[0034] It should be noted that this application can use different original query statements to query the target parameter values ​​for different databases, and no limitation is made here. This application uses a MySQL database as an example. In addition, the original query statement in this application can be a single table query or a join query of two or more tables, and is not limited in the embodiments of this application.

[0035] Specifically, this application can use the count function to count the total amount of data corresponding to the target data table, that is, to obtain the total number of data rows of the target data table by executing the select count operation based on the table name of the target data table.

[0036] Step 102: Based on the total amount of data corresponding to the target data table and the preset segmented data amount, the target data table is segmented to obtain at least one segmented table corresponding to the target data table.

[0037] In the embodiments of this application, the preset segmented data volume can be determined according to the total data volume of the target data table, and can be adjusted adaptively according to the actual situation. It is not limited in the embodiments of this application.

[0038] Specifically, for example, if the total amount of data in the target data table is 10,000 records, the preset segment data size can be set to 2,500 records, that is, the target data table is divided into 4 segments, each containing 2,500 records.

[0039] After dividing the target data table into multiple segment tables, a count query operation needs to be performed on each segment table to determine whether the target parameter value exists in each segment table. Only if the target parameter value exists in the current segment table (the return value after the count operation is greater than zero) will a binary search be performed on that segment table; otherwise, the query will proceed to the next segment table.

[0040] Step 103: Based on the preset binary search algorithm, perform parameter query on the first segment table to obtain the first target parameter value, so as to generate the first query sample of the target database according to the first target parameter value. The first segment table is any segment table in at least one segment table.

[0041] In the embodiments of this application, the preset binary search algorithm performs a recursive binary search operation on a segmented table containing the target parameter value. That is, the segmented table is first divided into two sub-segmented tables with the same amount of data. The target parameter value is then checked for each sub-segmented table. For the sub-segmented table with the target parameter, the binary search operation is continued until the divided sub-segmented table contains only one piece of data, which is the target parameter value.

[0042] Specifically, based on the segmented table containing the target parameter value obtained in step 102, a binary search operation is performed on it using a preset binary search algorithm to obtain two sub-segmented tables corresponding to the segmented table. First, a count query operation is performed on the first sub-segmented table to determine if the target parameter value exists. If it does, the binary search operation is repeated on the sub-segmented table until the location of a unique data record is found. Based on this data location, the corresponding target parameter value is obtained. Otherwise, the recursive binary search operation is performed on the second sub-segmented table. The target parameter value is then assigned to the target parameter (such as "?") in the original query statement to obtain a query sample.

[0043] In summary, the query sample generation method proposed in this application involves obtaining the total data volume corresponding to the target data table in the original query statement, with the target data table stored in the target database. Based on the total data volume and a preset segmented data volume, the target data table is segmented to obtain at least one segmented table corresponding to the target data table. A parameter query is performed on the first segmented table using a preset binary search algorithm to obtain a first target parameter value, which is then used to generate a first query sample for the target database. The first segmented table can be any one of the at least one segmented table. This process eliminates the need to set database parameters, directly generating the corresponding query sample for the target database. This avoids consuming system resources and effectively improves the availability of the query sample. Furthermore, the segmentation and binary search methods significantly reduce the number of queries, effectively lowering the time complexity.

[0044] As one possible implementation method, Figure 4 A flowchart of a second query sample generation method provided in an embodiment of this application is shown. Figure 4 based on Figure 3 The illustrated embodiment further defines steps 101 and 102. Figure 4 In the illustrated embodiment, step 101 includes steps 201, 202, and 203, and step 102 includes steps 204 and 205. For example... Figure 4 As shown, the method includes the following steps: Step 201: Use a preset parsing tool to obtain the target query conditions in the original query statement. The target query conditions include the target field name.

[0045] In the embodiments of this application, a preset parsing tool (such as the jsqlparser tool) can parse and obtain the structural information of the original query statement (generally, the SQL query statement structural information is objectified), and can adjust the parsed original query statement to generate a new SQL query statement.

[0046] Specifically, the original query statement is analyzed using an SQL parsing tool to extract the target query conditions (i.e., query conditions with parameters, including field names). For example, if the original query statement is: select A.name from A where A.column1=?, the SQL parsing tool will obtain the target query condition A.column1=? based on its characteristics (such as "?"), where A.column1 is the target field name.

[0047] Step 202: Obtain the table name of the target data table based on the target field name.

[0048] In the embodiments of this application, the target field name generally contains the table name information of the target data table. After obtaining the target query conditions of the original query statement using an SQL parsing tool, the table name of the target data table corresponding to the target field name can be obtained according to the target field name corresponding to the target query conditions. For example, if the target field name is A.column1, then the table name of the corresponding target data table is A.

[0049] As an optional implementation, after parsing the original query statement using a parsing tool, it is necessary to preprocess the original query statement, that is, to transform the original query statement into an executable query statement (because executing the SQL query statement will result in an error if it contains unparseable symbols such as "?"). Specifically, the parsing tool deletes or replaces all target query conditions in the obtained original query statement with equivalent patterns such as "1=1". At this time, the transformed query statement can be executed normally. For example, after preprocessing (such as deleting target query conditions) the original query statement "select A.name from A where A.column1=?", it becomes "select A.name from A".

[0050] Step 203: Based on the table name of the target data table, obtain the total amount of data corresponding to the target data table.

[0051] In the embodiments of this application, the total amount of data corresponding to the target data table is the total number of data entries contained in the target data table.

[0052] Specifically, based on the table name of the target data table obtained in step 202, the total number of data rows in the target data table can be obtained by executing the select count operation.

[0053] Step 204: Based on the total amount of data in the target data table, sort each piece of data in the target data table to obtain the sorted target data table.

[0054] In the embodiments of this application, in order to avoid the randomness of data when segmenting the target data table (to ensure that the segmentation results are consistent each time and can completely cover the data in the table), it is necessary to sort based on the primary key field or unique index field of the target data table.

[0055] Specifically, sorting statements can be generated based on primary key fields or unique index fields, such as "select * from target data table order by primary key field". Executing this sorting statement can arrange the records in the target data table in a fixed order.

[0056] It's worth noting that database tables typically define primary keys (which can be obtained by querying the database's metadata table) for sorting. If a table doesn't have a primary key, indexed fields can be used instead.

[0057] Step 205: Based on the preset segmented data volume, the sorted target data table is segmented to obtain at least one segmented table corresponding to the sorted data table.

[0058] In the embodiments of this application, the preset segmented data volume is the number of data entries in the pre-set segment, which can be set according to actual needs, and is not limited in the embodiments of this application.

[0059] Specifically, after sorting the target data table according to step 204, and then combining the preset segmented data volume (such as 10,000 rows per segment), the segmentation is achieved through the limit syntax (such as "limit start, 10,000", where start and 10,000 are the starting row position and the number of rows to be returned, respectively, which are the cursor position and the amount of data contained in each segment).

[0060] In the embodiments of this application, after segmenting the sorted target data table, the original query statement needs to be adjusted, that is, the table name of the target data table is replaced with the segmented table name. For example, assuming the original query statement is "select * from A", and the table name A of the target data table is replaced with "select * from A order by primary key limit start, preset segment data size", then the adjusted original query statement is "select * from (select *from A order by primary key field limit start, preset segment data size) A_alias", where A_alias is the alias given to the segmented table after the transformation, and can be named arbitrarily within the syntax range, which is not restricted in this application.

[0061] As an optional implementation, after segmenting the sorted target data table, a segmented search is performed. That is, starting from the first segment table, a count query operation is used to sequentially query whether each segment table contains the target parameter value. Only the segment table containing the target parameter value is recursively searched to reduce the number of queries.

[0062] In summary, this application reduces the number of queries and thus lowers the complexity of operation time by performing segmented queries on the target data table based on the preset segmented data volume and the total data volume of the target data table.

[0063] As one possible implementation method, Figure 5 A flowchart of the third query sample generation method provided in the embodiments of this application is shown. Figure 5 based on Figure 3 The illustrated embodiment further defines step 103. Figure 5 In the illustrated embodiment, step 103 includes steps 301, 302, 303, 304, 305, and 306. For example... Figure 5 As shown, the method includes the following steps: Step 301: Based on the preset binary search algorithm, perform binary search on the first segment table to obtain at least one sub-segment table.

[0064] In embodiments of this application, the first segmentation table is any segmentation table of at least one segmentation table containing the target parameter value. (Refer to...) Figure 6 , Figure 6 This is a schematic diagram of a binary search algorithm provided in an embodiment of this application. The principle of the binary search algorithm is to split the "segment containing the target parameter" into two halves and continuously eliminate the half without the target parameter until only one record remains.

[0065] Specifically, such as Figure 7 As shown, Figure 7 This is a schematic diagram of a search process provided in an embodiment of this application. The application performs a binary search on the first segment table to obtain two sub-segment tables. Specifically, the adjusted original query statement obtained in step 205 is split into two new query statements. The table names of the segment tables, corresponding to "start" and "preset segment data volume", are replaced with "start" and "preset segment data volume / 2", and "start + preset segment data volume / 2" and "preset segment data volume / 2", respectively. This yields the segmented query statements for the sub-segment tables. This process is repeated to obtain the segmented query statements for the sub-segment tables after each binary search.

[0066] Step 302: Based on the segmented query statement of the first sub-segment table, query the number of target parameters in the first sub-segment table that satisfy the query conditions in the segmented query statement. The first sub-segment table is any sub-segment table among at least one sub-segment table. The segmented query statement is obtained by adjusting the original query statement based on the first sub-segment table.

[0067] In the embodiments of this application, the two new query statements obtained in step 301 are executed respectively to determine whether the target parameter value can be found in the two sub-segment tables. The sub-segments where the target parameter value can be found are further subjected to binary search until the unique location of the target parameter value is located.

[0068] Specifically, based on the segmented query statement corresponding to each sub-segment table, the count query operation is used to count the number of target parameters in each sub-segment table. If the return value after executing the count operation is greater than zero, step 303 is executed.

[0069] Step 303: If the number of target parameters is greater than the first preset value, determine the data volume of the first sub-segment table.

[0070] In the embodiments of this application, the first preset value is zero, indicating that the target parameter value exists in the current sub-segment table being queried.

[0071] Specifically, if the target parameter value exists in the current sub-segment table, the data volume of the current sub-segment table is determined based on the location of the limit in the segmented query statement (for example, "limit start,1" means there is only one piece of data, and the position of the data is "start"). If the data volume of the current sub-segment table is greater than 1, the binary search operation is continued on the current sub-segment table; if the data volume of the current sub-segment table is equal to 1, step 304 is executed.

[0072] Step 304: If the data volume of the first sub-segment table is the second preset value, determine the data position of the target parameter in the first sub-segment table.

[0073] In the embodiments of this application, the second preset value refers to the fact that the current sub-segment table being queried contains only one piece of data.

[0074] Specifically, if the first sub-segment table contains only one piece of data (i.e., the limit locates one piece of data), the data position of the target parameter in the first sub-segment table can be obtained based on the segmented query statement of the first sub-segment table. For example, if the limit of the segmented query statement corresponding to the first sub-segment table is "limit 200, 1", it indicates that the data position (index) of the target parameter in the first sub-segment table is 200.

[0075] Step 305: Obtain the value of the first target parameter based on the data location of the target parameter and the segment field name in the segmented query statement.

[0076] In the embodiments of this application, the segment field name in the segmented query statement is the target field name corresponding to the parameter to be filled in the original query statement.

[0077] Specifically, the target parameter value can be accurately located based on the data location of the target parameter (i.e., the row where the target parameter is located) and the target field name (i.e., the column where the target parameter is located).

[0078] Step 306: Assign values ​​to the original query statement using the first target parameter value to obtain the first query sample.

[0079] In the embodiments of this application, the first target parameter value obtained in step 305 is assigned to the original query statement, and the resulting new query statement is a query sample. For example, if the original query statement is "select student.name from student where student.id=?", and the target parameter value corresponding to the target field name (student ID) is 1001 (student ID identifier), then the query sample is "select student.name from studentwhere student.id=1001", which means querying the name of the student with student ID 1001 from table A.

[0080] After obtaining the first query sample, this application responds to the query statement execution instruction by executing the first query sample in the target database and obtaining the execution result; if the execution result satisfies the preset query result, the first query sample is saved to the sample set; based on the preset binary search algorithm, the second target parameter value obtained after performing parameter query on the second segment table is obtained, so as to generate the second query sample according to the second target parameter value, wherein the second segment table is any segment table other than the first segment table in at least one segment table.

[0081] In the embodiments of this application, the preset query result may refer to the data that can be queried, or the number of data entries queried may be within a preset data range. It should be noted that the preset data range may be customized or the relevant historical data of the original query statement may be queried for reference, and is not limited in the embodiments of this application.

[0082] Specifically, after obtaining the first query sample, the query sample is executed in the target database. If the execution can retrieve data (or the number of data records is within the preset range), it means that the query sample is valid and is saved to the sample set. Otherwise, the query sample is considered invalid. (In some cases, the query sample may be invalid, so it is necessary to judge, such as when the target query condition contains a greater than or less than sign, such as column>?).

[0083] After obtaining and verifying a query sample, continue with a binary search on the next segment of the table until the entire table has been traversed.

[0084] To further explain the entire process of generating query samples, please refer to... Figure 8 , Figure 8 This application provides an overall flowchart of a query sample generation method according to an embodiment of the present application. A specific example is given below to explain the query sample generation process: This application uses a joint query of two tables (i.e., Table A and Table B) as an example. It should be noted that the specific examples provided in this application are only for explaining the present invention and are not intended to limit the scope of the present invention.

[0085] 1) Parse and obtain key information of the original query statement: Parse the original query statement to obtain the target query conditions and target data table corresponding to the target parameters (i.e., the parameters corresponding to "?" in the original query statement); 2) Preprocessing the original query statement: The original query statement is preprocessed to transform it into an executable SQL query statement, such as deleting or replacing the target query condition with an equivalent form like "1=1"; 3) Obtain the total amount of data in the target data table and determine the number of segments in the target data table: Use the select count query operation to count the total amount of data in table A and table B respectively. For example, if table A and table B each have 20,000 rows, and the pre-set segment data volume is 10,000 rows, then table A and table B will be divided into two segments, and each segment table will contain 10,000 rows of data. 4) Modify the original query statement, perform segmented search in a loop, and determine whether the current segment has the target parameter value. If not, move to the next segment search: Continue to modify the original query statement after modification in 2) to obtain the segmented query statement for each segment table. That is, replace the table names of table A and table B with query statements containing primary key (for sorting) and limit (for positioning). After obtaining each segment table, perform a target parameter value existence check. For segment tables where the target parameter value does not exist, do not search again. 5) If the target parameter value exists in the current segment, perform a binary search on that segment until one or more possible sample locations are located: For the segment table containing the target parameter value, perform a binary search on it, as follows: Figure 9 As shown, Figure 9 This application provides an exemplary binary search structure diagram of two tables, as shown in the embodiment of the present application. Figure 9 First, select the current segment table of table B and divide it into two sub-segment tables. Then, compare the target parameter value with the current segment table of table A. If it does not exist, discard it and stop searching. If it exists, recursively perform the binary search (continue binary searching the current sub-segment table) until table B is divided into single rows of data. Then, use the same method to binary search the current segment table of table A until table A is divided into single rows of data. The final binary search result is as follows. Figure 10 As shown, Figure 10 This is a schematic diagram of an exemplary two-table binary search result provided in an embodiment of this application. Finally, one data point corresponding to each of Table A and Table B is combined to form one sample (target parameter value). 6) Obtain the target parameter value based on the target parameter position and segment field name to generate a query sample: Assign the target parameter value obtained in 5) to the original query statement of the two-table join to obtain a query sample; 7) Determine the validity of the query sample. If it is valid, save it to the sample set: Execute the query sample obtained in 6) in the target database. If the execution can retrieve data (or the number of data records is within the preset range), it means that the query sample is valid. Save it to the sample set and continue the search of the next segment until all data in Table A and Table B have been traversed. 8) Determine the program termination condition. If the condition is met, exit the loop and terminate the program; otherwise, continue the loop until all records have been traversed. Program termination conditions include, but are not limited to, the following: The program terminates when the segmented search loop ends, i.e., when both tables are traversed; the program terminates when the number of found query samples reaches the preset target number; and the program terminates when the program runtime reaches the preset value (the maximum runtime can be set to avoid resource waste in extreme cases).

[0086] The implementation method of the above-described query sample generation method also applies to the implementation method of this overall process, and will not be described in detail here.

[0087] It should be noted that for most raw query statements, the above steps can successfully obtain query samples. However, due to the complexity of SQL syntax, some raw query statements containing special syntax require specific processing. This application provides some common examples: 1) Outer join scenario: Outer join allows the query results to be returned even when one of the related tables is empty, but an empty table may cause the search program to exit prematurely. The optional handling method is: first, determine whether the outer join table, which can be empty, is empty. If it is empty and the target query condition contains the field of the table, then first preset the parameter value corresponding to the target query condition (such as setting it to a random constant value or string that does not affect the query result), and then execute the subsequent search for the target parameter value.

[0088] 2) Scenarios containing IN / NOT IN syntax: If the original query statement contains query conditions such as "IN (...)", "NOT IN (...)", "IN (?)", and "NOT IN (?)", the following processing methods can be used: Locate the position of this type of syntax by string matching or regular expressions, and first preprocess it to the form of equal sign + question mark (e.g., replace col IN (?) with col = ?); After the sample search is completed and the target parameter value is obtained, the equal sign form can be restored to the IN form.

[0089] 3) Scenarios containing LIMIT syntax: The original query statement may contain query conditions such as "limit ..." or "limit ?" that limit the number of rows to be retrieved. You only need to set an appropriate limit number of rows according to the actual situation (e.g., replace limit ? with limit 1,10). 4) Scenarios involving LIKE fuzzy queries: When the target query condition has a LIKE type, the same processing as the equals sign can be used. The difference is that, according to the syntax characteristics of LIKE, after obtaining the target parameter value, a percentage sign "%" is added to the left and right to make it conform to the syntax characteristics of LIKE %...%

[0090] 5) Scenarios where functions contain target parameters: For functions with target parameters, such as count(?) and concat('abc', ?), in most cases, the parameter can be set to a reasonable constant based on the function's syntax (generally done during the preprocessing of the original query statement). For example, count(?) can be replaced with count(10). More intelligent processing can also be performed based on the specific data in the table and the characteristics of the function.

[0091] In summary, the query sample generation method provided in this application uses a binary search algorithm to perform parameter search on the target data table, which can effectively control the search range and significantly improve search efficiency, thereby achieving compression and controllability of time complexity.

[0092] To implement the above embodiments, this application also provides a query sample generation device. Figure 11 This is a schematic diagram of the structure of a query sample generation device 1100 provided in an embodiment of this application. Figure 11 As shown, the device includes: The acquisition unit 1101 is used to acquire the total amount of data corresponding to the target data table in the original query statement. The target data table is stored in the target database. Segmentation unit 1102 is used to segment the target data table based on the total data volume and the preset segmented data volume to obtain at least one segmented table corresponding to the target data table. The generation unit 1103 is used to perform parameter query on the first segment table based on a preset binary search algorithm to obtain the first target parameter value, so as to generate the first query sample of the target database according to the first target parameter value. The first segment table is any segment table in at least one segment table.

[0093] In some embodiments of this application, the acquisition unit 1101 is used to: acquire the target query conditions in the original query statement using a preset parsing tool, the target query conditions including the target field name; acquire the table name of the target data table based on the target field name; and acquire the total amount of data corresponding to the target data table based on the table name of the target data table.

[0094] In some embodiments of this application, the segmentation unit 1102 is used to: sort each piece of data in the target data table based on the total amount of data corresponding to the target data table to obtain a sorted target data table; and segment the sorted target data table based on a preset segmented data amount to obtain at least one segmented table corresponding to the sorted data table.

[0095] In some embodiments of this application, the generation unit 1103 is configured to: perform binary search on a first segment table based on a preset binary search algorithm to obtain at least one sub-segment table; query the number of target parameters in the first sub-segment table that satisfy the query conditions in the segmented query statement based on the segmented query statement of the first sub-segment table, wherein the first sub-segment table is any one of the at least one sub-segment table, and the segmented query statement is obtained by adjusting the original query statement based on the first sub-segment table; determine the data volume of the first sub-segment table if the number of target parameters is greater than a first preset value; determine the data position of the target parameter in the first sub-segment table if the data volume of the first sub-segment table is a second preset value; and obtain the first target parameter value based on the data position of the target parameter and the segmented field name in the segmented query statement.

[0096] In some embodiments of this application, the generation unit 1103 is used to: assign a value to the original query statement using the first target parameter value to obtain a first query sample.

[0097] In some embodiments of this application, the generation unit 1103 is further configured to: execute a first query sample in a target database in response to a query statement execution instruction, and obtain an execution result; save the first query sample to a sample set if the execution result satisfies a preset query result; obtain a second target parameter value obtained after performing a parameter query on a second segment table based on a preset binary search algorithm, so as to generate a second query sample according to the second target parameter value, wherein the second segment table is any segment table other than the first segment table in at least one segment table.

[0098] The methods and apparatus provided in the embodiments of this application have been described above. To implement the functions of the methods provided in the embodiments of this application, the electronic device may include a hardware structure and software modules, and may implement the above functions in the form of a hardware structure, software modules, or a hardware structure plus software modules. One of the above functions may be executed in the form of a hardware structure, software modules, or a hardware structure plus software modules.

[0099] Figure 12 This is a block diagram illustrating an electronic device 1200 for implementing the above-described query sample generation method, according to an exemplary embodiment. For example, the electronic device 1200 may be a mobile phone, computer, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.

[0100] Reference Figure 12 The electronic device 1200 may include a communication interface 1201, capable of interacting with other devices; a processor 1202, connected to the communication interface 1201 to interact with other devices, used to execute the methods provided by one or more of the above-described technical solutions when running a computer program; and a memory 1203, on which the computer program is stored. Specifically, the specific processing procedure of the processor 1202 can refer to the query sample generation method described in the above embodiments of this application.

[0101] Of course, in practical applications, the various components in electronic device 1200 are coupled together through bus system 1204. It can be understood that bus system 1204 is used to realize the connection and communication between these components. In addition to a data bus, bus system 1204 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, in... Figure 12 The general labeled all buses as Bus System 1204.

[0102] The memory 1203 in this embodiment is used to store various types of data to support the operation of the electronic device 1200. Examples of such data include any computer program used to operate on the electronic device 1200.

[0103] The methods disclosed in the embodiments of this application can be applied to processor 1202, or implemented by processor 1202. Processor 1202 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 1202 or by instructions in the form of software. The processor 1202 may be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 1202 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of this application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of this application can be directly manifested as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. The software modules may be located in a storage medium, which is located in memory 1203. Processor 1202 reads the information in memory 1203 and completes the steps of the aforementioned method in combination with its hardware.

[0104] In an exemplary embodiment, the electronic device 1200 may be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers (MCUs), microprocessors, or other electronic components to perform the aforementioned method.

[0105] Embodiments of this application also propose a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the query sample generation method described in the above embodiments of this application.

[0106] Embodiments of this application also propose a computer program product, including a computer program that is executed by a processor using the query sample generation method described in the above embodiments of this application.

[0107] Embodiments of this application also propose a chip including one or more interface circuits and one or more processors; the interface circuits are used to receive signals from the memory of an electronic device and send signals to the processors, the signals including computer instructions stored in the memory, and when the processor executes the computer instructions, it causes the electronic device to execute the query sample generation method described in the above embodiments of this application.

[0108] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0109] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0110] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.

[0111] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processing module, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (control method), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic device, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.

[0112] It should be understood that various parts of the embodiments of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0113] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0114] Furthermore, the functional units in the various embodiments of the present invention can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc.

[0115] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A method for generating query samples, characterized in that, The method includes: Obtain the total amount of data corresponding to the target data table in the original query statement, wherein the target data table is stored in the target database; Based on the total amount of data corresponding to the target data table and the preset segmented data amount, the target data table is segmented to obtain at least one segmented table corresponding to the target data table. Based on a preset binary search algorithm, a parameter query is performed on the first segment table to obtain a first target parameter value, so as to generate a first query sample of the target database according to the first target parameter value. The first segment table is any segment table among the at least one segment table.

2. The method according to claim 1, characterized in that, The process of obtaining the total amount of data corresponding to the target data table in the original query statement includes: Using a preset parsing tool, the target query conditions in the original query statement are obtained, and the target query conditions include the target field name; Based on the target field name, obtain the table name of the target data table; Based on the table name of the target data table, obtain the total amount of data corresponding to the target data table.

3. The method according to claim 1, characterized in that, The step of segmenting the target data table based on the total data volume and the preset segmented data volume to obtain at least one segmented table corresponding to the target data table includes: Based on the total amount of data corresponding to the target data table, each piece of data in the target data table is sorted to obtain the sorted target data table. Based on a preset segmented data volume, the sorted target data table is segmented to obtain at least one segmented table corresponding to the sorted data table.

4. The method according to claim 1, characterized in that, The step of performing a parameter query on the first segment table based on a preset binary search algorithm to obtain the first target parameter value includes: Based on the preset binary search algorithm, binary search is performed on the first segment table to obtain at least one sub-segment table; Based on the segmented query statement of the first sub-segment table, query the number of target parameters in the first sub-segment table that satisfy the query conditions in the segmented query statement. The first sub-segment table is any sub-segment table in the at least one sub-segment table. The segmented query statement is obtained by adjusting the original query statement based on the first sub-segment table. If the number of target parameters is greater than a first preset value, the data volume of the first sub-segment table is determined. When the data volume of the first sub-segment table is a second preset value, determine the data position of the target parameter in the first sub-segment table; The value of the first target parameter is obtained based on the data location of the target parameter and the segment field name in the segmented query statement.

5. The method according to claim 1, characterized in that, The step of generating the first query sample of the target database based on the first target parameter value includes: The first target parameter value is used to assign a value to the original query statement to obtain the first query sample.

6. The method according to claim 1, characterized in that, After generating a first query sample of the target database based on the first target parameter value, the method includes: In response to the query statement execution instruction, the first query sample is executed in the target database to obtain the execution result; If the execution result satisfies the preset query result, the first query sample is saved to the sample set; Based on a preset binary search algorithm, the second target parameter value is obtained after performing a parameter query on the second segment table, and a second query sample is generated based on the second target parameter value. The second segment table is any segment table other than the first segment table in the at least one segment table.

7. A query sample generation device, characterized in that, The device includes: The acquisition unit is used to acquire the total amount of data corresponding to the target data table in the original query statement, wherein the target data table is stored in the target database. The segmentation unit is used to segment the target data table based on the total data volume and the preset segment data volume to obtain at least one segmented table corresponding to the target data table. The generation unit is used to perform parameter query on the first segment table based on a preset binary search algorithm to obtain a first target parameter value, so as to generate a first query sample of the target database based on the first target parameter value, wherein the first segment table is any segment table among the at least one segment table.

8. An electronic device, characterized in that, include: The processor and the memory used to store computer programs that can run on the processor. When the processor is used to run the computer program, it performs the method according to any one of claims 1 to 6.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 6.