Query method and device
By traversing in the query statement and only computing the basic calculation unit results that are traversed for the first time, the problem of repeated calculations under multiple aggregation functions is solved, and the query efficiency is improved.
Patent Information
- Application Number
- CN202311418882.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-27
- Publication Date
- 2025-04-29
AI Technical Summary
When multiple aggregate functions exist in the query statement, repeated calculations are prone to occur. How to reduce repeated calculations is a technical problem that needs to be solved urgently.
The processor receives the first query statement input by the user, traverses the basic computing unit corresponding to each aggregation function, and only calculates the results of the basic computing unit traversed for the first time, avoiding repeated calculations.
It effectively solves the problem of repeatedly calculating the basic calculation unit under multiple aggregation functions, and improves query efficiency.
Smart Images

Figure CN119903220A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a query method and device. Background Art
[0002] When analyzing and counting data in a database, you can use query statements containing aggregate functions. Aggregate functions are used to calculate a result based on multiple rows of input data. Common aggregate functions include sum(), count(), avg(), etc.
[0003] If a query statement includes multiple aggregate functions, after receiving the query statement, the database traverses the data in the data table corresponding to the query statement, determines the calculation result of each aggregate function, and outputs the calculation result of each aggregate function as the result of the query statement.
[0004] When there are multiple aggregate functions in a query statement, repeated calculations are likely to occur when determining the result of each aggregate function. How to reduce repeated calculations is a technical problem that urgently needs to be solved. Summary of the invention
[0005] The present application provides a query method and device for solving the problem of repeated calculation when there are multiple aggregation functions in a query statement.
[0006] In the first aspect, an embodiment of the present application provides a query method, which can be executed by a processor of a computer device. The method specifically includes the following steps: the processor receives a first query statement input by a user, wherein the first query statement includes M first aggregation functions, M is a positive integer, and each first aggregation function corresponds to at least one basic computing unit; the processor traverses the basic computing units corresponding to the M first aggregation functions, and calculates the results of the N basic computing units traversed for the first time, wherein N is a positive integer; the processor determines the calculation results corresponding to the M first aggregation functions according to the results of the N basic computing units, and then outputs the execution result of the first query statement according to the calculation results corresponding to the M first aggregation functions.
[0007] Through the above method, when the basic calculation units corresponding to the M first aggregation functions are the same, only the results of the N basic calculation units traversed for the first time are calculated, which can effectively solve the problem of repeated calculation of basic calculation units and improve query efficiency.
[0008] In a possible design, before the processor traverses the basic computing units corresponding to the M first aggregation functions respectively, it can also include: the processor determines a second query statement according to the first query statement, the second query statement includes a second aggregation function, wherein the second aggregation function includes M expressions and M function symbols corresponding to the M first aggregation functions respectively. The processor then determines the basic computing units corresponding to the M first aggregation functions respectively according to the M expressions and the M function symbols. With this design, the basic computing unit corresponding to each first aggregation function can be conveniently determined through the second aggregation function in the second query statement.
[0009] In a possible design, the first query statement also includes an identifier of the first data table, and the M first aggregation functions include at least one expression; the processor calculates the results of the N basic calculation units traversed for the first time, which may include: the processor determines the data corresponding to at least one expression in the first data table according to the identifier of the first data table and at least one expression, and then calculates the results of the N basic calculation units according to the data corresponding to the at least one expression. Through this design, a method for determining the results of N basic calculation units is provided.
[0010] In one possible design, the processor calculates the results of N basic calculation units based on the data corresponding to at least one expression, which may include: for a first expression in at least one expression, where the first expression is any expression in at least one expression, performing the following steps: traversing the data corresponding to the first expression in the first data table, and calculating the results of the basic calculation units related to the first expression.
[0011] In a possible design, before the processor determines the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units, it may also include: the processor determines the operation relationship between at least one basic calculation unit corresponding to each of the M first aggregation functions. The processor determines the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units, which may include: for each of the M first aggregation functions, the processor determines the result of at least one basic calculation unit corresponding to each first aggregation function from the results of the N basic calculation units, and then determines the calculation result corresponding to each first aggregation function based on the result of at least one basic calculation unit corresponding to each first aggregation function and the operation relationship between at least one basic calculation unit corresponding to each first aggregation function.
[0012] In a second aspect, an embodiment of the present application further provides a query device, the query device comprising a transceiver unit and a processing unit:
[0013] A transceiver unit, configured to receive a first query statement input by a user, wherein the first query statement includes M first aggregation functions, M is a positive integer, and each first aggregation function corresponds to at least one basic computing unit;
[0014] A processing unit, used to traverse the basic computing units corresponding to the M first aggregation functions respectively, and calculate the results of the N basic computing units traversed for the first time, where N is a positive integer;
[0015] The processing unit is further used to determine the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units;
[0016] The processing unit is further used to output the execution result of the first query statement according to the calculation results corresponding to the M first aggregation functions.
[0017] In one possible design, before the processing unit traverses the basic computing units corresponding to the M first aggregation functions respectively, the processing unit is also used to determine a second query statement based on the first query statement, wherein the second query statement includes a second aggregation function, and the second aggregation function includes M expressions and M function symbols corresponding to the M first aggregation functions respectively; based on the M expressions and M function symbols, determine the basic computing units corresponding to the M first aggregation functions respectively.
[0018] In one possible design, the first query statement also includes an identifier of the first data table, and the M first aggregation functions include at least one expression; the processing unit is specifically used to: determine the data corresponding to at least one expression in the first data table based on the identifier of the first data table and at least one expression; and calculate the results of N basic calculation units based on the data corresponding to at least one expression.
[0019] In one possible design, the processing unit is specifically used to: for a first expression in at least one expression, where the first expression is any expression in at least one expression, perform the following steps: traverse the data corresponding to the first expression in the first data table, and calculate the results of the basic calculation units related to the first expression.
[0020] In one possible design, before the processing unit determines the calculation results corresponding to M first aggregation functions respectively based on the results of N basic calculation units, the processing unit is also used to: determine the operational relationship between at least one basic calculation unit corresponding to each of the M first aggregation functions; the processing unit is specifically used to: for each of the M first aggregation functions, execute: determine the result of at least one basic calculation unit corresponding to each first aggregation function from the results of the N basic calculation units; based on the result of at least one basic calculation unit corresponding to each first aggregation function, and the operational relationship between at least one basic calculation unit corresponding to each first aggregation function, determine the calculation result corresponding to each first aggregation function.
[0021] In a third aspect, an embodiment of the present application further provides a computer device, comprising a memory and a processor, wherein the memory is used to store programs and data, and the processor is used to run the programs stored in the memory, and execute the method provided in the first aspect according to the data stored in the memory.
[0022] In a fourth aspect, an embodiment of the present application further provides a computer storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the method provided in the first aspect above.
[0023] In a fifth aspect, an embodiment of the present application further provides a chip, which is used to read a computer program stored in a memory to implement the method in the first aspect above.
[0024] In a sixth aspect, an embodiment of the present application provides a chip system, which includes a processor for supporting a computer device to implement the functions involved in the first aspect. In a possible design, the chip system also includes a memory, which is used to store the necessary programs and data for the computer device. The chip system can be composed of a chip, or it can include a chip and other discrete devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 A schematic diagram of the structure of a computer device provided in an embodiment of the present application;
[0026] Figure 2 A flowchart of a query method provided in an embodiment of the present application;
[0027] Figure 3 A flowchart of a method for determining a basic computing unit corresponding to a first aggregation function provided in an embodiment of the present application;
[0028] Figure 4A structural diagram of a query device provided in an embodiment of the present application;
[0029] Figure 5 A structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solution and advantages of the present application more clear, the present application will be further described in detail below with reference to the accompanying drawings. The specific operation methods, functional descriptions, etc. in the method embodiments can also be applied to the device embodiments or system embodiments.
[0031] Below, some terms in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0032] Structured query language (SQL) is a special-purpose programming language, a database query and programming language used to access data and query, update, and manage relational database systems.
[0033] The query statement is used to query the data in the database and will not modify the data in the database. The syntax format of a simple query statement is select expression from table name, where expression can also be understood as the field name or column name in the data table, and table name can also be understood as the identifier of the data table. For example, select age from table1, where age is the column name and table1 is the table name. The data table corresponding to table1 includes the data corresponding to the column name age.
[0034] The query statement can also include aggregate functions, and the corresponding syntax format is select aggregate function (expression) from table name.
[0035] An aggregate function is a function that takes a collection as input and returns a single value. The database management system (DBMS) provides specialized aggregate functions such as count(), sum(), avg(), max(), min(), etc.
[0036] The count() function is used to count the number of rows of data in the specified column of the data table.
[0037] The sum() function is used to calculate the sum of the data in the specified column of the data table.
[0038] The avg() function is used to calculate the average value of the data in the specified column of the data table.
[0039] The max() function is used to calculate the maximum value of the data in the specified column of the data table.
[0040] The min() function is used to calculate the minimum value of the data in the specified column of the data table.
[0041] The query statement may include at least one aggregation function, each aggregation function includes an expression, and the expressions in each aggregation function may be the same or different. Take the query statement including multiple aggregation functions, and the expressions included in each aggregation function are the same as an example, such as select count(age),sum(age),avg(age)from table1, where the query statement includes three aggregation functions, namely count(), sum() and avg(), and the expression included in each aggregation function is age, table1 is the table name, and the data table corresponding to table1 includes data corresponding to the column name age; take the query statement including multiple aggregation functions, and some of the aggregation functions include the same expression as an example, such as select count(age),sum(score),avg(score)from table1, where the query statement includes three aggregation functions, namely count(), sum() and avg(), and the expressions included in the aggregation functions sum() and avg() are both score, the expression included in the aggregation function count() is age, and the data table corresponding to table1 includes data corresponding to the column name age and data corresponding to the column name score.
[0042] Generally speaking, when a query statement includes multiple aggregation functions, the result corresponding to each aggregation function is determined separately. Specifically, for any aggregation function among the multiple aggregation functions, the following steps can be performed: first, according to the aggregation function and the expression included in the aggregation function, the basic calculation unit corresponding to the aggregation function is determined. Then, the result of the aggregation function is determined according to the result of the basic calculation unit.
[0043] In the embodiment of the present application, each aggregation function may correspond to one basic computing unit or may correspond to multiple basic computing units.
[0044] When an aggregate function corresponds to a basic computing unit, the result of the basic computing unit can be directly used as the result of the aggregate function.
[0045] In the case where the aggregation function corresponds to multiple basic computing units, it is also necessary to determine the operation relationship between the multiple basic computing units, that is, the aggregation function can be obtained through the operation relationship between the multiple basic computing units. According to the operation relationship between the multiple basic computing units determined above, the results of the multiple basic computing units are calculated to obtain the result of the aggregation function.
[0046] The following is a detailed explanation of the basic computing units corresponding to different aggregation functions.
[0047] count(X), its corresponding basic calculation unit is to calculate the number of rows of data in column X of the data table. The basic calculation unit can be abbreviated as count_X.
[0048] sum(X), its corresponding basic calculation unit is to calculate the sum of the data in column X of the data table. The basic calculation unit can be abbreviated as sum_X.
[0049] avg(X), its corresponding basic calculation units include two, namely, calculating the number of rows of data in column X of the data table, that is, count_X, and calculating the sum of the data in column X of the data table, that is, sum_X.
[0050] max(X), its corresponding basic calculation unit is to calculate the maximum value of the data in column X of the data table. The basic calculation unit can be abbreviated as max_X.
[0051] min(X), its corresponding basic calculation unit is to calculate the minimum value of the data in column X of the data table. The basic calculation unit can be abbreviated as min_X.
[0052] It should be understood that when the aggregation functions are the same but the expressions in the aggregation functions are different, the basic calculation units corresponding to the aggregation functions are different. For example, count(age) and count(score) have the same aggregation functions but different expressions in the aggregation functions, so the basic calculation units corresponding to the two are different. The basic calculation unit corresponding to count(age) is the number of rows of data in the age column of the data table, and the basic calculation unit corresponding to count(score) is the number of rows of data in the score column of the data table.
[0053] Based on the above, it can be seen that when a query statement includes multiple aggregation functions, since each aggregation function needs to be calculated separately, if the same basic calculation unit exists between different aggregation functions, it will lead to repeated calculation of the same basic calculation unit. In order to solve this problem, the present application provides a query method and device.
[0054] The embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0055] Figure 1 The structure diagram of a possible computer device applicable to the query method provided in the embodiment of the present application is shown. Figure 1 As shown, the computer device includes: a processor 110, a memory 120, a communication module 130, an input unit 140, a display unit 150, a power supply 160 and other components. Those skilled in the art can understand that Figure 1 The structure of the computer device shown in the figure does not constitute a limitation on the computer device. The computer device provided in the embodiment of the present application may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0056] Combine the following Figure 1 A detailed introduction to the various components of a computer device:
[0057] The communication module 130 can be connected to other devices by wireless connection or physical connection to realize data transmission and reception of the computer device. Optionally, the communication module 130 can include any one or a combination of a radio frequency (RF) circuit, a wireless fidelity (WiFi) module, a communication interface, a Bluetooth module, etc., which is not limited in the embodiment of the present application.
[0058] The memory 120 may be used to store program instructions and data. The processor 110 executes various functional applications and data processing of the computer device by running the program instructions stored in the memory 120. Among them, the program instructions may enable the processor 110 to execute the query method provided in the following embodiments of the present application.
[0059] Optionally, the memory 120 may mainly include a program storage area and a data storage area. The program storage area may store an operating system, various application programs, and program instructions, etc.; the data storage area may store various data such as query statements and data tables. In addition, the memory 110 may include a high-speed random access memory, and may also include a non-volatile memory, such as a disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0060] The input unit 140 may be used to receive information such as data or operation instructions input by a user. Optionally, the input unit 140 may include input devices such as a touch panel, function keys, a physical keyboard, a mouse, a camera, and a monitor.
[0061] The display unit 150 can realize human-computer interaction and is used to display information input by the user, information provided to the user, etc. through a user interface. The display unit 150 may include a display panel 151. Optionally, the display panel 151 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.
[0062] Furthermore, when the input unit includes a touch panel, the touch panel may cover the display panel 151. When the touch panel detects a touch event on or near it, it transmits the touch event to the processor 110 to determine the type of the touch event and perform a corresponding operation.
[0063] The processor 110 is the control center of the computer device, and uses various interfaces and lines to connect the above components. The processor 110 can complete various functions of the computer device by executing program instructions stored in the memory 120 and calling data stored in the memory 120 to implement the query method provided in the embodiment of the present application.
[0064] Optionally, the processor 110 may include one or more processing units. Specifically, the processing unit may include a hardware device such as a CPU and / or a GPU capable of floating-point operations. The processing unit can determine the result of the query statement and output it. When the processor 110 of the computer device implements the query method, the processing unit reads the query statement from the storage data area of the memory 120, and outputs the execution result of the query statement according to the query statement.
[0065] The computer device also includes a power supply 160 (such as a battery) for supplying power to various components. Optionally, the power supply 160 can be logically connected to the processor 110 through a power management system, so that the power management system can realize functions such as charging and discharging of the computer device.
[0066] Although not shown, the computer device may also include components such as a camera, a sensor, and an audio collector, which will not be described in detail here.
[0067] The present application embodiment provides a query method. Figure 1 The processor in the computer device shown executes. Figure 2 As shown, the process of the method includes:
[0068] S201: The processor receives a first query statement input by a user.
[0069] In an embodiment of the present application, the first query statement includes M first aggregation functions and identifiers of a first data table, each first aggregation function includes at least one expression, where M is a positive integer.
[0070] The syntax format of the first query statement may be select first aggregate function 1 (expression 1), ..., first aggregate function M (expression M) from the identifier of the first data table, wherein the identifier of the first data table may be the table name of the first data table.
[0071] The first aggregation function may include the following two implementation modes.
[0072] In implementation mode 1, the first aggregation function may be an aggregation function provided by a database management system, for example, the first aggregation function is any one of count(), sum(), avg(), max(), min(), etc. Each aggregation function provided by the database management system may include an expression, so the first aggregation function may include an expression.
[0073] For example, if the first query statement includes three first aggregation functions, namely count(), sum(), and avg(), and each first aggregation function includes the expression age, then the first query statement can be select count(age),sum(age),avg(age)from table1.
[0074] In implementation mode 2, the first aggregation function may also be composed of aggregation functions provided by the database management system, wherein the first aggregation function may be determined by performing four arithmetic operations on the aggregation functions provided by the database management system, for example, the first aggregation function is sum() / count(), and / is a division sign. Each aggregation function provided by the database management system may include an expression, and the first aggregation function is composed of aggregation functions provided by the database management system, so the first aggregation function may include at least one expression.
[0075] For example, if the first query statement includes one first aggregate function, namely sum() / count(), and both sum() and count() include the expression age, then the first query statement may be select sum(age) / count(age)fromtable1.
[0076] In the embodiment of the present application, after the processor obtains the first query statement, it can Figure 3 The following steps are shown to determine the basic computing units corresponding to each first aggregation function in the first query statement:
[0077] S301: The processor determines a second query statement according to the first query statement.
[0078] In the embodiment of the present application, the second query statement includes a second aggregation function, which is not an aggregation function provided by the database management system, but an aggregation function rewritten by the present application. The function name of the second aggregation function can be customized, and the present application customizes it as a generic_func() function.
[0079] After obtaining the first query statement, the processor obtains the M first aggregation functions in the first query statement, and for the i-th first aggregation function among the M first aggregation functions, where i is an integer that runs through [1, M], obtains the expression included in the i-th first aggregation function as the i-th expression, and determines the function symbol corresponding to the i-th first aggregation function. Among them, different first aggregation functions correspond to different function symbols. After determining the M expressions and M function symbols corresponding to the M first aggregation functions, the processor fills the M expressions and M function symbols into the second aggregation function in sequence. Therefore, the second aggregation function includes M expressions and M function symbols corresponding to the M first aggregation functions, respectively.
[0080] In the embodiment of the present application, the positional relationship between the M expressions and the M function symbols in the second aggregation function may include the following three possible implementations:
[0081] In a first possible implementation, the M function symbols are arranged sequentially after the M expressions.
[0082] The first query statement is select first aggregate function 1 (expression 1), ..., first aggregate function M (expression M) from table name. The second query statement is determined according to the first query statement, and the second query statement is select second aggregate function (expression 1, ..., expression M, function symbol 1, ..., function symbol M) from table name. Among them, function symbol 1 is determined according to first aggregate function 1, function symbol M is determined according to first aggregate function M, and the rest is not repeated.
[0083] In a second possible implementation, the M expressions are arranged sequentially after the M function symbols.
[0084] The first query statement is select first aggregate function (expression 1), ..., first aggregate function (expression M) from table name. The second query statement is determined according to the first query statement, and the second query statement is select second aggregate function (function symbol 1, ..., function symbol M, expression 1, ..., expression M) from table name.
[0085] In a third possible implementation, M expressions and M function symbols are arranged in sequence in a cross shape.
[0086] The first query statement is select first aggregate function 1 (expression 1), ..., first aggregate function M (expression M) from table name. The second query statement is determined according to the first query statement. The second query statement can be select second aggregate function (expression 1, function symbol 1, ..., expression M, function symbol M) from table name. The syntax format of the second query statement can also be select second aggregate function (function symbol 1, expression 1, ..., function symbol M, expression M) from table name.
[0087] For ease of description, the following second query statements are explained by taking select second aggregate function (expression 1, function symbol 1, ..., expression M, function symbol M) from table name as an example.
[0088] In the above method, since M expressions and M function symbols are sequentially added to the second aggregation function, it is convenient for the subsequent processor to determine the basic computing unit corresponding to each first aggregation function.
[0089] S302: The processor determines basic computing units corresponding to the M first aggregation functions respectively according to the M expressions and the M function symbols.
[0090] In an embodiment of the present application, the processor obtains the i-th expression and the i-th function symbol, and determines the basic computing unit corresponding to the i-th first aggregation function based on the i-th expression and the i-th function symbol, where i is an integer ranging from [1, M]. The i-th first aggregation function corresponds to at least one basic computing unit.
[0091] When determining the basic computing unit corresponding to the ith first aggregation function, it is also necessary to determine the operation relationship between the basic computing units corresponding to the ith first aggregation function, as follows:
[0092] In the case where the ith first aggregation function corresponds to one basic computing unit, the result of the basic computing unit can be directly used as the result of the ith first aggregation function.
[0093] In the case where the ith first aggregation function corresponds to multiple basic computing units, it is also necessary to determine the operation relationship between the multiple basic computing units, that is, the ith first aggregation function can be obtained through the operation relationship between the multiple basic computing units.
[0094] For example, the first query statement is select count(age),sum(score),avg(score)fromtable1. For the first first aggregate function count(age), the processor determines that the first expression is age, and the function symbol corresponding to the first first aggregate function is COUNT; for the second first aggregate function sum(score), the processor determines that the second expression is score, and the function symbol corresponding to the second first aggregate function is SUM; for the third first aggregate function avg(score), the processor determines that the third expression is score, and the function symbol corresponding to the third first aggregate function is AVG.
[0095] The processor determines that the second query statement is select generic_func(age,COUNT,score,SUM,score,AVG)fromtable1 according to the determined three expressions and three function symbols and the second aggregate function generic_func().
[0096] Based on the three expressions and three function symbols in the second aggregate function of the second query statement, the processor can determine that the basic calculation unit corresponding to the first aggregate function count(age) is count_age, and the result of the basic calculation unit count_age is the result of the first aggregate function count(age).
[0097] The basic calculation unit corresponding to the second first aggregation function sum(score) is sum_score, and the result of the basic calculation unit sum_score is the result of the first aggregation function sum(score).
[0098] The basic calculation units corresponding to the third first aggregation function avg(score) are count_score and sum_score, and the result of the basic calculation unit sum_score / count_score is the result of the first aggregation function avg(score).
[0099] In the above method, the basic computing unit corresponding to each first aggregation function can be conveniently determined through the second aggregation function in the second query statement.
[0100] S202, the processor traverses the basic computing units corresponding to the M first aggregation functions respectively, and calculates the results of the N basic computing units traversed for the first time, where N is a positive integer.
[0101] In the embodiment of the present application, each first aggregation function includes at least one expression, and the expressions included in each first aggregation function may be the same or different. Therefore, the M first aggregation functions include at least one expression.
[0102] In one possible implementation, the processor may determine the data corresponding to at least one expression in the first data table based on an identifier of the first data table and at least one expression, and then calculate the results of N basic computing units based on the data corresponding to at least one expression.
[0103] Specifically, in order to calculate the results of N basic computing units, the present application provides a generic_sfunc() function, which performs the following steps: for a first expression in at least one expression, where the first expression is any expression in at least one expression, the processor obtains data corresponding to the first expression from a first data table, and then traverses the data corresponding to the first expression in the first data table to calculate the results of the basic computing units related to the first expression.
[0104] It should be understood that when processing at least one expression, the processor can read each row of records in the first data table in turn, each row of records including data corresponding to multiple expressions, obtain data corresponding to at least one expression from each row of records, and then calculate the results of the basic calculation units related to at least one expression.
[0105] The processor can also obtain the data corresponding to each expression from the first data table in turn, and for the first expression in at least one expression, read each row of records in the data corresponding to the first expression in turn, each row of records only includes the data corresponding to the first expression, and then calculate the results of the basic calculation units related to the first expression.
[0106] For example, the first query statement is select count(age),sum(score),avg(score)fromtable1. According to the first query statement, two expressions are determined, namely age and score. The basic calculation unit corresponding to the first aggregation function count(age) is count_age, the basic calculation unit corresponding to the first aggregation function sum(score) is sum_score, and the basic calculation units corresponding to the first aggregation function avg(score) are count_score and sum_score. Among them, the three non-repeated basic calculation units traversed for the first time are count_age, sum_score, and count_score.
[0107] The processor obtains the data corresponding to age from the first data table, traverses the data corresponding to age, and counts the number of rows of the data corresponding to age, so as to determine the result of the basic calculation unit count_age.
[0108] The processor obtains the data corresponding to score from the first data table, traverses the data corresponding to score, counts the sum of the data corresponding to score, and determines the result of the basic calculation unit sum_score. The processor counts the number of rows of the data corresponding to score to determine the result of the basic calculation unit count_score.
[0109] S203: The processor determines the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units.
[0110] A possible implementation method, in order to calculate the calculation results corresponding to M first aggregation functions respectively, the present application provides a generic_ffunc() function, which performs the following steps: for each of the M first aggregation functions, first determine the result of at least one basic calculation unit corresponding to each first aggregation function from the results of N basic calculation units, and then determine the calculation result corresponding to each first aggregation function based on the result of at least one basic calculation unit corresponding to each first aggregation function and the operational relationship between at least one basic calculation unit corresponding to each first aggregation function.
[0111] S204: The processor outputs the execution result of the first query statement according to the calculation results corresponding to the M first aggregation functions.
[0112] In a possible implementation, calculation results corresponding to the M first aggregation functions are output according to the order of the M first aggregation functions in the first query statement.
[0113] In the above method, when the basic calculation units corresponding to the M first aggregation functions are the same, only the results of the N basic calculation units traversed for the first time are calculated, which can effectively solve the problem of repeated calculation of basic calculation units and improve query efficiency.
[0114] Based on the above embodiments, the present application also provides a query device 400, which is applied to Figure 1 The processor of the computer device shown is used to implement Figure 2 The query method provided by the embodiment shown. Figure 4 As shown, the query device includes: a transceiver unit 401 and a processing unit 402. Among them:
[0115] The transceiver unit 401 is used to receive a first query statement input by a user, where the first query statement includes M first aggregation functions, where M is a positive integer; each first aggregation function corresponds to at least one basic computing unit;
[0116] The processing unit 402 is used to traverse the basic computing units corresponding to the M first aggregation functions respectively, and calculate the results of the N basic computing units traversed for the first time, where N is a positive integer;
[0117] The processing unit 402 is further used to determine the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units;
[0118] The processing unit 402 is further configured to output the execution result of the first query statement according to the calculation results respectively corresponding to the M first aggregation functions.
[0119] An embodiment of the present application provides a query device, which, after receiving a first query statement input by a user, can traverse the basic computing units corresponding to the M first aggregation functions in the first query statement, calculate the results of the N basic computing units traversed for the first time, and determine the calculation results corresponding to the M first aggregation functions according to the results of the N basic computing units, and then output the execution result of the first query statement according to the calculation results corresponding to the M first aggregation functions, thereby solving the problem of repeated calculation of the basic computing units.
[0120] It should be noted that the division of modules in the embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0121] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0122] Based on the above embodiments, the present application also provides a computer device, which is used to implement the following Figure 2 The query method shown has the following Figure 4 The query device functions shown. Figure 5 As shown, the computer device includes: a processor 501 and a memory 502.
[0123] The processor 501 and the memory 502 are connected to each other. Optionally, the processor 501 and the memory 502 can be connected to each other via a bus 503; the bus 503 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0124] Optionally, the computer device 500 further includes a communication module 504 for communicating and interacting with other devices. Optionally, the communication module 504 can communicate with other devices via wireless connection, for example, the communication module 504 can be an RF circuit, a WiFi module, etc. The communication module 504 can also communicate with other devices via physical connection, for example, the communication module 504 can be a communication interface.
[0125] The processor 501 is used to implement Figure 2 The specific process of the query method shown can refer to the specific description in the above embodiment and will not be repeated here.
[0126] The memory 502 is used to store programs and data. Specifically, the program may include program code, which includes instructions for computer operations. The memory 502 may include random access memory (RAM), and may also include non-volatile memory (non-volatile memory), such as at least one disk memory. The processor 501 executes the program stored in the memory 502 to implement the above functions, thereby achieving the following: Figure 2 The query method shown.
[0127] The present application also provides a computer storage medium, wherein a computer program is stored in the computer storage medium, and when the computer program is executed by a computer, the computer executes Figure 2 The query method shown.
[0128] In summary, an embodiment of the present application provides a query method and device. In the method, after receiving a first query statement input by a user, the basic computing units corresponding to the M first aggregation functions in the first query statement can be traversed, and the results of the N basic computing units traversed for the first time can be calculated. Based on the results of the N basic computing units, the calculation results corresponding to the M first aggregation functions can be determined. Then, based on the calculation results corresponding to the M first aggregation functions, the execution result of the first query statement can be output, thereby solving the problem of repeated calculation of the basic computing units.
[0129] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0130] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0131] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0133] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A query method, characterized in that: The method comprises: Receive a first query statement input by a user, where the first query statement includes M first aggregation functions, where M is a positive integer; each of the first aggregation functions corresponds to at least one basic computing unit; Traversing the basic computing units corresponding to the M first aggregation functions respectively, and calculating the results of the N basic computing units traversed for the first time, where N is a positive integer; Determine, according to the results of the N basic computing units, the computing results respectively corresponding to the M first aggregation functions; Output the execution result of the first query statement according to the calculation results respectively corresponding to the M first aggregation functions.
2. The method according to claim 1, characterized in that Before traversing the basic computing units respectively corresponding to the M first aggregation functions, the method further includes: Determine a second query statement according to the first query statement, wherein the second query statement includes a second aggregation function, and the second aggregation function includes M expressions and M function symbols respectively corresponding to the M first aggregation functions; According to the M expressions and the M function symbols, basic computing units corresponding to the M first aggregation functions are determined.
3. The method according to claim 1, characterized in that The first query statement also includes an identifier of a first data table, and the M first aggregation functions include at least one expression; The results of the N basic computing units traversed for the first time by the calculation include: Determine, according to the identifier of the first data table and the at least one expression, data corresponding to the at least one expression in the first data table; The results of the N basic calculation units are calculated according to the data respectively corresponding to the at least one expression.
4. The method according to claim 3, characterized in that The calculating the results of the N basic calculation units according to the data respectively corresponding to the at least one expression includes: For a first expression in the at least one expression, where the first expression is any expression in the at least one expression, perform the following steps: The data corresponding to the first expression in the first data table are traversed to calculate the results of the basic calculation units related to the first expression.
5. The method according to claim 1, characterized in that Before determining the calculation results respectively corresponding to the M first aggregation functions according to the results of the N basic calculation units, the method further includes: Determine an operation relationship between at least one basic computing unit corresponding to each of the M first aggregation functions; Determining the calculation results respectively corresponding to the M first aggregation functions according to the results of the N basic calculation units includes: For each of the M first aggregation functions, executing: Determine, from the results of the N basic computing units, a result of at least one basic computing unit corresponding to each of the first aggregation functions; Based on the result of at least one basic calculation unit corresponding to each of the first aggregation functions and the operation relationship between the at least one basic calculation unit corresponding to each of the first aggregation functions, the calculation result corresponding to each of the first aggregation functions is determined.
6. A query device, characterized in that: The query device includes a transceiver unit and a processing unit: The transceiver unit is used to receive a first query statement input by a user, where the first query statement includes M first aggregation functions, where M is a positive integer; Each of the first aggregation functions corresponds to at least one basic computing unit; The processing unit is used to traverse the basic computing units corresponding to the M first aggregation functions respectively, and calculate the results of the N basic computing units traversed for the first time, where N is a positive integer; The processing unit is further used to determine the calculation results corresponding to the M first aggregation functions respectively according to the results of the N basic calculation units; The processing unit is further used to output the execution result of the first query statement according to the calculation results respectively corresponding to the M first aggregation functions.
7. The device according to claim 6, characterized in that Before traversing the basic computing units respectively corresponding to the M first aggregation functions, the processing unit is further used to determine a second query statement according to the first query statement, where the second query statement includes a second aggregation function, and the second aggregation function includes M expressions and M function symbols respectively corresponding to the M first aggregation functions; According to the M expressions and the M function symbols, basic computing units corresponding to the M first aggregation functions are determined.
8. The device according to claim 6, characterized in that The first query statement also includes an identifier of a first data table, and the M first aggregation functions include at least one expression; The processing unit is specifically used for: Determine, according to the identifier of the first data table and the at least one expression, data corresponding to the at least one expression in the first data table; The results of the N basic calculation units are calculated according to the data respectively corresponding to the at least one expression.
9. The device according to claim 8, characterized in that The processing unit is specifically used for: For a first expression in the at least one expression, where the first expression is any expression in the at least one expression, perform the following steps: The data corresponding to the first expression in the first data table are traversed to calculate the results of the basic calculation units related to the first expression.
10. The device according to claim 6, characterized in that Before determining the calculation results respectively corresponding to the M first aggregation functions according to the results of the N basic calculation units, the processing unit is further used to: Determine an operation relationship between at least one basic computing unit corresponding to each of the M first aggregation functions; The processing unit is specifically used for: For each of the M first aggregation functions, executing: Determine, from the results of the N basic computing units, a result of at least one basic computing unit corresponding to each of the first aggregation functions; Based on the result of at least one basic calculation unit corresponding to each of the first aggregation functions and the operation relationship between the at least one basic calculation unit corresponding to each of the first aggregation functions, the calculation result corresponding to each of the first aggregation functions is determined.
11. A computer device, characterized in that: include: Memory, used to store programs and data; A processor, configured to run the program stored in the memory, and to execute the method according to any one of claims 1 to 5 according to the data stored in the memory.
12. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and when the computer program is executed by a computer, the computer executes the method provided in any one of claims 1 to 5.