Data query method, electronic device and storage medium
By parsing and splitting query statements, combined with thread parallel processing, the problem of insufficient parallelization and repeated calculations in complex database queries is solved, and query efficiency and stability are improved.
Patent Information
- Application Number
- CN202410954580.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-17
AI Technical Summary
In existing databases, due to strict parallelization startup conditions during complex queries, the query speed is slow and the parallelization mechanism cannot be effectively utilized. In addition, repeated calculations in complex queries lead to excessive resource consumption.
By parsing the query statement, the statement field types are identified, split into indivisible computing units, and processed in parallel through threads to reduce repeated calculations and optimize the allocation relationship between threads and computing units.
It improves query efficiency, reduces resource consumption, achieves more stable parallel computing execution, and improves processing efficiency.
Smart Images

Figure CN118503311B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data query method, an electronic device and a storage medium. Background Art
[0002] As we enter the era of big data, the amount of data in all walks of life is increasing, and the demand for data storage and data query is also growing. A complex query usually results in slow query speed.
[0003] In order to solve this problem, the parallelization mechanism of the database is often used for query.
[0004] However, currently, relatively strict parallelization startup conditions are set inside the database. For some complex query statements, the parallelization mechanism may not be used for querying because the database's parallelization startup conditions are not met, resulting in a slow query speed. Summary of the invention
[0005] The purpose of the present application is to provide a data query method, an electronic device and a storage medium to improve the query efficiency of complex query tasks in order to address the deficiencies in the above-mentioned prior art.
[0006] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:
[0007] In a first aspect, an embodiment of the present application provides a data query method, comprising: parsing a query statement to obtain at least one statement field in the query statement;
[0008] Determine, according to the type of each of the statement fields, a plurality of computing units corresponding to the query statement, wherein the type of the statement field includes: a first type or a second type, the complexity corresponding to the second type is less than the complexity corresponding to the first type, and each of the computing units is an inseparable field in the query statement;
[0009] Allocating corresponding threads to each of the computing units respectively, and obtaining query results of each of the computing units in parallel through the corresponding threads;
[0010] The query result of the query statement is determined according to the query results of each of the calculation units and the calculation logic of the query statement.
[0011] Optionally, determining the plurality of computing units corresponding to the query statement according to the type of each statement field includes:
[0012] If the type of the statement field is the first type, disassembling the statement field to obtain a plurality of computing units corresponding to the statement field;
[0013] If the type of the statement field is the second type, the statement field is used as a calculation unit.
[0014] Optionally, the disassembling the statement field to obtain a plurality of computing units corresponding to the statement field includes:
[0015] According to the statement field and the created first mapping table, determining whether to obtain multiple computing units corresponding to the statement field from the first mapping table; the first mapping table is used to record the mapping relationship between the first type of statement field and the split computing units;
[0016] If yes, obtaining a plurality of computing units corresponding to the statement field from the first mapping table according to the statement field;
[0017] If not, the statement field is split according to a preset splitting strategy to obtain a plurality of computing units corresponding to the statement field.
[0018] Optionally, judging whether to obtain multiple computing units corresponding to the statement field from the first mapping table according to the statement field and the created first mapping table includes:
[0019] According to the statement field, querying whether the statement field exists in the first mapping table;
[0020] If the statement field exists in the first mapping table, determining whether the check value of the statement field is consistent with the reference check value of the statement field recorded in the first mapping table;
[0021] If they are consistent, multiple computing units corresponding to the statement fields are obtained from the first mapping table.
[0022] Optionally, the allocating a corresponding thread to each of the computing units respectively, and obtaining the query results of each of the computing units in parallel through the corresponding thread, includes:
[0023] According to each computing unit and a second mapping table, determining the thread to which each computing unit is to be assigned, and assigning each computing unit to a corresponding thread; the second mapping table is used to record the mapping relationship between the computing unit and each thread in the thread pool;
[0024] The query results of each computing unit are obtained by parallel processing of threads corresponding to each computing unit.
[0025] Optionally, determining the thread to which each computing unit is to be allocated according to each computing unit and the second mapping table includes:
[0026] If a target thread corresponding to the target computing unit is recorded in the second mapping table, determining that the target thread is the thread to be allocated to the target computing unit;
[0027] If the target thread corresponding to the target computing unit is not recorded in the second mapping table, adding the target computing unit to the candidate set;
[0028] The computing units in the candidate set are evenly distributed to the threads.
[0029] Optionally, the allocating a corresponding thread to each of the computing units respectively, and obtaining the query results of each of the computing units in parallel through the corresponding thread, includes:
[0030] Allocate each computing unit to the corresponding thread in the thread pool, and generate an initial task set corresponding to each thread;
[0031] Add the primary key attribute of the result report to the initial task set corresponding to each thread, and obtain the intermediate task set corresponding to each thread;
[0032] Reorganize tasks according to the intermediate task set corresponding to each thread to obtain the target task set corresponding to each thread, wherein the target task set includes the query statement corresponding to each computing unit;
[0033] The target task set corresponding to each thread is written into the thread queue, the thread pool is started, and the target task set corresponding to each thread is executed in parallel.
[0034] Optionally, determining the query result of the query statement according to the query results of each of the computing units and the computing logic of the query statement includes:
[0035] According to the query results of each calculation unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, the query results of each calculation unit are written into the corresponding position in the result report to obtain the initial data query results;
[0036] The query result of the query statement is obtained according to the initial data query result and the calculation logic of the query statement.
[0037] Optionally, the query results of each computing unit are written into corresponding positions in the result report according to the query results of each computing unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report to obtain the initial data query result, including:
[0038] According to the correspondence between the primary key attribute and the row, determining the row to which the query result of each calculation unit belongs in the result report;
[0039] According to the correspondence between fields and columns, determining the column to which each calculation unit belongs in the result report;
[0040] The query results of each computing unit are written into corresponding positions in the result report according to the rows to which the query results of each computing unit belong in the result report and the columns to which the query results of each computing unit belong in the result report.
[0041] Optionally, the allocating corresponding threads to the computing units respectively includes:
[0042] Determine the row splitting ratio when the thread executes the next computing unit query task according to the average query task time of the thread and the time taken by the thread to execute the query task of the current computing unit;
[0043] Splitting the next computing unit query task of the thread into multiple subtasks according to the row splitting multiple when the thread executes the next computing unit query task;
[0044] Each subtask is assigned to a corresponding thread according to the idle state and / or processing capability of each thread.
[0045] Optionally, the allocating corresponding threads to the computing units respectively includes:
[0046] Generate a mapping relationship between each computing unit and each thread according to the processing time of each computing unit and the current total time of each thread;
[0047] According to the mapping relationship between each computing unit and each thread, a corresponding thread is allocated to each computing unit.
[0048] Optionally, generating a mapping relationship between each computing unit and each thread according to the processing time consumed by each computing unit and the current total time consumed by each thread includes:
[0049] Sort the computing units according to their processing time.
[0050] According to the sorting results of each computing unit, each computing unit is sequentially allocated to the thread with the smallest total time consumption, and a mapping relationship between each computing unit and the allocated thread is generated.
[0051] In a second aspect, an embodiment of the present application further provides a data query device, including: a parsing module, a determining module, and a processing module;
[0052] The parsing module is used to parse the query statement to obtain at least one statement field in the query statement;
[0053] The determination module is used to determine a plurality of computing units corresponding to the query statement according to a type of each of the statement fields, wherein the type of the statement field includes: a first type or a second type, the complexity corresponding to the second type is less than the complexity corresponding to the first type, and each of the computing units is an inseparable field in the query statement;
[0054] The processing module is used to assign corresponding threads to each of the computing units, and obtain query results of each of the computing units in parallel through the corresponding threads;
[0055] The processing module is used to determine the query result of the query statement according to the query results of each of the calculation units and the calculation logic of the query statement.
[0056] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to implement the data query method provided in the first aspect.
[0057] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the data query method provided in the first aspect is executed.
[0058] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program code. When the computer program code is executed by a computing device, the computing device executes the data query method provided in the first aspect.
[0059] The beneficial effects of this application are:
[0060] The present application provides a data query method, an electronic device and a storage medium, the method comprising: parsing a query statement to obtain at least one statement field in the query statement; determining multiple computing units corresponding to the query statement according to the type of each statement field; assigning corresponding threads to each computing unit respectively, and obtaining the query results of each computing unit in parallel through the corresponding threads; determining the query results of the query statement according to the query results of each computing unit and the calculation logic of the query statement. The present application method can split the statement field according to the type of the statement field by identifying the statement field in the query statement, and obtain multiple computing units corresponding to the query statement. By splitting the query statement into the smallest computing unit field that cannot be split, and querying each computing unit, the additional resource consumption caused by the repeated calculations of different fields in the query statement can be effectively reduced. Among them, only the splitting strategy needs to be configured, and the statement fields of different types can be automatically split according to the configured splitting strategy to obtain the computing units corresponding to the query statement, and the splitting process is automatically realized, which has a higher effect. By assigning each computing unit to the corresponding thread for parallel processing, compared with the method of executing multiple subtasks multiple times by one thread, multi-threaded parallel execution is adopted, and the computing efficiency is significantly improved. After the computing unit is allocated to the thread, the execution of the thread can be triggered without any triggering restrictions, and the implementation of the solution is more stable.
[0061] In addition, the allocation relationship between computing units and threads is optimized based on the query time of threads, so that at any time, the total processing time of each thread in the thread pool can reach the global optimum, thereby improving processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0063] Figure 1 A flowchart of a data query method provided in an embodiment of the present application;
[0064] Figure 2 A flowchart of another data query method provided in an embodiment of the present application;
[0065] Figure 3 A flowchart of another data query method provided in an embodiment of the present application;
[0066] Figure 4 A flowchart of another data query method provided in an embodiment of the present application;
[0067] Figure 5 A flowchart of another data query method provided in an embodiment of the present application;
[0068] Figure 6 A flowchart of another data query method provided in an embodiment of the present application;
[0069] Figure 7 A flowchart of another data query method provided in an embodiment of the present application;
[0070] Figure 8 A flowchart of another data query method provided in an embodiment of the present application;
[0071] Fig. 9 A flowchart of another data query method provided in an embodiment of the present application;
[0072] Fig.10 A flowchart of another data query method provided in an embodiment of the present application;
[0073] Fig.11 A flowchart of another data query method provided in an embodiment of the present application;
[0074] Fig.12 A flowchart of another data query method provided in an embodiment of the present application;
[0075] Fig.13 A schematic diagram of a data query device provided in an embodiment of the present application;
[0076] Fig.14 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0077] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of sequence, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.
[0078] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0079] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0080] In the prior art, when the amount of data in a table in an Oracle (relational database) database is large, a complex query usually results in a slow query speed.
[0081] To solve this problem, some solutions will consider using Oracle's own parallelization mechanism to try to avoid such problems (such as HINTS, / +parallel(n) / etc.), this method is not stable. The problems of this method include: 1. Under normal circumstances, it is necessary to determine whether to use parallelism based on the execution plan. Generally, parallelism will be effective only when the table data volume is in the millions and the full table scan is required; 2. Oracle database itself does not guarantee parallel execution. In CBO (Cost-Based Optimization) mode, if the index can be reached, parallelism will fail; 3. Parallelization itself does not support the use of grouping functions. After the parallel threads return the results, the main thread needs to call the grouping function for calculation.
[0082] Some other solutions would consider dividing the query into multiple sub-queries. First, this solution does not fully utilize the current huge CPU and memory resources, and it executes multiple sub-queries in one thread. At the same time, even if the thread pool technology is used, manual query splitting has the problem of poor scalability.
[0083] Complex queries often contain some repeated or similar calculation logic (for example , , and B may be calculated through a complex and time-consuming storage function. The repeated calculation of this part of B is considered unnecessary). These repeated calculations will consume additional CPU and memory resources during the query. Therefore, these repeated calculations can be lexically parsed according to certain rules to parse out the same calculation units (such as B, , ), and then recalculate in memory after the query results are returned.
[0084] Based on this, the data query method provided by this solution obtains at least one statement field by parsing the query statement, and obtains multiple calculation units corresponding to the query statement based on the statement field, thereby obtaining the indivisible minimum unit field corresponding to the query statement. By querying each calculation unit, repeated or similar calculation logic only needs to be calculated once, reducing unnecessary repeated calculations. By assigning each calculation unit to different threads for parallel processing, the computing efficiency can be improved, and the execution of parallel calculations has no restrictions and can be triggered at any time, achieving a more stable effect.
[0085] First, some common terms that may be involved in this plan are explained:
[0086] SQL: is a database query and programming language used to access data and query, update, and manage relational database systems.
[0087] Thread pool: A thread resource usage model. Use the thread pool to maintain multiple threads, waiting for the scheduling to allocate tasks that can be executed concurrently. The thread pool can avoid the overhead of thread creation and destruction, ensure full utilization of the kernel, and prevent over-scheduling.
[0088] Complex query: refers to a SQL script that involves multiple tables and complex logic.
[0089] Complex fields: refers to query fields with complex calculation logic in SQL scripts, such as fields that use stored functions.
[0090] Lexical analysis: refers to the process in computer science of converting a character sequence into a word (Token) sequence according to the lexical rules of a language.
[0091] Calculation unit: refers to the logical block extracted from the complex field, such as , then B and for The computing unit.
[0092] Figure 1 The following is a flow chart of a data query method provided by an embodiment of the present application; the execution subject of this solution can be a computer device such as a terminal or a server. Figure 1 As shown, the method may include:
[0093] S101: Parse a query statement to obtain at least one statement field in the query statement.
[0094] The query statement may be an SQL statement, which is usually composed of multiple fields. For example, an SQL statement may include {data to be queried, where to query from, query conditions}, etc. By parsing and identifying the query statement, at least one statement field in the query statement may be obtained.
[0095] S102: Determine multiple computing units corresponding to the query statement according to the type of each statement field.
[0096] The types of statement fields include: a first type or a second type, the complexity corresponding to the second type is less than the complexity corresponding to the first type, and each calculation unit is an inseparable field in the query statement.
[0097] Optionally, according to the type of the statement field, the statement field may be split to obtain calculation units corresponding to each statement field, so that the calculation units corresponding to each statement field constitute multiple calculation units corresponding to the query statement.
[0098] In this embodiment, the statement field can be divided into two types: a first type of statement field and a second type of statement field, wherein the first type of statement field may refer to a complex field, and the second type of statement field may refer to a simple field.
[0099] Generally, fields that are not simple data types (such as INT, VARCHAR, DATE, etc.) or fields composed of multiple simple fields can be defined as complex fields. Complex fields can include but are not limited to: composite fields, JSON fields, array fields, encrypted fields, etc.
[0100] The type of each statement field can be determined based on the characteristics of pre-defined complex fields and simple fields.
[0101] S103 . Allocate corresponding threads to each computing unit respectively, and obtain query results of each computing unit in parallel through the corresponding threads.
[0102] Based on the multiple computing units corresponding to the determined query statements, each computing unit can be allocated to a corresponding thread in the thread pool, wherein one thread can correspond to one or more computing units. When the number of computing units is the same as the number of threads, one computing unit can be allocated to one thread.
[0103] By starting the thread pool, you can start multi-threaded parallel query, so as to obtain the query results of each computing unit corresponding to each thread. The computing units corresponding to the thread can refer to the computing units allocated to the thread.
[0104] S104: Determine the query result of the query statement according to the query results of each computing unit and the computing logic of the query statement.
[0105] Since the query statement is formed by logical combination of various computing units, it is necessary to combine and calculate the query results of each computing unit according to the calculation logic of the query statement to obtain the query result of the query statement. The calculation logic of the query statement can refer to the logical combination relationship between various calculation logics. For example: the query statement A=B+C D / E, the calculation units corresponding to the query statement are: B, C, D, E. The calculation logic between calculation units C and D is multiplication, and the calculation logic between the result of the multiplication of C and D and E is division. Assuming that the query results of each calculation unit B, C, D, and E are: 1, 3, 6, and 2, then after combining the query results of each calculation unit according to the calculation logic of the query statement, the query result of query statement A is: 1+3 6 / 2=10.
[0106] In summary, the data query method provided in this embodiment includes: parsing the query statement to obtain at least one statement field in the query statement; determining multiple computing units corresponding to the query statement according to the type of each statement field; assigning corresponding threads to each computing unit, and obtaining the query results of each computing unit in parallel through the corresponding threads; determining the query results of the query statement according to the query results of each computing unit and the calculation logic of the query statement. The method of the present application identifies the statement field in the query statement, so that the statement field can be split according to the type of the statement field to obtain multiple computing units corresponding to the query statement. By splitting the query statement into the smallest computing unit field that cannot be split, and querying each computing unit, the additional resource consumption caused by the repeated calculations of different fields in the query statement can be effectively reduced. By assigning each computing unit to the corresponding thread for parallel processing, compared with the method of executing multiple subtasks multiple times by one thread, multi-threaded parallel execution is adopted, and the computing efficiency is significantly improved. And after the computing unit is assigned to the thread, the execution of the thread can be triggered, there is no trigger restriction condition, and the implementation stability of the scheme is higher.
[0107] Optionally, in step S102, determining multiple computing units corresponding to the query statement based on the type of each statement field may include: if the type of the statement field is the first type, disassembling the statement field to obtain multiple computing units corresponding to the statement field; if the type of the statement field is the second type, treating the statement field as a computing unit.
[0108] In some embodiments, if the type of the statement field is the first type, since the statement field of the first type is a complex field, the statement field can be disassembled by field splitting to obtain multiple computing units corresponding to the statement field.
[0109] If the statement field type is the second type, since the statement field of the second type is a simple field, its own calculation will not consume too many resources, or it itself is an indivisible minimum calculation unit, so the statement field can be directly used as a calculation unit.
[0110] Figure 2 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Figure 2 As shown, in the above steps, the statement field is disassembled to obtain multiple computing units corresponding to the statement field, which may include:
[0111] S201. According to a statement field and a created first mapping table, determine whether to obtain multiple computing units corresponding to the statement field from the first mapping table.
[0112] The first mapping table is used to record the mapping relationship between the first type of statement fields and the split computing units.
[0113] In one achievable manner, the statement field may be compared with the created first mapping table to determine whether the statement field exists in the first mapping table and whether the computing units corresponding to the statement field can be obtained from the first mapping table.
[0114] It is worth noting that the first mapping table may record the mapping relationship between different first-type statement fields and their split computing units. When initially created, the first mapping table is empty, and as the method is continuously executed, each time a first-type statement field is split, the mapping relationship between the first-type statement field obtained by splitting and its corresponding split computing unit can be updated to the first mapping table, thereby gradually improving the first mapping table.
[0115] In this way, when the first type of statement field is subsequently split, the first mapping table can be queried first. If the first type of statement field to be split exists in the first mapping table and meets the requirements, the calculation units corresponding to the statement field can be preferentially obtained from the first mapping table.
[0116] S202: If yes, then obtain multiple computing units corresponding to the statement field from the first mapping table according to the statement field.
[0117] If it is determined that the computing units corresponding to the statement fields can be obtained from the first mapping table, then the computing units corresponding to the statement fields can be obtained from the first mapping table according to the statement fields.
[0118] S203: If not, split the statement field according to a preset splitting strategy to obtain multiple computing units corresponding to the statement field.
[0119] If the calculation unit corresponding to the statement field cannot be obtained from the first mapping table, the statement field can be split according to the preset splitting strategy to obtain the calculation units corresponding to the statement field, and the mapping relationship between the statement field and the calculation units obtained by splitting is written into the first mapping table.
[0120] Figure 3 A flowchart of another data query method provided by an embodiment of the present application; in step S201, judging whether to obtain multiple computing units corresponding to the statement field from the first mapping table according to the statement field and the created first mapping table may include:
[0121] S301. According to the statement field, query whether the statement field exists in the first mapping table.
[0122] First, check whether the statement field exists in the first mapping table, that is, check whether the statement field exists in the first mapping table.
[0123] S302: If there is a statement field in the first mapping table, determine whether the check value of the statement field is consistent with the reference check value of the statement field recorded in the first mapping table.
[0124] If it exists, it is further determined whether the check value of the statement field is consistent with the benchmark check value of the statement field stored in the first mapping table (in order to distinguish it from the check value currently calculated in real time, the check value recorded in the first mapping table can be called the benchmark check value). Among them, the check value can use the MD5 (Message-Digest Algorithm) check value. When the calculation logic of the statement field has not changed, the MD5 check value of the statement field remains unchanged. The purpose of checking with the MD5 value is to ensure that the statement field currently being queried is completely consistent with the statement field stored in the first mapping table. Not only the calculation units contained are consistent, but also the calculation logic needs to be consistent.
[0125] S303: If they are consistent, obtain multiple computing units corresponding to the statement fields from the first mapping table.
[0126] If the check value of the statement field is consistent with the reference check value of the statement field recorded in the first mapping table, it is determined that a plurality of computing units corresponding to the statement field can be obtained from the first mapping table.
[0127] Figure 4 A flowchart of another data query method provided by an embodiment of the present application; Optionally, in step S202, according to the statement field, obtaining multiple computing units corresponding to the statement field from the first mapping table may include:
[0128] S401. According to a statement field, obtain a split computing unit corresponding to the statement field from a first mapping table.
[0129] Optionally, the statement field can be searched from the first mapping table according to the statement field, thereby obtaining the split computing unit corresponding to the statement field, wherein multiple split computing units corresponding to one statement field are stored together as a computing unit group.
[0130] S402: Determine the split computing unit corresponding to the statement field as the computing unit corresponding to the statement field.
[0131] Therefore, the multiple split computing units corresponding to the statement field can be determined as the computing unit corresponding to the statement field, wherein one split computing unit is used as one computing unit corresponding to the statement field.
[0132] Figure 5 A flowchart of another data query method provided by an embodiment of the present application; Optionally, in step S203, the statement field is split according to a preset splitting strategy to obtain multiple calculation units corresponding to the statement field, which may include:
[0133] S501. Split the statement field according to each operation logic symbol contained in the statement field to obtain multiple calculation units corresponding to the statement field.
[0134] In some embodiments, when there is no statement field in the first mapping table, or when there is a statement field but the check value of the statement field is different from the benchmark check value recorded in the first mapping table, the statement field needs to be split according to a preset splitting strategy.
[0135] Optionally, the process of splitting according to the preset splitting strategy can be understood as a lexical tree analysis process. Lexical tree analysis can refer to the process of converting a character sequence into a word (Token) sequence according to the lexical rules of a language in computer science.
[0136] It can be understood that the two fields separated by the operation logic symbols need to be split according to the operation logic symbols contained in the statement field.
[0137] For example: , and The logical operator " " is separated, so you can and Split it out and get two computing units.
[0138] S502: Record the mapping relationship between the statement fields and the calculation units obtained by splitting, and the mapping relationship between the statement fields and the corresponding calculation logic into a first mapping table.
[0139] Optionally, the mapping relationship between the statement fields and the calculation units obtained by splitting can be recorded in the first mapping table. At the same time, the mapping relationship between the statement fields and the corresponding calculation logic can also be recorded in the first mapping table, which can be used to split the subsequent statement fields and calculate the query statements.
[0140] For example: statement field A=B+C D / E, then the calculation units obtained after splitting include: B, C, D, E; the correspondence between A and the calculation units B, C, D, E can be recorded, so that when querying the statement field A, B, C, D, E can be determined as the calculation units corresponding to A.
[0141] In addition, you can also record A and the calculation logic B+C The corresponding relationship between D / E, so that when the query result of the statement field is calculated according to the query result of the calculation unit B, C, D, E, the calculation logic of the statement field can be obtained according to the calculation logic between the recorded B, C, D, E.
[0142] Optionally, in step S103, a corresponding thread is assigned to each computing unit, and query results of each computing unit are obtained in parallel through the corresponding threads, which may include: assigning each computing unit to a corresponding thread in a thread pool, performing query processing in parallel through each thread, and obtaining query results corresponding to each thread; the query results corresponding to each thread include: query results of each computing unit to which each thread is assigned; the query results of each computing unit include query results of the computing unit under each primary key attribute.
[0143] In one achievable manner, each computing unit can be assigned to a corresponding thread in a thread pool, thereby starting the thread pool and running each thread in parallel to perform parallel query processing and obtain query results corresponding to each thread. The query result corresponding to a thread can include the query results of all computing units assigned to the thread, and the query result of a computing unit can include the query results of the computing unit under each primary key attribute.
[0144] Among them, the primary key attribute can be set when the result report is created. Once the primary key attribute is set, it should not be changed. The primary key attribute can uniquely determine the row in the result report. The primary key attribute can be determined based on the key information you want to query.
[0145] For example, to query the personal information of students in a class, you can create primary key attributes including: name, age, gender, home address, etc. The query results corresponding to each primary key attribute are stored in a row, and each column corresponds to a student. In this way, the results of each student queried under each primary key attribute can be stored in the corresponding row to obtain a query result report.
[0146] Optionally, in the above step S103, a corresponding thread is assigned to each computing unit, and the query result of each computing unit is obtained in parallel through the corresponding thread, which may include: determining the thread to be assigned to each computing unit according to each computing unit and the second mapping table, and assigning each computing unit to the corresponding thread; obtaining the query result of each computing unit through parallel processing of the threads corresponding to each computing unit; the second mapping table is used to record the mapping relationship between the computing unit and each thread in the thread pool.
[0147] In one achievable manner, when each computing unit is assigned to a corresponding thread in the thread pool, the thread to which each computing unit should be assigned can be determined according to each computing unit and the second mapping table, wherein the second mapping table is used to record the mapping relationship between different computing units and different threads.
[0148] In the initial state, the second mapping table is empty, and according to the continuous execution of the method, the mapping relationship between the computing unit and the thread can be continuously generated and recorded in the second mapping table to continuously improve the second mapping table. It is even possible to continuously update the mapping relationship between each computing unit and each thread in the second mapping table according to the actual situation in order to achieve the optimal computing time.
[0149] Figure 6 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Figure 6 As shown, according to each computing unit and the second mapping table, determining the thread to which each computing unit is to be allocated may include:
[0150] S601: If a target thread corresponding to a target computing unit is recorded in the second mapping table, determine that the target thread is a thread to be allocated to the target computing unit.
[0151] In some embodiments, when assigning a corresponding thread to each computing unit, the second mapping table may be queried first. If the corresponding relationship between the target computing unit and the target thread is recorded in the second mapping table, the target thread may be determined as the thread corresponding to the target computing unit, thereby assigning the target computing unit to the target thread for processing. The target computing unit may be any computing unit in each computing unit, and the target thread may be any thread in each thread.
[0152] S602: If the target thread corresponding to the target computing unit is not recorded in the second mapping table, add the target computing unit to the candidate set.
[0153] When the second mapping table does not record the thread corresponding to the target computing unit, the target computing unit can be added to the candidate set first. The candidate set is used to store all computing units that do not have corresponding threads in the second mapping table.
[0154] S603: Evenly distribute the computing units in the candidate set to the threads.
[0155] After the traversal of each computing unit is completed and the thread allocation is completed, each computing unit in the candidate set can be allocated. Optionally, each computing unit in the candidate set can be evenly distributed to each thread in the thread pool.
[0156] When the number of computing units in the candidate set is the same as the number of threads, one computing unit can be allocated to each thread; when the number of computing units in the candidate set is greater or less than the number of threads, they are allocated as evenly as possible to balance the computing pressure of each thread. For example: when there are 5 computing units and 3 threads, 2 computing units can be allocated to each of the two threads, and the remaining 1 computing unit can be allocated to the remaining 1 thread. Or when there are 3 computing units and 5 threads, 3 computing units can be allocated to the 3 threads with the smallest computing time.
[0157] Figure 7 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Figure 7 As shown, in step S103, corresponding threads are respectively allocated to each computing unit, and query results of each computing unit are obtained in parallel through the corresponding threads, including:
[0158] S701. Allocate each computing unit to a corresponding thread in a thread pool, and generate an initial task set corresponding to each thread.
[0159] Optionally, after allocating the computing units, an initial task set corresponding to each thread may be obtained, and the initial task set corresponding to the thread includes all computing units allocated to the thread.
[0160] S702: Add a primary key attribute of the result report to the initial task set corresponding to each thread to obtain an intermediate task set corresponding to each thread.
[0161] Add the primary key attribute of the result report to the initial task set corresponding to each thread. When the primary key attribute of the result report is determined, the primary key attribute added here is determined. By adding the primary key attribute of the result report to the initial task set corresponding to each thread, the thread can be indicated what to query when performing a query. If the primary key attribute is not added, the thread is not clear about what specific information to query for the computing unit. The primary key attribute indicates what specific information to query for each computing unit. The primary key attribute can include one or more, which can be set according to the query requirements.
[0162] S703 . Reorganize tasks according to the intermediate task sets corresponding to each thread to obtain a target task set corresponding to each thread, where the target task set includes query statements corresponding to each computing unit.
[0163] For a thread to execute a query task, it needs to execute an SQL statement. Therefore, it is also necessary to reorganize the query task corresponding to each thread according to the intermediate task set corresponding to each thread to obtain the target task set corresponding to each thread.
[0164] S704: Write the target task set corresponding to each thread into the thread queue, start the thread pool, and execute the target task set corresponding to each thread in parallel.
[0165] Write the target task set corresponding to each thread into the thread queue. After starting the thread pool, you can start multi-threaded query. By executing the target task set corresponding to each thread in parallel, you can get the query results corresponding to each thread. At the same time, the query time of each thread can be recorded to optimize the mapping relationship between computing units and threads in the later stage.
[0166] Figure 8 A flowchart of another data query method provided in an embodiment of the present application; Figure 8 As shown, in step S104, determining the query result of the query statement according to the query results of each computing unit and the computing logic of the query statement may include:
[0167] S801. According to the query results of each calculation unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, the query results of each calculation unit are written into the corresponding position in the result report to obtain the initial data query results.
[0168] For an SQL query, it essentially returns a two-dimensional table, called a result report. The purpose of this solution is to use multi-threading to solve the time-consuming problem of complex queries. Therefore, if you want to confirm the location of a returned result, you need to know its rows and columns. Therefore, in order to ensure that the query results of each thread can be assembled to the corresponding position, it is necessary to first query the primary key attributes of the result report, and then establish a mapping relationship between the primary key attributes and the rows in the result report based on the returned results; then, based on the fields, establish a mapping relationship between the fields and the columns. The fields here can be specific to the calculation unit, and the query results of a calculation unit are stored in a column.
[0169] It has been explained in the above embodiments that the query results of each computing unit include the query results of the computing unit under each primary key attribute, and the primary key attribute has a corresponding relationship with the row. Therefore, according to the corresponding relationship between the primary key attribute and the row, the query results of the computing unit under each primary key attribute can be recorded in the corresponding row. According to the corresponding relationship between the computing unit and the column, the column corresponding to the query result of the computing unit under the primary key attribute is determined, so that the query results of each computing unit are written into the corresponding position in the result report to obtain the initial data query result. The reason why it is called the initial data query result is that only the query results of each computing unit in the query statement are obtained.
[0170] S802: Obtain the query result of the query statement according to the initial data query result and the calculation logic of the query statement.
[0171] According to the query results of each calculation unit in the initial data query result and the calculation logic of each calculation unit in the query statement, the query results of each calculation unit can be recombined and calculated to obtain the query result of the query statement.
[0172] Fig. 9 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Fig. 9 As shown, in step S801, according to the query results of each calculation unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, the query results of each calculation unit are written into the corresponding position in the result report to obtain the initial data query results, which may include:
[0173] S901. Determine the row to which the query result of each calculation unit belongs in the result report according to the correspondence between the primary key attribute and the row.
[0174] According to the correspondence between the primary key attributes and the rows, the row to which the query result of the calculation unit under each primary key attribute belongs can be determined.
[0175] S902: Determine the column to which each calculation unit belongs in the result report according to the correspondence between the fields and the columns.
[0176] According to the correspondence between fields and columns, the column to which the query result of the calculation unit belongs in the result report can be determined, and the query result of a calculation unit can occupy a column in the result report, where each row of the column stores the query result of the calculation unit under different primary key attributes.
[0177] S903. Write the query results of each computing unit into corresponding positions in the result report according to the rows to which the query results of each computing unit belong in the result report and the columns to which the query results of each computing unit belong in the result report.
[0178] Then, based on the rows to which the primary key attributes of the calculation unit belong in the result report, and the columns to which the calculation unit belongs in the result report, the position of the query result of the calculation unit under each primary key attribute in the result report can be uniquely determined, thereby writing the query result of the calculation unit to the corresponding position in the result report.
[0179] Assume that the calculation units include calculation unit 1, calculation unit 2, and calculation unit 3; the primary key attributes include: attribute 1, attribute 2, and attribute 3; calculation unit 1 corresponds to the first column, calculation unit 2 corresponds to the second column, calculation unit 3 corresponds to the third column, attribute 1 corresponds to the first row, attribute 2 corresponds to the second row, and attribute 3 corresponds to the third row; the result report is shown in Table 1 below:
[0180] Table 1
[0181]
[0182] This embodiment also provides two optimization schemes to optimize the mapping relationship between computing units and threads based on the query results of threads, so that in the subsequent computing unit allocation process, the allocation result is better and the query time of each thread can be optimized.
[0183] Fig.10 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Fig.10 As shown, in step S103, allocating corresponding threads to each computing unit may include:
[0184] S1001. Determine a row splitting ratio when the thread executes a next computing unit query task according to an average query task consumption of the thread and a query task consumption of the thread in the current computing unit.
[0185] Taking a thread as an example, in one implementable method, the query task time generated each time the thread executes a query task of a computing unit will be recorded. Then, the average query task time of the thread can be calculated based on the query task time generated when the thread executes the query task of each computing unit and the number of executed computing units.
[0186] Therefore, the row splitting ratio when the thread executes the next computing unit query task can be calculated based on the average query task time of the thread and the time taken by the thread to execute the current computing unit query task, and the row splitting ratio corresponding to the thread can be recorded.
[0187] S1002. Split the next computing unit query task of the thread into multiple subtasks according to the row splitting ratio when the thread executes the next computing unit query task.
[0188] Then, when executing the next computing unit query task, the thread can first query whether there is a record of the row split ratio. If yes, the next computing unit query task to be executed can be split into multiple subtasks according to the row split ratio.
[0189] Optionally, the row splitting ratio may be used to determine the number of subtasks that can be split accordingly. For example, if the row splitting ratio is 3, the next computing unit query task may be split into 3 subtasks.
[0190] Assuming that the query result that the computing unit needs to query includes the query results under 6 primary key attributes, the query task of the computing unit under the 6 primary key attributes can be divided into 3 subtasks, and the query task under 2 primary key attributes can be divided into one subtask.
[0191] S1003: Allocate each subtask to a corresponding thread according to the idle state and / or processing capability of each thread.
[0192] Optionally, each subtask may be allocated to a corresponding thread according to the current idle state and / or processing capability of each thread.
[0193] Among them, one subtask can be assigned to the thread originally corresponding to the computing unit for processing, and the remaining subtasks can be assigned to the currently idle threads or threads with higher processing efficiency for processing, so as to balance the processing burden of each thread and optimize the total processing time.
[0194] Fig.11 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Fig.11 As shown, in step S103, corresponding threads are allocated to each computing unit respectively, including:
[0195] S1101 . Generate a mapping relationship between each computing unit and each thread according to the processing time consumed by each computing unit and the current total time consumed by each thread.
[0196] In another feasible method, idle time update or independent server can be used to process each computing unit first to obtain the processing time of each computing unit, and then the greedy algorithm is used to update the thread corresponding to each computing unit.
[0197] Optionally, a mapping relationship between each computing unit and each thread may be generated first according to the recorded processing time consumption of each computing unit and the current total time consumption of each thread.
[0198] The current total time consumption of each thread may be the total time consumption of the query tasks currently executed by each thread. As the tasks are continuously executed, the total time consumption of the thread increases continuously.
[0199] S1102. Allocate corresponding threads to the computing units according to the mapping relationship between the computing units and the threads.
[0200] Optionally, the second mapping table stores mapping relationships between computing units and threads, and based on the optimization method of this embodiment, the generated mapping relationships between computing units and threads can be used as the latest mapping relationships to update the mapping relationships between computing units and threads stored in the second mapping table.
[0201] Therefore, when allocating computing units to threads, the latest mapping relationship may be read from the second mapping table for allocation.
[0202] Fig.12 A flowchart of another data query method provided in an embodiment of the present application; optionally, as Fig.12 As shown, in step S1101, generating a mapping relationship between each computing unit and each thread according to the processing time of each computing unit and the current total time of each thread may include:
[0203] S1201. Sort the computing units according to the processing time consumed by each computing unit.
[0204] The computing units may be sorted first according to the processing time consumed by each computing unit. The sorting may be from large to small or from small to large, without limitation.
[0205] S1202 . Allocate each computing unit to the thread with the shortest total time consumption in sequence according to the sorting result of each computing unit, and generate a mapping relationship between each computing unit and the thread to which it is allocated.
[0206] According to the sorting results, each computing unit can be allocated to the thread with the shortest total time in turn, and after the computing unit is allocated to the thread, the current total time of the thread is updated. Through this allocation method, the global time consumption of the multi-threaded task can be guaranteed to be locally minimized.
[0207] Assume that the computing units are computing unit 1, computing unit 2, computing unit 3, computing unit 4, and computing unit 5; the processing time of computing unit 1 is 5, the processing time of computing unit 2 is 3, the processing time of computing unit 3 is 8, the processing time of computing unit 4 is 10, and the processing time of computing unit 5 is 7; the threads are thread 1, thread 2, and thread 3. Initially, the total time consumed by thread 1, thread 2, and thread 3 is 0.
[0208] After sorting the computing units in descending order of processing time, we can get the sequence: {computing unit 4, computing unit 3, computing unit 5, computing unit 1, computing unit 2}; computing unit 4 can be assigned to thread 1 first. At this time, the total time consumption of thread 1 becomes 10, then computing unit 3 can be assigned to thread 2 or thread 3. Assuming that computing unit 3 is assigned to thread 2, the total time consumption of thread 2 becomes 8; next, computing unit 5 is assigned to thread 3, and the total time consumption of thread 3 becomes 7; according to the total time consumption of each thread, the total time consumption of thread 3 is currently the smallest, so computing unit 1 is assigned to thread 3, and the total time consumption of thread 3 reaches 12; the total time consumption of thread 2 is currently the smallest, so computing unit 2 is assigned to thread 2, and the total time consumption of thread 2 becomes 11; and so on, the next computing unit is assigned to thread 1, and by continuing to execute, the threads corresponding to each computing unit can be determined.
[0209] This method can optimize the allocation relationship between computing units and threads by providing two optimization methods, so that at any time, the total processing time of each thread in the thread pool can reach a global minimum, thereby reducing resource consumption and improving processing efficiency.
[0210] In summary, the data query method provided in this embodiment includes: parsing the query statement to obtain at least one statement field in the query statement; determining multiple computing units corresponding to the query statement according to the type of each statement field; assigning corresponding threads to each computing unit, and obtaining the query results of each computing unit in parallel through the corresponding threads; determining the query results of the query statement according to the query results of each computing unit and the calculation logic of the query statement. The present application method can split the statement field according to the type of the statement field by identifying the statement field in the query statement, and obtain multiple computing units corresponding to the query statement. By splitting the query statement into the smallest computing unit field that cannot be split, and querying each computing unit, the additional resource consumption caused by the repeated calculations of different fields in the query statement can be effectively reduced. Among them, only the splitting strategy needs to be configured, and the different types of statement fields can be automatically split according to the configured splitting strategy to obtain the computing units corresponding to the query statement, and the splitting process is automatically realized, and the effect is higher. By assigning each computing unit to the corresponding thread for parallel processing, compared with the method of executing multiple subtasks multiple times by one thread, multi-threaded parallel execution is adopted, and the computing efficiency is significantly improved. After the computing unit is allocated to the thread, the execution of the thread can be triggered without any triggering restrictions, and the implementation of the solution is more stable.
[0211] In addition, the allocation relationship between computing units and threads is optimized based on the query time of threads, so that at any time, the total processing time of each thread in the thread pool can reach the global optimum, thereby improving processing efficiency.
[0212] The following describes the apparatus, device, storage medium, etc. used to execute the data query method provided by the present application. The specific implementation process and technical effects are as mentioned above and will not be described in detail below.
[0213] Fig.13 Schematic diagram of a data query device provided in an embodiment of the present application, the functions implemented by the data query device correspond to the steps performed by the above method. Fig.13 As shown, the device may include: an analysis module 130, a determination module 131, and a processing module 132;
[0214] The parsing module 130 is used to parse the query statement to obtain at least one statement field in the query statement;
[0215] A determination module 131 is used to determine a plurality of computing units corresponding to the query statement according to the type of each statement field, wherein the type of the statement field includes: a first type or a second type, the complexity corresponding to the second type is less than the complexity corresponding to the first type, and each computing unit is an inseparable field in the query statement;
[0216] The processing module 132 is used to assign corresponding threads to each computing unit, and obtain the query results of each computing unit in parallel through the corresponding threads;
[0217] The processing module 132 is used to determine the query result of the query statement according to the query results of each computing unit and the calculation logic of the query statement.
[0218] Optionally, the determination module 131 is specifically configured to, if the type of the statement field is the first type, decompose the statement field to obtain a plurality of computing units corresponding to the statement field;
[0219] If the type of the statement field is the second type, the statement field is taken as a calculation unit.
[0220] Optionally, the determination module 131 is specifically used to determine whether to obtain multiple computing units corresponding to the statement field from the first mapping table according to the statement field and the created first mapping table; the first mapping table is used to record the mapping relationship between the first type of statement field and the split computing unit;
[0221] If yes, then according to the statement field, obtain multiple computing units corresponding to the statement field from the first mapping table;
[0222] If not, the statement field is split according to a preset splitting strategy to obtain multiple calculation units corresponding to the statement field.
[0223] Optionally, the determination module 131 is specifically configured to query whether a statement field exists in the first mapping table according to the statement field;
[0224] If there is a statement field in the first mapping table, determining whether the check value of the statement field is consistent with the reference check value of the statement field recorded in the first mapping table;
[0225] If they are consistent, multiple computing units corresponding to the statement fields are obtained from the first mapping table.
[0226] Optionally, the determination module 131 is specifically configured to obtain the split computing unit corresponding to the statement field from the first mapping table according to the statement field;
[0227] The split calculation unit corresponding to the statement field is determined as the calculation unit corresponding to the statement field.
[0228] Optionally, the determination module 131 is specifically configured to split the statement field according to each operation logic symbol contained in the statement field to obtain a plurality of calculation units corresponding to the statement field;
[0229] The mapping relationship between the statement field and each calculation unit obtained by splitting and the mapping relationship between the statement field and the corresponding calculation logic are recorded in the first mapping table.
[0230] Optionally, the processing module 132 is specifically used to assign each computing unit to a corresponding thread in the thread pool, and perform query processing in parallel through each thread to obtain a query result corresponding to each thread; the query result corresponding to each thread includes: the query result of each computing unit to which each thread is assigned; the query result of each computing unit includes the query result of the computing unit under each primary key attribute.
[0231] Optionally, the processing module 132 is specifically used to determine the thread to which each computing unit is to be assigned according to each computing unit and a second mapping table; the second mapping table is used to record the mapping relationship between the computing unit and each thread in the thread pool;
[0232] The query results of each computing unit are obtained by parallel processing of the threads corresponding to each computing unit.
[0233] Optionally, the processing module 132 is specifically configured to determine that the target thread is a thread to be allocated to the target computing unit if a target thread corresponding to the target computing unit is recorded in the second mapping table;
[0234] If the target thread corresponding to the target computing unit is not recorded in the second mapping table, the target computing unit is added to the candidate set;
[0235] Allocate the computational units in the candidate set to each thread evenly.
[0236] Optionally, the processing module 132 is specifically configured to assign each computing unit to a corresponding thread in the thread pool and generate an initial task set corresponding to each thread;
[0237] Add the primary key attribute of the result report to the initial task set corresponding to each thread, and obtain the intermediate task set corresponding to each thread;
[0238] According to the intermediate task set corresponding to each thread, tasks are reorganized to obtain the target task set corresponding to each thread, wherein the target task set includes the query statements corresponding to each computing unit;
[0239] The target task set corresponding to each thread is written into the thread queue, the thread pool is started, and the target task set corresponding to each thread is executed in parallel.
[0240] Optionally, the processing module 132 is specifically configured to write the query results of each computing unit into corresponding positions in the result report according to the query results of each computing unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, so as to obtain an initial data query result;
[0241] The query result of the query statement is obtained according to the initial data query result and the calculation logic of the query statement.
[0242] Optionally, the processing module 132 is specifically configured to determine the row to which the query result of each computing unit belongs in the result report according to the correspondence between the primary key attribute and the row;
[0243] According to the correspondence between fields and columns, determine the column to which each calculation unit belongs in the result report;
[0244] According to the row to which the query result of each computing unit belongs in the result report and the column to which the query result of each computing unit belongs in the result report, the query result of each computing unit is written into the corresponding position in the result report.
[0245] Optionally, the processing module 132 is specifically configured to determine a row splitting ratio when the thread executes a next computing unit query task according to an average query task time of the thread and a time taken by the thread to execute a current computing unit query task;
[0246] Splitting the next computing unit query task of the thread into multiple subtasks according to the row splitting multiple when the thread executes the next computing unit query task;
[0247] Each subtask is assigned to a corresponding thread according to the idle state and / or processing capability of each thread.
[0248] Optionally, the processing module 132 is specifically configured to generate a mapping relationship between each computing unit and each thread according to the processing time consumed by each computing unit and the current total time consumed by each thread;
[0249] According to the mapping relationship between each computing unit and each thread, a corresponding thread is allocated to each computing unit.
[0250] Optionally, the processing module 132 is specifically configured to sort the computing units according to the processing time consumed by each computing unit;
[0251] According to the sorting results of each computing unit, each computing unit is sequentially allocated to the thread with the smallest total time consumption, and a mapping relationship between each computing unit and the allocated thread is generated.
[0252] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0253] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital singnal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0254] The above modules can be connected or communicated with each other via a wired connection or a wireless connection. The wired connection may include a metal cable, an optical cable, a hybrid cable, etc., or any combination thereof. The wireless connection may include a connection in the form of a LAN, a WAN, Bluetooth, a ZigBee, or NFC, or any combination thereof. Two or more modules may be combined into a single module, and any one module may be divided into two or more units. Those skilled in the art will clearly understand that for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application.
[0255] Fig.14 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, which may be a computing device with data processing capabilities.
[0256] The device may include: a processor 801 and a storage medium 802 .
[0257] The storage medium 802 is used to store programs, and the processor 801 calls the programs stored in the storage medium 802 to execute the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.
[0258] The storage medium 802 stores program code, and when the program code is executed by the processor 801, the processor 801 executes various steps of the data query method according to various exemplary embodiments of the present application described in the above “Exemplary Method” section of this specification.
[0259] The processor 801 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and may implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0260] The storage medium 802, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The storage medium may include at least one type of storage medium, for example, a flash memory, a hard disk, a multimedia card, a card-type storage medium, a random access storage medium (Random Access Memory, RAM), a static random access storage medium (Static Random Access Memory, SRAM), a programmable read-only storage medium (Programmable Read Only Memory, PROM), a read-only storage medium (Read Only Memory, ROM), an electrically erasable programmable read-only storage medium (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic storage medium, a disk, an optical disk, and the like. The storage medium is any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The storage medium 802 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0261] Optionally, the present application also provides a program product, such as a computer-readable storage medium, including a program, which is used to execute the above method embodiment when executed by a processor.
[0262] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0263] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0264] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0265] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only storage medium (English: Read-Only Memory, referred to as: ROM), random access storage medium (English: Random Access Memory, referred to as: RAM), disk or optical disk and other media that can store program codes.
Claims
1. A data query method, characterized in that: include: Parsing the query statement to obtain at least one statement field in the query statement; Determine, according to the type of each of the statement fields, a plurality of computing units corresponding to the query statement, wherein the type of the statement field includes: a first type or a second type, the complexity corresponding to the second type is less than the complexity corresponding to the first type, and each of the computing units is an inseparable field in the query statement; Allocating corresponding threads to each of the computing units respectively, and obtaining query results of each of the computing units in parallel through the corresponding threads; Determining the query result of the query statement according to the query results of each of the computing units and the computing logic of the query statement; The step of determining, according to the type of each of the statement fields, a plurality of computing units corresponding to the query statement includes: If the type of the statement field is the first type, judging whether to obtain multiple computing units corresponding to the statement field from the first mapping table according to the statement field and the created first mapping table; the first mapping table is used to record the mapping relationship between the statement field of the first type and the split computing units; If so, then based on the statement field, multiple computing units corresponding to the statement field are obtained from the first mapping table; if not, then the statement field is split according to a preset splitting strategy to obtain multiple computing units corresponding to the statement field.
2. The data query method according to claim 1, characterized in that: The step of determining, according to the type of each of the statement fields, a plurality of computing units corresponding to the query statement includes: If the type of the statement field is the second type, the statement field is used as a calculation unit.
3. The data query method according to claim 1, characterized in that: The determining, based on the statement field and the created first mapping table, whether to obtain multiple computing units corresponding to the statement field from the first mapping table includes: According to the statement field, querying whether the statement field exists in the first mapping table; If the statement field exists in the first mapping table, determining whether the check value of the statement field is consistent with the reference check value of the statement field recorded in the first mapping table; If they are consistent, multiple computing units corresponding to the statement fields are obtained from the first mapping table.
4. The data query method according to claim 1, characterized in that: The step of respectively allocating corresponding threads to the computing units and obtaining query results of the computing units in parallel through the corresponding threads includes: According to each computing unit and a second mapping table, determining the thread to which each computing unit is to be assigned, and assigning each computing unit to a corresponding thread; the second mapping table is used to record the mapping relationship between the computing unit and each thread in the thread pool; The query results of each computing unit are obtained by parallel processing of threads corresponding to each computing unit.
5. The data query method according to claim 4, characterized in that: The step of determining the thread to which each computing unit is to be allocated according to each computing unit and the second mapping table includes: If a target thread corresponding to the target computing unit is recorded in the second mapping table, determining that the target thread is the thread to be allocated to the target computing unit; If the target thread corresponding to the target computing unit is not recorded in the second mapping table, adding the target computing unit to the candidate set; The computing units in the candidate set are evenly distributed to the threads.
6. The data query method according to claim 1, characterized in that: The step of respectively allocating corresponding threads to the computing units and obtaining query results of the computing units in parallel through the corresponding threads includes: Allocate each computing unit to the corresponding thread in the thread pool, and generate an initial task set corresponding to each thread; Add the primary key attribute of the result report to the initial task set corresponding to each thread, and obtain the intermediate task set corresponding to each thread; Reorganize tasks according to the intermediate task set corresponding to each thread to obtain the target task set corresponding to each thread, wherein the target task set includes the query statement corresponding to each computing unit; The target task set corresponding to each thread is written into the thread queue, the thread pool is started, and the target task set corresponding to each thread is executed in parallel.
7. The data query method according to claim 1, characterized in that: Determining the query result of the query statement according to the query results of each of the computing units and the computing logic of the query statement includes: According to the query results of each calculation unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, the query results of each calculation unit are written into the corresponding position in the result report to obtain the initial data query results; The query result of the query statement is obtained according to the initial data query result and the calculation logic of the query statement.
8. The data query method according to claim 7, characterized in that: According to the query results of each computing unit and the correspondence between the primary key attribute and the row and the correspondence between the field and the column in the pre-created result report, the query results of each computing unit are written into the corresponding position in the result report to obtain the initial data query results, including: According to the correspondence between the primary key attribute and the row, determining the row to which the query result of each calculation unit belongs in the result report; According to the correspondence between fields and columns, determining the column to which each calculation unit belongs in the result report; The query results of each computing unit are written into corresponding positions in the result report according to the rows to which the query results of each computing unit belong in the result report and the columns to which the query results of each computing unit belong in the result report.
9. The data query method according to claim 1, characterized in that: The allocating corresponding threads to the computing units respectively comprises: Determine the row splitting ratio when the thread executes the next computing unit query task according to the average query task time of the thread and the time taken by the thread to execute the query task of the current computing unit; Splitting the next computing unit query task of the thread into multiple subtasks according to the row splitting multiple when the thread executes the next computing unit query task; Each subtask is assigned to a corresponding thread according to the idle state and / or processing capability of each thread.
10. The data query method according to claim 1, characterized in that: The allocating corresponding threads to the computing units respectively comprises: Generate a mapping relationship between each computing unit and each thread according to the processing time of each computing unit and the current total time of each thread; According to the mapping relationship between each computing unit and each thread, a corresponding thread is allocated to each computing unit.
11. The data query method according to claim 10, characterized in that: The generating a mapping relationship between each computing unit and each thread according to the processing time of each computing unit and the current total time of each thread includes: Sort the computing units according to their processing time. According to the sorting results of each computing unit, each computing unit is sequentially allocated to the thread with the smallest total time consumption, and a mapping relationship between each computing unit and the allocated thread is generated.
12. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the program instructions to implement the data query method as described in any one of claims 1 to 11.
13. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the data query method according to any one of claims 1 to 11 is implemented.
14. A computer program product, characterized in that The computer program product comprises a computer program code. When the computer program code is executed by a computing device, the computing device executes the data query method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Task splitting method and device of data exchange system
CN110597618A
Database query interface engine based on XML template
CN111752542A
Data query method and device, electronic equipment and storage medium
CN111782923A
Query statement generation method and device
CN116467499A
Data query method and device, storage medium and electronic equipment
CN116521705A
