A data query method and device, a storage medium and an electronic device
By parsing the data query statement and selecting a parallel extension template to generate subquery statements for parallel execution, the problem of complex operators not being able to be pushed down to the database for parallel execution is solved, thus improving data query efficiency.
Patent Information
- Application Number
- CN202310377466.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-10
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2043-04-10
AI Technical Summary
In existing technologies, complex operators in data query statements, such as the Join operator and the Aggregate operator in multi-table join queries, cannot be pushed down to the database for parallel execution, resulting in low data query efficiency.
By parsing the data query statement, the target operator and target data table are determined, a parallel expansion template is selected, subquery statements are generated, and each subquery statement is executed in parallel to perform data query in the database.
It improves the efficiency of data querying, avoids the problems of memory overflow and long data transmission time of a single database node, and realizes parallel execution of the database.
Smart Images

Figure CN116521705B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a data query method, apparatus, storage medium, and electronic device. Background Technology
[0002] Currently, because data processing systems (such as Spark) employ clustered or distributed big data computing engines, these systems are commonly used in machine learning, big data analytics, and other fields to perform complex data processing tasks on large datasets at high speed. For example, a data processing system might obtain a user's input query, retrieve the necessary data for machine learning or big data analysis from a data source system, and then perform inference and prediction based on the obtained data to obtain the prediction result.
[0003] When performing complex processing of large amounts of data through a data processing system, the system analyzes the user-input data query statement to determine the operators required to execute the query. For basic operators, such as Scan or Relation operators used to scan data in database tables, and Filter operators used to filter data based on conditions, the system can translate them into SQL-style subqueries, send them to the database for execution, and then obtain the data returned by the database after execution. Further data processing is then performed based on the obtained data.
[0004] When a data processing system performs a data query task, there may be a situation where the table to be queried contains a large amount of data. In this case, the task of querying the data in the table can be split into multiple subtasks and executed in parallel.
[0005] However, the current data query method cannot push down complex operators contained in the query statement (such as the Join operator for multi-table join queries, the Aggregate operator, etc.) to the database for parallel execution. Summary of the Invention
[0006] This specification provides a data query method, apparatus, storage medium, and electronic device to solve the problem in the prior art that complex operators contained in query statements cannot be pushed down to the database for parallel execution.
[0007] The following technical solution is adopted in this specification:
[0008] This manual provides a data query method, including:
[0009] Retrieve data query statement;
[0010] The data query statement is parsed to determine an operator of a specified type from the operators contained in the data query statement, which is used as the target operator, and to determine the data table storing the data to be queried corresponding to the data query statement, which is used as the target data table.
[0011] From the preset parallel expansion templates, determine the parallel expansion template that matches the number of the target operator and the target data table, and use it as the target parallel expansion template;
[0012] Based on the target parallel expansion template, the specified field is determined from the fields contained in the target data table;
[0013] Based on the specified fields, generate the subquery statements corresponding to the data query statement;
[0014] Each subquery statement is executed in parallel to perform data queries in the database.
[0015] Optionally, based on the target parallel expansion template, a specified field is determined from the fields contained in the target data table, specifically including:
[0016] If the target operator in the data query statement is a join operator, then according to the target parallel expansion template, the condition fields with index constraints are determined from the condition fields required to execute the join operator contained in the target data table, and used as candidate specified fields.
[0017] The specified field is determined from the candidate specified fields.
[0018] Optionally, the specified field is determined from the candidate specified fields, specifically including:
[0019] If the number of join operators is greater than 1, then the specified field is determined from each candidate specified field based on the amount of data contained in each candidate specified field;
[0020] If the number of join operators is 1, then any one of the candidate specified fields is selected as the specified field.
[0021] Optionally, based on the target parallel expansion template, a specified field is determined from the fields contained in the target data table, specifically including:
[0022] If the target operator contained in the data query statement is the Aggregate operator, then according to the target parallel expansion template, the condition fields with index constraints are determined from the condition fields required to execute the Aggregate operator contained in the target data table, and used as each candidate specified field.
[0023] Select any one of the candidate specified fields as the specified field.
[0024] Optionally, based on the target parallel expansion template, a specified field is determined from the fields contained in the target data table, specifically including:
[0025] If the target operators in the data query statement are Aggregate and join operators, then according to the target parallel expansion template, it is determined whether there are any fields in the target data table that have index constraints and are the same as the condition fields in the target data table that are required to execute the Aggregate operator.
[0026] If so, use the same fields as the specified fields;
[0027] If not, then any one of the condition fields in the target data table required to execute the Aggregate operator will be used as the specified field.
[0028] Optionally, the method further includes:
[0029] If the data query statement does not contain a target operator, then the field corresponding to the query condition contained in the data query statement will be used as the specified field.
[0030] Optionally, based on the specified field, subquery statements corresponding to the data query statement are generated, specifically including:
[0031] Determine the range of values contained in the specified field;
[0032] Determine the number of each subquery statement to be generated, and use that as the target number;
[0033] Based on the target quantity, the value range is divided equally to obtain each sub-value range;
[0034] Based on the range of each sub-value domain, generate each sub-query statement corresponding to the data query statement.
[0035] Optionally, based on the specified field, subquery statements corresponding to the data query statement are generated, specifically including:
[0036] Determine the range of values contained in the specified field;
[0037] Determine the number of each subquery statement to be generated, and use that as the target number;
[0038] The range of each sub-value domain is determined based on the number of values contained in the specified field and the target number;
[0039] Based on the range of each sub-value domain, generate each sub-query statement corresponding to the data query statement.
[0040] This specification provides a data query device, including:
[0041] The retrieval module is used to retrieve data query statements;
[0042] The parsing module is used to parse the data query statement to determine an operator of a specified type from the operators contained in the data query statement as the target operator, and to determine the data table storing the data to be queried corresponding to the data query statement as the target data table.
[0043] The first determining module is used to determine, from the preset parallel extension templates, a parallel extension template that matches the number of the target operator and the target data table, and use it as the target parallel extension template;
[0044] The second determining module is used to determine a specified field from the fields contained in the target data table based on the target parallel extension template.
[0045] The generation module is used to generate sub-query statements corresponding to the data query statement based on the specified field;
[0046] The execution module is used to execute each subquery statement in parallel to perform data queries in the database.
[0047] Optionally, the second determining module is specifically used to: if the target operator contained in the data query statement is a join operator, then, according to the target parallel extension template, determine the condition fields with index constraints from the condition fields required to execute the join operator contained in the target data table, as each candidate specified field; and determine the specified field from each candidate specified field.
[0048] Optionally, the second determining module is specifically used to: if the number of join operators is greater than 1, determine the specified field from each candidate specified field based on the amount of data contained in each candidate specified field; if the number of join operators is 1, select any condition field from each candidate specified field as the specified field.
[0049] Optionally, the second determining module is specifically used to: if the target operator contained in the data query statement is an Aggregate operator, then, according to the target parallel expansion template, determine the condition fields with index constraints from the condition fields required to execute the Aggregate operator contained in the target data table, and use them as candidate specified fields; and select any one of the condition fields from the candidate specified fields as the specified field.
[0050] Optionally, the second determining module is specifically used to, if the target operator contained in the data query statement is an Aggregate or a join operator, determine, according to the target parallel expansion template, whether there exists a field with an index constraint among the condition fields required to execute the Aggregate operator contained in the target data table that is the same as the condition fields required to execute the join operator contained in the target data table; if yes, use the same field as the specified field; if no, use any one of the condition fields required to execute the Aggregate operator contained in the target data table as the specified field.
[0051] Optionally, the second determining module is further configured to, if the data query statement does not contain a target operator, use the field corresponding to the query condition contained in the data query statement as the specified field.
[0052] Optionally, the generation module is specifically used to: determine the value range of the values contained in the specified field; determine the number of each subquery statement to be generated as the target number; divide the value range equally according to the target number to obtain each sub-value range; and generate each subquery statement corresponding to the data query statement according to each sub-value range.
[0053] Optionally, the generation module is specifically used to: determine the value range of the values contained in the specified field; determine the number of each subquery statement to be generated as the target number; determine the range of each sub-value range based on the number of values contained in the specified field and the target number; and generate each subquery statement corresponding to the data query statement based on the range of each sub-value range.
[0054] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described data query method.
[0055] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described data query method.
[0056] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0057] The data query method provided in this specification first obtains a data query statement, parses the data query statement to determine a specified type of operator from the operators contained in the data query statement as the target operator, and determines the data table storing the data to be queried corresponding to the data query statement as the target data table. Then, it determines a parallel extension template from each parallel extension template that matches the number of target operators and target data tables as the target parallel extension template. Based on the target parallel extension template, it determines a specified field from the fields contained in the target data table. Based on the specified field, it generates each subquery statement corresponding to the data query statement and executes each subquery statement in parallel to perform data query in the database.
[0058] As can be seen from the above method, by using the complex operators contained in the data query statement as the specified operators, the specified fields can be determined from the condition fields required to execute the target operator according to the preset execution strategy. The task of querying data for the specified fields can be divided into multiple sub-tasks, and a subquery statement for querying each sub-task can be generated. In this way, the database can execute each subquery statement in parallel to improve the data query efficiency. Attached Figure Description
[0059] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:
[0060] Figure 1 This is a flowchart illustrating a data query method provided in this specification;
[0061] Figure 2 This is a diagram illustrating a data query statement and its subqueries provided in this specification.
[0062] Figure 3 This is a schematic diagram of a data query device provided in this specification;
[0063] Figure 4 This specification provides a corresponding Figure 1 A schematic diagram of an electronic device. Detailed Implementation
[0064] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0065] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0066] Figure 1 This is a flowchart illustrating a data query method provided in this specification, including the following steps:
[0067] S100: Data retrieval query statement.
[0068] In this manual, when users need to perform complex data processing such as big data analysis and machine learning, they can input a data query statement to retrieve data from a data source system into the data processing system installed on their device. The data processing system can then execute the corresponding data query task through the data source system based on the data query statement obtained by the data processing system, and perform corresponding data processing on the retrieved data. Here, the data source system can refer to database systems such as MySQL, Oracle, and SQL Server.
[0069] In this specification, the executing entity used to implement the data query method can refer to a specified device such as a server set up in the data processing system, or a specified device such as a desktop computer or a laptop computer. For ease of description, the following description will only use the server as the executing entity to illustrate the data query method provided in this specification.
[0070] S102: Parse the data query statement to determine an operator of a specified type from the operators contained in the data query statement as the target operator, and determine the data table storing the data to be queried corresponding to the data query statement as the target data table.
[0071] Furthermore, after obtaining the data query statement, the server can parse it to determine the operators contained within it. Then, it can identify operators of a specific type as target operators and the data table containing the data to be queried corresponding to the data query statement as the target data table. The data query statement can be written in programming languages such as Java, Scala, Python, R, and SQL. The operators can be code used to perform specific actions in each step of the data query process, including: operators like Scan or Relation for scanning data in tables stored in the database; operators like Filter for filtering data; operators like Join for joining tables in multiple databases; and operators like Aggregate for grouping and / or filtering data by group.
[0072] Specifically, after the server obtains the data query statement input by the user, it can obtain the logical execution plan corresponding to the data query statement by performing lexical analysis, semantic analysis, and syntax analysis on the obtained data query statement. Based on the determined logical execution plan, the server can determine the operators contained in the data query statement.
[0073] For example, suppose the user inputs a data query statement as "select * from user where userName = 'Mr. Zhang'". During the execution of this query, the first operator used is the `from` operator to locate the data table (i.e., the `user` table which stores user data). In other words, the `from` operator determines which table to retrieve data from. After determining the data table using the `from` operator, the `scan` operator can be used to scan and retrieve all data in that table. Then, the `filter` operator, based on the condition `userName = "Mr. Zhang"`, can filter out the data corresponding to the user with the username "Mr. Zhang" from all the retrieved data in the table. Finally, the `project` or `select` operator, used to determine the query results, returns the data corresponding to the user with the username "Mr. Zhang", thus completing the data query operation.
[0074] Furthermore, after the server determines the operators contained in the data query statement, it can filter out operators of a specified type from the operators and use them as target operators. The specified type can refer to the type corresponding to complex operators, such as the join operator, the aggregate operator, etc.
[0075] S104: Determine a parallel extension template from each parallel extension template that matches the number of the target operator and the target data table, and use it as the target parallel extension template.
[0076] S106: Based on the target parallel extension template, determine the specified field from the fields contained in the target data table.
[0077] Furthermore, after determining the target operator contained in the obtained data query statement and the target data table, the server can determine the parallel extension template that matches the target operator and the target data table from each parallel extension template, and use it as the target parallel extension template. It can also determine the specified field from each field contained in the target data table based on the target parallel extension template.
[0078] Specifically, if the target operator in the data query statement is a join operator and the number of join operators is 1, then according to the target parallel extension template, the condition fields with index constraints can be determined from the condition fields required to execute the join operator in the target data table as candidate specified fields, and any one of the candidate specified fields can be selected as the specified field.
[0079] If the target operator in the data query statement is a join operator, and the number of join operators is greater than 1, then the indexed constraint condition fields can be determined from the condition fields required to execute the join operator in the target data table according to the target parallel extension template. These condition fields are then used as candidate specified fields. The specified field is determined from each candidate specified field based on the amount of data contained in each candidate specified field.
[0080] It should be noted that in practical applications, when the number of join operators is greater than 1, the number of target data tables to be joined by the join operators must be greater than 2. For example, suppose the data query statement is "Select * from A join Bon A.ID=B.ID join C on A.ID=C.ID". When executing this data query statement, the first join operator needs to be executed first to join table A and table B according to the condition "A.ID=B.ID" to obtain the query result. Then, the second join operator is executed to join the query results of table A and table B with table C according to the condition "A.ID=C.ID" to obtain the final query result.
[0081] When the first join operator is executed to connect tables A and B, table C is in a waiting state. Table C in a waiting state requires corresponding memory space, resulting in memory consumption. Based on this, when determining the specified field from each candidate specified field according to the amount of data contained in each candidate specified field, the candidate specified field with the largest amount of data can be selected as the specified field. This allows data query tasks for target data tables with a large amount of data and a large amount of memory space to be executed first, thereby reducing the memory space occupied by target data tables in a waiting state.
[0082] If the target operator in the data query statement is the Aggregate operator, then according to the target parallel expansion template, the condition fields with index constraints are determined from the condition fields required to execute the Aggregate operator contained in the target data table, and these are used as candidate specified fields. Then, any one of the condition fields is selected from the candidate specified fields as the specified field.
[0083] If the target operators in the data query statement are Aggregate and join operators, then based on the target parallel expansion template, it is determined whether there are indexed fields among the condition fields required to execute the join operator in the target data table. It is also determined whether there are any identical fields among the indexed fields among the condition fields required to execute the join operator in the target data table and among the condition fields required to execute the Aggregate operator in the target data table. If so, the identical fields are used as the specified fields; otherwise, any one of the condition fields required to execute the Aggregate operator in the target data table is used as the specified field.
[0084] If the data query statement does not contain a target operator, then the field corresponding to the query condition contained in the data query statement will be used as the specified field.
[0085] S108: Generate subquery statements corresponding to the data query statement based on the specified field.
[0086] Furthermore, after determining the specified field, the server can generate subquery statements corresponding to the data query statement based on the specified field. These subquery statements are used to query data for at least some of the values contained in the specified field.
[0087] One method for the server to generate subquery statements corresponding to the data query statement based on a specified field is as follows: the server can determine the value range of the values contained in the specified field, determine the number of subquery statements to be generated as the target number, divide the value range equally according to the target number to obtain each sub-value range, and generate each subquery statement corresponding to the data query statement based on each sub-value range.
[0088] The number of subquery statements to be generated can be determined according to actual needs. The value range is divided equally according to the number of subquery statements to be generated. For example, if the number of subquery statements to be generated is three, then the corresponding number of sub-value ranges to be divided is also three. If the value range of the specified field is [1, 60000], then the value range can be divided into three sub-value ranges: [1, 20000], [20001, 40000], and [40001, 60000]. The subquery statements corresponding to the data query statements are generated according to each sub-value range.
[0089] In addition, in practical applications, there is a significant deviation in the number of values in a specified field that fall within each sub-value range. For example, in the sub-value range [1, 20000], there may be 100 values out of all values contained in the specified field, while in the sub-value range [20001, 40000], there may be 5000 values out of all values contained in the specified field. This deviation will cause the query efficiency of each sub-query statement generated when generating the data query statement based on each sub-value range to be different, thereby reducing the overall efficiency of the data query statement.
[0090] Based on this, the server can also determine the range of each sub-value domain according to the number of values contained in the specified field and the target number, and generate each sub-query statement corresponding to the data query statement according to the range of each sub-value domain.
[0091] For example, assuming the specified field contains 10,000 values and there are 5 subqueries to be generated, the subquery range for the first subquery can be determined based on the range of the first 2,000 values in the specified field, say [1, 5000]. The subquery range for the second subquery can be determined based on the range of the 2001st to 4000th values in the specified field, say [5001, 23000]. The subquery range for the third subquery can be determined based on the range of the 4001st to 6000th values in the specified field, say [23001, 58000], and so on, to determine the subquery range for each subquery.
[0092] To further explain the above content in detail, the following explains how to generate subqueries corresponding to data query statements, as follows: Figure 2 As shown.
[0093] Figure 2 This is a diagram illustrating a data query statement and its subqueries provided in this specification.
[0094] from Figure 2 As can be seen, when the data query statement is "Select staff.name from staff join leadon staff.ID=lead.ID", the database needs to query the names of employees whose employee ID and leader ID are the same from the employee data table staff and the leader data table lead. That is, it needs to query the names of employees belonging to the leadership level. At this time, the database needs to determine the Cartesian product of all data contained in the employee data table staff and all data contained in the leader data table lead. Then, it can filter the names of employees that meet the conditions from the Cartesian product of all data contained in the employee data table staff and all data contained in the leader data table lead according to the condition statement "staff.ID=lead.ID", which is the final query result. At this time, it can be split into subqueries.
[0095] Assuming `staff.ID` is a specified field, the values contained in the specified field `staff.ID` can be divided into sub-value ranges, such as a sub-value range of ID from 0 to 100, and another sub-value range of ID from 101 to 200. This allows for the generation of sub-queries targeting each sub-value range, such as: "Select staff.name from staff join lead on staff.ID=lead.ID and staff.ID>100and staff.ID<101", and "Select staff.name from staff join lead on staff.ID=lead.ID and staff.ID>100and staff.ID<201". This allows the database to execute each sub-query in parallel. For example, it can determine the Cartesian product of the data in the employee table `staff` (ID from 0 to 100) and all data in the leader table `lead`, and then filter out the names of employees who meet the condition "staff.ID=lead.ID".
[0096] S110: Execute each subquery statement in parallel to perform data queries in the database.
[0097] Furthermore, after generating each subquery statement, the server can execute each subquery statement in parallel through the data source system to retrieve the corresponding data in the database.
[0098] It should be noted that the database mentioned above can refer to each database node in a distributed system. The data source system can execute each subquery statement through each database node, thereby avoiding problems such as long data transmission time and memory overflow that may occur when a single database node executes a data query statement due to the large amount of data to be accessed.
[0099] As can be seen from the above, the server can use complex operators contained in the data query statement as specified operators. Then, according to the preset execution strategy, it can determine the specified field from the condition fields required to execute the target operator, and split the task of querying data for the specified field into multiple sub-tasks. It can also generate sub-query statements for querying each sub-task, thereby enabling the database to execute each sub-query statement in parallel to improve data query efficiency.
[0100] The above describes one or more embodiments of the data query method provided in this specification. Based on the same idea, this specification also provides corresponding data query devices, such as... Figure 3 As shown.
[0101] Figure 3 This is a schematic diagram of a data query device provided in this specification, the device comprising:
[0102] Module 301 is used to obtain data query statements;
[0103] The parsing module 302 is used to parse the data query statement to determine an operator of a specified type from the operators contained in the data query statement as the target operator, and to determine the data table storing the data to be queried corresponding to the data query statement as the target data table.
[0104] The first determining module 303 is used to determine from each parallel extension template a parallel extension template that matches the number of the target operator and the target data table, and use it as the target parallel extension template;
[0105] The second determining module 304 is used to determine a specified field from the fields contained in the target data table according to the target parallel extension template;
[0106] The generation module 305 is used to generate each sub-query statement corresponding to the data query statement based on the specified field;
[0107] Execution module 306 is used to execute each subquery statement in parallel to perform data queries in the database.
[0108] Optionally, the second determining module 304 is specifically used to: if the target operator contained in the data query statement is a join operator, then, according to the target parallel extension template, determine the condition fields with index constraints from the condition fields required to execute the join operator contained in the target data table, as each candidate specified field; and determine the specified field from each candidate specified field.
[0109] Optionally, the second determining module 304 is specifically used to: if the number of join operators is greater than 1, determine the specified field from each candidate specified field based on the amount of data contained in each candidate specified field; if the number of join operators is 1, select any condition field from each candidate specified field as the specified field.
[0110] Optionally, the second determining module 304 is specifically used to: if the target operator contained in the data query statement is an Aggregate operator, then, according to the target parallel expansion template, determine the condition fields with index constraints from the condition fields required to execute the Aggregate operator contained in the target data table, as each candidate specified field; and select any one of the condition fields from each candidate specified field as the specified field.
[0111] Optionally, the second determining module 304 is specifically used to, if the target operator contained in the data query statement is an Aggregate or a join operator, determine, according to the target parallel extension template, whether there is a field with an index constraint among the condition fields required to execute the Aggregate operator contained in the target data table that is the same as the condition fields required to execute the join operator contained in the target data table; if yes, use the same field as the specified field; if no, use any one of the condition fields required to execute the Aggregate operator contained in the target data table as the specified field.
[0112] Optionally, the second determining module 304 is further configured to, if the data query statement does not contain a target operator, use the field corresponding to the query condition contained in the data query statement as the specified field.
[0113] Optionally, the generation module 305 is specifically used to: determine the value range of the values contained in the specified field; determine the number of each subquery statement to be generated as the target number; divide the value range equally according to the target number to obtain each sub-value range; and generate each subquery statement corresponding to the data query statement according to each sub-value range.
[0114] Optionally, the generation module 305 is specifically used to: determine the value range of the values contained in the specified field; determine the number of each subquery statement to be generated as the target number; determine the range of each sub-value range according to the number of values contained in the specified field and the target number; and generate each subquery statement corresponding to the data query statement according to the range of each sub-value range.
[0115] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 This provides a data query method.
[0116] This instruction manual also provides Figure 4 One of the corresponding Figure 1 A schematic diagram of the structure of an electronic device. (e.g.) Figure 4 At the hardware level, this electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then executes it to achieve the above. Figure 1 The data query method. Of course, in addition to the software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0117] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0118] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0119] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0120] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware components.
[0121] Those skilled in the art will understand that embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0122] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0123] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0124] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0125] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0126] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0127] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0128] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0129] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0130] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0131] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0132] The above are merely embodiments of this specification and are not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A data query method, comprising: obtaining a data query statement; parsing the data query statement to determine, from each operator included in the data query statement, an operator of a specified type as a target operator and a data table storing data to be queried corresponding to the data query statement as a target data table; determining, from each preset parallel expansion template, a parallel expansion template matching the target operator and a number of the target data tables as a target parallel expansion template; determining, according to the target parallel expansion template, a specified field from each field included in the target data table, comprising: determining, according to the target parallel expansion template, a condition field having an index constraint from each condition field included in the target data table required for executing the target operator as a specified field; generating each sub-query statement corresponding to the data query statement according to the specified field; parallelly executing each sub-query statement to execute data query in a database. 2.The method of claim 1, wherein the determining, according to the target parallel expansion template, a specified field from each field included in the target data table comprises: if the target operator included in the data query statement is a join operator, determining, according to the target parallel expansion template, a condition field having an index constraint from each condition field included in the target data table required for executing the join operator as each candidate specified field; and determining a specified field from the each candidate specified field. 3.The method of claim 2, wherein the determining a specified field from the each candidate specified field comprises: if the number of the join operators is greater than 1, determining a specified field from the each candidate specified field according to a data amount of data included in each candidate specified field; and if the number of the join operators is 1, selecting an arbitrary condition field from the each candidate specified field as a specified field. 4.The method of claim 1, wherein the determining, according to the target parallel expansion template, a specified field from each field included in the target data table comprises: if the target operator included in the data query statement is an Aggregate operator, determining, according to the target parallel expansion template, a condition field having an index constraint from each condition field included in the target data table required for executing the Aggregate operator as each candidate specified field; and selecting an arbitrary condition field from the each candidate specified field as a specified field. 5.The method of claim 1, wherein the determining, according to the target parallel expansion template, a specified field from each field included in the target data table comprises: If the target operator included in the data query statement is an Aggregate operator and a join operator, according to the target parallel expansion template, it is determined whether there is a field included in the target data table and having an index constraint and being identical to each condition field included in the target data table and required for executing the Aggregate operator; If yes, the identical field is taken as a specified field; If no, any one of the condition fields included in the target data table and required for executing the Aggregate operator is taken as a specified field.
6. The method of claim 1, further comprising: If the data query statement does not include a target operator, a field corresponding to a query condition included in the data query statement is taken as a specified field.
7. The method of claim 1, wherein each sub-query statement corresponding to the data query statement is generated according to the specified field, and specifically comprising: determining a value domain range of a value included in the specified field; determining a target number of sub-query statements to be generated; dividing the value domain range according to the target number to obtain each sub-value domain range; generating each sub-query statement corresponding to the data query statement according to the each sub-value domain range.
8. The method of claim 1, wherein each sub-query statement corresponding to the data query statement is generated according to the specified field, and specifically comprising: determining a value domain range of a value included in the specified field; determining a target number of sub-query statements to be generated; determining each sub-value domain range according to a number of values included in the specified field and the target number; generating each sub-query statement corresponding to the data query statement according to the each sub-value domain range.
9. A data query apparatus, comprising: an acquisition module configured to acquire a data query statement; a parsing module configured to parse the data query statement to determine a specified type of operator from each operator included in the data query statement as a target operator, and determine a data table storing to-be-queried data corresponding to the data query statement as a target data table; a first determination module configured to determine a parallel expansion template matching the target operator and a number of the target data tables from each preset parallel expansion template as a target parallel expansion template; a second determination module configured to determine a specified field from each field included in the target data table according to the target parallel expansion template, including: determining a condition field having an index constraint from condition fields included in the target data table and required for executing the target operator as a specified field according to the target parallel expansion template; a generation module configured to generate each sub-query statement corresponding to the data query statement according to the specified field; an execution module configured to execute each sub-query statement in parallel to execute data query in a database. 10.The apparatus of claim 9, wherein the second determining module is specifically configured to, if the target operator contained in the data query statement is a join operator, determine, according to the target parallel expansion template, a condition field having an index constraint from each condition field required by the target data table for executing the join operator as each candidate specified field, and determine a specified field from the candidate specified fields. 11.The apparatus of claim 10, wherein the second determining module is specifically configured to, if the number of join operators is greater than 1, determine a specified field from the candidate specified fields according to the amount of data contained in each candidate specified field, and if the number of join operators is 1, select an arbitrary condition field from the candidate specified fields as the specified field. 12.The apparatus of claim 9, wherein the second determining module is specifically configured to, if the target operator contained in the data query statement is an Aggregate operator, determine, according to the target parallel expansion template, a condition field having an index constraint from each condition field required by the target data table for executing the Aggregate operator as each candidate specified field, and select an arbitrary condition field from the candidate specified fields as the specified field. 13.The apparatus of claim 9, wherein the second determining module is specifically configured to, if the target operator contained in the data query statement is an Aggregate and join operator, determine, according to the target parallel expansion template, whether there is a field having an index constraint and being the same as a condition field required by the target data table for executing the join operator in each condition field required by the target data table for executing the Aggregate operator, and if yes, take the same field as the specified field, and if no, take an arbitrary condition field in each condition field required by the target data table for executing the Aggregate operator as the specified field. 14.The apparatus of claim 9, wherein the second determining module is further configured to, if the data query statement does not contain a target operator, take a field corresponding to a query condition contained in the data query statement as the specified field.
15. The apparatus of claim 9, wherein the generating module is specifically configured to determine a value range of the value contained in the specified field; and determine the number of the to-be-generated subquery statements as the target number. divide the value domain range according to the target number to obtain each sub-value domain range; generate each sub-query statement corresponding to the data query statement according to the each sub-value domain range.
16. The apparatus of claim 9, wherein the generating module is specifically configured to determine a value range of the value contained in the specified field; and determine the number of the to-be-generated subquery statements as the target number. determine each sub-value domain range according to the number of values contained in the specified field and the target number; generate each sub-query statement corresponding to the data query statement according to the each sub-value domain range. 17.A computer readable storage medium, the storage medium storing a computer program, the computer program being executed by a processor to implement the method of any one of claims 1-8.
18. An electronic device comprising a memory, a processor, and a computer program stored on the memory and loadable on the processor, the processor implementing the method of any of claims 1 to 8 when executing the program.
Citation Information
Patent Citations
Method and device for processing database query statement
CN114925093A
Data query method and device, electronic equipment and storage medium
CN115374157A