SQL statement processing method and device, electronic device and storage medium

By generating the target query table and rewriting the subquery, and using group by operations to deduplicate and aggregate SQL statements, the problem of low query efficiency of complex SQL statements is solved, data query efficiency is improved, and system parallelism is fully utilized.

CN116541409BActive Publication Date: 2025-08-12BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310272012.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-16
Publication Date
2025-08-12
Estimated Expiration
2043-03-16

AI Technical Summary

Technical Problem

In the prior art, data query based on complex SQL statements is relatively low, which affects task processing efficiency and user experience.

Method used

By generating the target query table and rewriting the subquery, deduplication and aggregation of SQL statements using group by operations, and generating the target SQL statements to make full use of the system parallelism capabilities.

Benefits of technology

It improves the efficiency of data query, achieves the same data query purpose as the original SQL statement, and reduces the use of Distinct aggregation functions, making full use of system parallelism capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116541409B_ABST
    Figure CN116541409B_ABST
Patent Text Reader

Abstract

One or more embodiments of the present specification provide a method and apparatus, electronic device, and storage medium for processing SQL statements, the method comprising: obtaining an SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and a Distinct aggregation function for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated; generating a target query table based on the table to be queried and a sequence number table, and generating a subquery for the target query table, wherein the sequence number table includes a table consisting of sequence numbers of each first column to be aggregated, and the subquery uses group by to deduplicate each first column to be aggregated; rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of this specification relate to the field of database technology, and in particular, to a method and device for processing SQL statements, an electronic device, and a storage medium. Background Art

[0002] In recent years, with the development of computers and databases, SQL (Structure Query Language), a database-specific computer programming language, has gained widespread use, becoming the most important and commonly used query language for relational databases. When performing data queries based on SQL statements, a certain amount of computing power is consumed by the computer application system, which in turn calls the execution engine to perform the data query.

[0003] In related technologies, when performing data queries based on relatively complex SQL statements, the efficiency is low, affecting the processing efficiency of related tasks and user experience. Summary of the Invention

[0004] In view of this, one or more embodiments of this specification provide a method and apparatus for processing SQL statements, an electronic device, and a storage medium.

[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:

[0006] According to a first aspect of one or more embodiments of this specification, a method for processing an SQL statement is proposed, including:

[0007] Obtaining a SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated;

[0008] Generate a target query table based on the table to be queried and the sequence number table, and generate a subquery for the target query table, wherein the sequence number table includes a table composed of the sequence numbers of each first column to be aggregated, and the subquery uses group by to deduplicate each first column to be aggregated;

[0009] The SQL statement to be processed is rewritten according to the subquery to obtain a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.

[0010] In one embodiment of the present specification, the sequence number table includes a table obtained by combining the sequence numbers of each first to-be-aggregated column.

[0011] In one embodiment of the present specification, generating a target query table according to the to-be-queried table and the sequence number table includes:

[0012] The table to be queried and the sequence number table are inner-joined or cross-joined to obtain the target query table.

[0013] In one embodiment of the present specification, the target query table includes a sequence number column and a plurality of second columns to be aggregated, the plurality of second columns to be aggregated correspond one-to-one to the plurality of first columns to be aggregated, and each sequence number in the sequence number column serves as a row label for the same row of data;

[0014] Generating a subquery for the target query table includes:

[0015] Add a first value-taking function for each second column to be aggregated and a group by with multiple third columns to be aggregated as key values in the subquery, wherein the first value-taking function is used to retain data with row labels corresponding to the sequence numbers of the second column to be aggregated, and to set data with row labels other than the sequence numbers corresponding to the second column to be aggregated to blank, the sequence number corresponding to the second column to be aggregated is the sequence number of the corresponding first column to be aggregated, and the multiple third columns to be aggregated are the results of multiple first value-taking functions for the second column to be aggregated.

[0016] In one embodiment of the present specification, rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement includes:

[0017] An aggregate function for each third to-be-aggregated column in the result of the subquery is added to the target SQL statement.

[0018] In one embodiment of the present specification, the table to be queried includes at least one first column to be queried, the SQL statement to be processed includes the at least one first column to be queried, and a group by statement with the at least one first column to be queried as a key value;

[0019] The target query table includes at least one second to-be-queried column, wherein the at least one second to-be-queried column corresponds one-to-one to the at least one first to-be-queried column;

[0020] The generating of a subquery for the target query table further includes:

[0021] Adding the at least one second to-be-queried column to the subquery, wherein the groupby in the subquery uses the plurality of third to-be-aggregated columns and the at least one third to-be-queried column as key values, wherein the at least one third to-be-queried column has a one-to-one correspondence with the at least one second to-be-queried column;

[0022] The step of rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement includes:

[0023] Add the at least one third column to be queried and a group by statement using the at least one third column to be queried as a key value in the target SQL statement.

[0024] In one embodiment of the present specification, the table to be queried includes at least one first column to be summed, and the SQL statement to be processed includes a summation function for each first column to be summed;

[0025] The target query table includes at least one second column to be summed, wherein the plurality of second columns to be summed correspond one-to-one to the plurality of first columns to be summed;

[0026] The generating of a subquery for the target query table further includes:

[0027] Adding a second value function for each second column to be summed within the subquery, and adding a summation function for each second value function, wherein the second value function is used to retain data whose row label is the sequence number corresponding to the second column to be summed, and to set data whose row label is not the sequence number corresponding to the second column to be summed to blank, and the sequence number corresponding to the second column to be summed is the sequence number of the corresponding first column to be summed;

[0028] The step of rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement includes:

[0029] The at least one third column to be summed is added to the target SQL statement, wherein the at least one third column to be summed is a result of multiple summation functions for the second value function.

[0030] In one embodiment of the present specification, the sequence number of each first to-be-aggregated column is different; and / or,

[0031] The sequence number of each first column to be summed is different; and / or,

[0032] The sequence number of each first column to be summed is the same as the sequence number of any first column to be aggregated.

[0033] In one embodiment of the present specification, it further includes:

[0034] Add a sequence number to each first column to be aggregated and each first column to be summed.

[0035] In one embodiment of this specification, obtaining the SQL statement to be processed includes:

[0036] Determine whether the SQL statement used for data query contains multiple Distinct aggregate functions;

[0037] In the case that there are multiple SQL statements with Distinct aggregate functions in the SQL statement for data query, the SQL statement for data query is determined as the SQL statement to be processed.

[0038] In one embodiment of the present specification, it further includes:

[0039] Execute data query based on the target SQL statement.

[0040] According to a second aspect of one or more embodiments of this specification, a device for processing SQL statements is provided, comprising:

[0041] An acquisition module is configured to acquire a SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated;

[0042] a subquery module, configured to generate a target query table based on the table to be queried and the sequence number table, and to generate a subquery for the target query table, wherein the sequence number table includes a table consisting of the sequence numbers of each first column to be aggregated, and the subquery uses a group by operation to remove duplicates from each first column to be aggregated;

[0043] A rewriting module is used to rewrite the SQL statement to be processed according to the subquery to obtain a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.

[0044] In one embodiment of the present specification, the sequence number table includes a table obtained by combining the sequence numbers of each first to-be-aggregated column.

[0045] In one embodiment of the present specification, when the sub-query module is used to generate a target query table according to the table to be queried and the sequence number table, it is specifically used to:

[0046] The table to be queried and the sequence number table are inner-joined or cross-joined to obtain the target query table.

[0047] In one embodiment of the present specification, the target query table includes a sequence number column and a plurality of second columns to be aggregated, the plurality of second columns to be aggregated correspond one-to-one to the plurality of first columns to be aggregated, and each sequence number in the sequence number column serves as a row label for the same row of data;

[0048] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0049] Add a first value-taking function for each second column to be aggregated and a group by with multiple third columns to be aggregated as key values in the subquery, wherein the first value-taking function is used to retain data with row labels corresponding to the sequence numbers of the second column to be aggregated, and to set data with row labels other than the sequence numbers corresponding to the second column to be aggregated to blank, the sequence number corresponding to the second column to be aggregated is the sequence number of the corresponding first column to be aggregated, and the multiple third columns to be aggregated are the results of multiple first value-taking functions for the second column to be aggregated.

[0050] In one embodiment of this specification, the rewriting module is specifically configured to:

[0051] An aggregate function for each third to-be-aggregated column in the result of the subquery is added to the target SQL statement.

[0052] In one embodiment of the present specification, the table to be queried includes at least one first column to be queried, the SQL statement to be processed includes the at least one first column to be queried, and a group by statement with the at least one first column to be queried as a key value;

[0053] The target query table includes at least one second to-be-queried column, wherein the at least one second to-be-queried column corresponds one-to-one to the at least one first to-be-queried column;

[0054] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0055] Adding the at least one second to-be-queried column to the subquery, wherein the groupby in the subquery uses the plurality of third to-be-aggregated columns and the at least one third to-be-queried column as key values, wherein the at least one third to-be-queried column has a one-to-one correspondence with the at least one second to-be-queried column;

[0056] The rewriting module is specifically used for:

[0057] Add the at least one third column to be queried and a group by statement using the at least one third column to be queried as a key value in the target SQL statement.

[0058] In one embodiment of the present specification, the table to be queried includes at least one first column to be summed, and the SQL statement to be processed includes a summation function for each first column to be summed;

[0059] The target query table includes at least one second column to be summed, wherein the plurality of second columns to be summed correspond one-to-one to the plurality of first columns to be summed;

[0060] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0061] Adding a second value function for each second column to be summed within the subquery, and adding a summation function for each second value function, wherein the second value function is used to retain data whose row label is the sequence number corresponding to the second column to be summed, and to set data whose row label is not the sequence number corresponding to the second column to be summed to blank, and the sequence number corresponding to the second column to be summed is the sequence number of the corresponding first column to be summed;

[0062] The rewriting module is specifically used for:

[0063] The at least one third column to be summed is added to the target SQL statement, wherein the at least one third column to be summed is a result of multiple summation functions for the second value function.

[0064] In one embodiment of the present specification, the sequence number of each first to-be-aggregated column is different; and / or,

[0065] The sequence number of each first column to be summed is different; and / or,

[0066] The sequence number of each first column to be summed is the same as the sequence number of any first column to be aggregated.

[0067] In one embodiment of the present specification, a sequence number module is further included, which is used to:

[0068] Add a sequence number to each first column to be aggregated and each first column to be summed.

[0069] In one embodiment of this specification, the acquisition module is specifically configured to:

[0070] Determine whether the SQL statement used for data query contains multiple Distinct aggregate functions;

[0071] In the case that there are multiple SQL statements with Distinct aggregate functions in the SQL statement for data query, the SQL statement for data query is determined as the SQL statement to be processed.

[0072] In one embodiment of the present specification, an execution module is further included, which is used to:

[0073] Execute data query based on the target SQL statement.

[0074] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, including:

[0075] processor;

[0076] a memory for storing processor-executable instructions;

[0077] The processor implements the method described in the first aspect by running the executable instructions.

[0078] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.

[0079] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:

[0080] The SQL statement processing method provided in the embodiment of this specification first obtains the SQL statement to be processed, which includes a table to be queried and a Distinct aggregation function for each first column to be aggregated in the table to be queried, and the serial number of each first column to be aggregated constitutes a serial number table, so a target query table can be generated based on the table to be queried and the serial number table, and a subquery for the target query table can be generated, and finally the SQL statement to be processed can be rewritten according to the subquery to obtain the target SQL statement. Since the subquery uses group by to deduplicate each first column to be aggregated, the target SQL statement can deduplicate and aggregate each first column to be aggregated; the target SQL statement can achieve the same data query purpose as the SQL statement to be processed, and the target SQL statement does not contain a Distinct aggregation function, so when executing data queries based on the target SQL statement, the parallel capabilities of the system can be fully utilized to improve the efficiency of data queries. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] Figure 1 This is a flowchart of a method for processing SQL statements provided by an exemplary embodiment.

[0082] Figure 2 It is a structural diagram of a device provided by an exemplary embodiment.

[0083] Figure 3 It is a block diagram of an SQL statement processing device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0084] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with certain aspects of one or more embodiments of this specification, as detailed in the appended claims.

[0085] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than those described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments, and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0086] In recent years, with the development of computers and databases, SQL (Structure Query Language), a database-specific computer programming language, has gained widespread use, becoming the most important and commonly used query language for relational databases. When performing data queries based on SQL statements, a certain amount of computing power is consumed by the computer application system, which in turn calls the execution engine to perform the data query.

[0087] In related technologies, when performing data queries based on relatively complex SQL statements, the efficiency is low, affecting the processing efficiency of related tasks and user experience.

[0088] Based on this, on the first aspect, at least one embodiment of this specification provides a method for processing SQL statements, which can rewrite SQL statements in the rewriting stage, so that when executing data queries based on the rewritten SQL statements, the system's parallel capabilities can be fully utilized to improve the efficiency of data queries.

[0089] Exemplarily, the method can rewrite SQL statements that include multiple Distinct aggregation functions, so that the rewritten SQL statements can respectively implement deduplication and aggregation operations for each Distinct aggregation function, and fully utilize the system's parallel capabilities when executing data queries.

[0090] Distinct is used to return unique values in the table it targets, that is, to deduplicate the table. For example, if the data in the column targeted by Distinct is "A, B, C, A, B, D, E, F", the query result of Distinct is "A, B, C, D, E, F". The aggregate function with Distinct is a combination of Distinct and an aggregate function, which is used to return the aggregated result of the Distinct query result. For example, the aggregate function with Distinct can be:

[0091] Select

[0092] Count(Distinct c1),

[0093] Count(Distinct c2),

[0094] From T1.

[0095] Please refer to the attached Figure 1 , which exemplarily shows the process of the method, including steps S101 to S103.

[0096] In step S101 , a SQL statement to be processed is obtained, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated.

[0097] In one possible embodiment, the SQL statement to be processed may be obtained in the following manner:

[0098] First, determine whether the SQL statement used for data query contains multiple Distinct aggregate functions;

[0099] Next, in the case that there are multiple SQL statements with Distinct aggregate functions in the SQL statement for data query, the SQL statement for data query is determined as the SQL statement to be processed.

[0100] It can be understood that the SQL statement to be processed can be an SQL statement for data query; the SQL statement to be processed can be an SQL query statement (i.e., a Select statement), and its query items include: the results of the Distinct aggregation function for each first to-be-aggregated column in the table to be queried.

[0101] For example, the SQL statement to be processed may be:

[0102] create table t1(c1 int,c2 int);

[0103] Q1:

[0104] select

[0105] count(distinct c1)as c1_cnt,

[0106] count(distinct c2)as c2_cnt,

[0107] from t1;

[0108] The table to be queried t1 can be as follows:

[0109] Table t1

[0110]

[0111]

[0112] In step S102, a target query table is generated based on the table to be queried and the sequence number table, and a subquery for the target query table is generated, wherein the sequence number table includes a table composed of the sequence numbers of each first column to be aggregated, and the subquery uses group by to deduplicate each first column to be aggregated.

[0113] Optionally, a sequence number is pre-added to each first column to be aggregated, wherein each first column to be aggregated has a different sequence number. For example, the first column to be aggregated c1 in table t1 in the example of step S101 is assigned a sequence number of 1, and the first column to be aggregated c2 in table t1 is assigned a sequence number of 2.

[0114] Exemplarily, the sequence number table includes a table obtained by combining the sequence numbers of each first column to be aggregated, for example, by combining each first column to be aggregated using a union or union all operator. It should be understood that this example does not limit the method for generating the sequence number table; other reasonable methods for generating the sequence number table may also be applied to the embodiments described herein.

[0115] As another example, generating the target query table based on the table to be queried and the sequence number table may include inner joining or cross joining the table to be queried and the sequence number table to obtain the target query table. For example, the table to be queried and the sequence number table may be joined using an inner join or cross join operator to obtain the target query table. It will be understood that this example does not limit the method for generating the target query table, and other reasonable methods for generating the target query table may also be applied to the embodiments described in this specification.

[0116] The above two examples are combined to generate a target query table based on the table to be queried. Taking the table to be queried t1 in step S101 as an example, if the above two examples are used to generate the target query table, the code representing the target query table generation process can be:

[0117] t1

[0118] inner join

[0119] (select 1as dup_code union all select 2as dup_code)dup;

[0120] The generated target query table t1' can be as follows:

[0121] Table t1'

[0122]

[0123]

[0124] It is understood that the target query table includes a sequence number column and multiple second columns to be aggregated, wherein the multiple second columns to be aggregated correspond one-to-one with the multiple first columns to be aggregated, and each sequence number in the sequence number column serves as a row label for the same row of data. For example, the target query table t1' described above includes a sequence number column and second columns to be aggregated c1 and c2, wherein the second column to be aggregated c1 corresponds to the first column to be aggregated c1 in the query table t1, i.e., the first column to be aggregated c1 forms the second column to be aggregated c1 after being concatenated with the sequence number table; the second column to be aggregated c2 corresponds to the first column to be aggregated c2 in the query table t1, i.e., the first column to be aggregated c2 forms the second column to be aggregated c2 after being concatenated with the sequence number table; and each sequence number in the sequence number column in the target query table serves as the row label for the row in which it resides, i.e., the row label for the data in the row.

[0125] Furthermore, since the first column to be aggregated has a sequence number and the second column to be aggregated corresponds to the first column to be aggregated, the second column to be aggregated also has a corresponding sequence number, namely, the sequence number of the first column to be aggregated. For example, if the sequence number of the first column to be aggregated c1 in the query table is 1, and the sequence number of the first column to be aggregated c2 is 2, then the sequence number corresponding to the second column to be aggregated c1 in the target query table t1' is 1, and the sequence number corresponding to the second column to be aggregated c2 is 2.

[0126] Based on the form and content of the above-mentioned target query table, in a possible embodiment, the generation of a subquery for the target query table may include: adding a first value function for each second column to be aggregated and a group by with multiple third columns to be aggregated as key values in the subquery, wherein the first value function is used to retain data with a row number corresponding to the sequence number of the second column to be aggregated, and to set data with a row number other than the sequence number corresponding to the second column to be aggregated to blank, the sequence number corresponding to the second column to be aggregated is the sequence number of the corresponding first column to be aggregated, and the multiple third columns to be aggregated are the results of multiple first value functions for the second column to be aggregated. The subquery can be a query statement (i.e., a Select statement), whose query items include: the result of the first value function for each second column to be aggregated; the key value of the group by is the basis for grouping using the group by operator, that is, the subquery uses group by to deduplicate each first column to be aggregated.

[0127] Continuing with the example of step S101 with the SQL statement to be processed, the table to be queried t1, and the target query table t1', the subquery for the target query table may be:

[0128]

[0129]

[0130] (select 1as dup_code union all select 2as dup_code)dup;

[0131] group by d_c1,d_c2;

[0132] The result of the subquery can be the following table t1":

[0133] Table t1"

[0134] d_c1 d_c2 Alice NULL Bob NULL David NULL NULL Switch NULL PS5 NULL Xbox

[0135] The table t1″ includes third columns to be aggregated d_c1 and d_c2, wherein the third column to be aggregated d_c1 is the result of the first value function on the second column to be aggregated c1, and the third column to be aggregated d_c2 is the result of the first value function on the second column to be aggregated c2.

[0136] From the above table t1", it can be seen that since the subquery is grouped by each third column to be aggregated, the subquery has completed deduplication for each first column to be aggregated.

[0137] In step S103, the SQL statement to be processed is rewritten according to the subquery to obtain a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.

[0138] Since the subquery has already completed deduplication for each first column to be aggregated, the purpose of rewriting the pending SQL statement in this step is to aggregate the results of the subquery. Exemplarily, an aggregate function (such as a count function) for each third column to be aggregated in the result of the subquery is added to the target SQL statement to complete the rewriting of the pending SQL statement. It is understandable that the target SQL statement can be an SQL query statement (i.e., a Select statement), whose query items include: the results of the aggregate function (such as a count function) for each third column to be aggregated in the result of the subquery.

[0139] Continuing with the example of the SQL statement to be processed and the table to be queried t1 in step S101, and the target query table t1′ and the subquery result table t″ in step S102, the target SQL statement obtained by rewriting the SQL statement to be processed based on the subquery can be:

[0140] Q3:

[0141] Select count(d_c1)as c1_cnt,count(d_c2)as c2_cnt

[0142] from(

[0143] Select

[0144] if(dup_code=1,t1.c1,NULL)as d_c1,

[0145] if(dup_code=2,t1.c2,NULL)as d_c2,

[0146] from

[0147]

[0148] It is understandable that after obtaining the target SQL statement, data query can be executed based on the target SQL statement. For example, after executing the data query based on the target SQL statement in the above example, the following table t1"' can be obtained:

[0149] Table t1"'

[0150] Count(c1) Count(c2) 3 3

[0151] Thus, the deduplication aggregation results of each first to-be-aggregated column c1 and c2 in table t1 can be obtained.

[0152] The SQL statement processing method provided in the embodiment of this specification first obtains the SQL statement to be processed, which includes a table to be queried and a Distinct aggregation function for each first column to be aggregated in the table to be queried, and the serial number of each first column to be aggregated constitutes a serial number table, so a target query table can be generated based on the table to be queried and the serial number table, and a subquery for the target query table can be generated, and finally the SQL statement to be processed can be rewritten according to the subquery to obtain the target SQL statement. Since the subquery uses group by to deduplicate each first column to be aggregated, the target SQL statement can deduplicate and aggregate each first column to be aggregated; the target SQL statement can achieve the same data query purpose as the SQL statement to be processed, and the target SQL statement does not contain a Distinct aggregation function, so when executing data queries based on the target SQL statement, the parallel capabilities of the system can be fully utilized to improve the efficiency of data queries.

[0153] In particular, it can be seen from the examples in the above steps S101, S102 and S103 that the SQL statement processing method rewrites the SQL statement to be processed, pushes the first column to be aggregated down to the subquery for grouping and deduplication, replacing Distinct, and then performs an aggregation operation on the first column to be aggregated after deduplication in the subquery; that is, the SQL statement processing method only adds a rewrite rule in the rewrite stage, and does not make any changes to the optimization and execution stages, and does not perform intrusive operations such as custom processing on the execution engine, so it can fully utilize the parallel capabilities of the system and improve the efficiency of data query.

[0154] In some embodiments of the present specification, the table to be queried further includes at least one first column to be queried, and the SQL statement to be processed includes the at least one first column to be queried and a group by with the at least one first column to be queried as a key value; illustratively, the SQL statement to be processed can be an SQL query statement (i.e., a Select statement), and its query item can also include: the at least one first column to be queried.

[0155] For example, if the at least one first column to be queried and a group by statement with the at least one first column to be queried as a key value are added to the SQL statement to be processed in the example of step S101, the SQL statement to be processed may be:

[0156]

[0157]

[0158] The table to be queried t1 can be as follows:

[0159] Table t1

[0160]

[0161] Taking the table to be queried t1 in this embodiment as an example, the code representing the target query table generation process may be: t1

[0162] inner join

[0163] (select 1as dup_code union all select 2as dup_code)dup;

[0164] The generated target query table t1' can be as follows:

[0165] Table t1'

[0166]

[0167]

[0168] It can be understood that the target query table can also include at least one second column to be queried, wherein the at least one second column to be queried corresponds one-to-one to the at least one first column to be queried; that is, the target query table includes a sequence number column, multiple second columns to be aggregated, and at least one second column to be queried, the multiple second columns to be aggregated correspond one-to-one to the multiple first columns to be aggregated, the at least one second column to be queried corresponds one-to-one to the at least one first column to be queried, and each sequence number in the sequence number column serves as a row label for the same row of data. For example, the target query table t1' includes a sequence number column, second columns to be aggregated c1 and c2, and a second column to be queried c3, wherein the second column to be aggregated c1 corresponds to the first column to be aggregated c1 in the table to be queried t1, that is, the first column to be aggregated c1 forms the second column to be aggregated c1 after being connected with the sequence number table; the second column to be aggregated c2 corresponds to the first column to be aggregated c2 in the table to be queried t1, that is, the first column to be aggregated c2 forms the second column to be aggregated c2 after being connected with the sequence number table; the second column to be queried c3 corresponds to the first class to be queried c3 in the table to be queried t1, that is, the first column to be queried c3 forms the second column to be queried c3 after being connected with the sequence number table; each sequence number in the sequence number column in the target query table is used as the row label of the row, that is, the row label of the data in the row.

[0169] Based on the target query table, when generating a subquery, the at least one second column to be queried can be added to the subquery. That is, a value function for each second column to be aggregated, the at least one second column to be queried, and a group by statement with the multiple third columns to be aggregated and the at least one third column to be queried as key values are added to the subquery, wherein the at least one third column to be queried has a one-to-one correspondence with the at least one second column to be queried. The subquery can be a query statement (i.e., a Select statement), whose query items include: the result of the first value function for each second column to be aggregated, and the at least one second column to be queried.

[0170] Continuing to take the SQL statement to be processed, the table to be queried t1, and the target query table t1' in the above example of this embodiment as an example, the subquery for the target query table may be:

[0171]

[0172] The result of the subquery can be the following table t1":

[0173] Table t1"

[0174] c3 d_c1 d_c2 Female Alice NULL Female NULL Switch Female NULL PS5 Female NULL Xbox Male Bob NULL Male David NULL Male NULL PS5 Male NULL Xbox Male NULL Switch

[0175] The table t1″ includes third columns to be aggregated d_c1 and d_c2, and a third column to be queried c3. The third column to be aggregated d_c1 is the result of a function applied to the second column to be aggregated c1, the third column to be aggregated d_c2 is the result of a function applied to the second column to be aggregated c2, and the third column to be queried c3 corresponds to the second column to be queried.

[0176] Based on the above subquery, when rewriting the SQL statement to be processed, the at least one third column to be queried and the group by with the at least one third column to be queried as the key value can be added to the target SQL statement, that is, the aggregate function for each third column to be aggregated in the result of the subquery, the at least one third column to be queried and the group by with the at least one third column to be queried as the key value are added to the target SQL statement, wherein the at least one third column to be queried corresponds one-to-one with the at least one second column to be queried. It can be understood that the target SQL statement can be an SQL query statement (i.e., a Select statement), and its query items include: the result of the aggregate function (such as a count function) for each third column to be aggregated in the result of the subquery, and the at least one third column to be queried.

[0177] Continuing with the above example of the SQL statement to be processed, the table to be queried t1, the target query table t1′ and the result table t″ of the subquery, the target SQL statement obtained by rewriting the SQL statement to be processed based on the subquery can be:

[0178]

[0179]

[0180] group by c3;

[0181] It is understandable that after obtaining the target SQL statement, data query can be executed based on the target SQL statement. For example, after executing the data query based on the target SQL statement in the above example, the following table t1"' can be obtained:

[0182] Table t1"'

[0183] Count(c1) Count(c2) c3 1 3 Female 2 3 Male

[0184] Thus, the deduplication aggregation results of each first to-be-aggregated column c1 and c2 in each group of data grouped according to c3 can be obtained.

[0185] In some implementations of this specification, the table to be queried also includes at least one first column to be summed, and the SQL statement to be processed also includes a summation function for each first column to be summed; illustratively, the SQL statement to be processed can be an SQL query statement (i.e., a Select statement), and its query item can also include: the result of the summation function (e.g., Sum) for each first column to be summed.

[0186] For example, if a summation function for each first column to be summed is added to the SQL statement to be processed in the example of the previous embodiment, the SQL statement to be processed may be:

[0187] create table t1(c1 int,c2 int,c3 int,c4 int);

[0188] Q1:

[0189] select

[0190] c3,

[0191] count(distinct c1)as c1_cnt,

[0192] count(distinct c2)as c2_cnt,

[0193] sum(c4) as c4_sum

[0194] from t1 group by c3;

[0195] The table to be queried t1 can be as follows:

[0196] Table t1

[0197]

[0198]

[0199] Taking the table to be queried t1 in this embodiment as an example, the code representing the target query table generation process may be:

[0200] t1

[0201] inner join

[0202] (select 1as dup_code union all select 2as dup_code)dup;

[0203] The generated target query table t1' can be as follows:

[0204] Table t1'

[0205]

[0206] It can be understood that the target query table can also include at least one second column to be summed, wherein the at least one second column to be summed corresponds one-to-one to the at least one first column to be summed; that is, the target query table includes a sequence number column, multiple second columns to be aggregated, at least one second column to be queried and at least one second column to be summed, the multiple second columns to be aggregated correspond one-to-one to the multiple first columns to be aggregated, the at least one second column to be queried corresponds one-to-one to the at least one first column to be queried, the at least one second column to be summed corresponds one-to-one to the at least one first column to be summed, and each sequence number in the sequence number column serves as a row label for the same row of data. For example, the target query table t1' includes a sequence number column, second to-be-aggregated columns c1 and c2, a second to-be-queried column c3, and a second to-be-summed column c4, wherein the second to-be-aggregated column c1 corresponds to the first to-be-aggregated column c1 in the query table t1, that is, the first to-be-aggregated column c1 is formed after being connected with the sequence number table to form the second to-be-aggregated column c1; the second to-be-aggregated column c2 corresponds to the first to-be-aggregated column c2 in the query table t1, that is, the first to-be-aggregated column c2 is formed after being connected with the sequence number table to form The second column to be aggregated c2; the second column to be queried c3 corresponds to the first class to be queried c3 in the table to be queried t1, that is, the first column to be queried c3 is formed after being connected with the sequence number table to form the second column to be queried c3; the second column to be summed c4 corresponds to the first column to be summed c4 in the table to be queried t1, that is, the first column to be summed c4 is formed after being connected with the sequence number table to form the second column to be summed c4; each sequence number in the sequence number column in the target query table is used as the row label of the row, that is, the row label of the data in the row.

[0207] Based on the above target query table, when generating a subquery, a second value function for each second column to be summed can be added to the subquery, and a sum function for each second value function can be added, wherein the second value function is used to retain the data whose row label is the sequence number corresponding to the second column to be summed, and to set the data whose row label is not the sequence number corresponding to the second column to be summed to blank, and the sequence number corresponding to the second column to be summed is the sequence number of the corresponding first column to be summed; that is, the first value function for each second column to be aggregated, the at least one second column to be queried, a group by with the multiple third columns to be aggregated and the at least one third column to be queried as key values, the second value function for each second column to be summed, and the sum function for each second value function can be added to the subquery. The subquery can be a query statement (i.e., a Select statement), and its query items include: the result of the first value function for each second column to be aggregated, the at least one second column to be queried, and the results of the multiple sum functions for the second value functions.

[0208] Note that each first column to be summed has a different sequence number; the sequence number of each first column to be summed is the same as the sequence number of any first column to be aggregated. This means that the first column to be summed reuses the sequence number of the first column to be aggregated. For example, if the table to be queried includes two first columns to be aggregated and one first column to be summed, and the sequence numbers of the two first columns to be aggregated are 1 and 2, respectively, the sequence number of the first column to be summed can be 1 or 2.

[0209] Continuing to take the SQL statement to be processed, the table to be queried t1, and the target query table t1' in the above example of this embodiment as an example, the subquery for the target query table may be:

[0210]

[0211]

[0212] The result of the subquery can be the following table t1":

[0213] Table t1"

[0214] c3 d_c1 d_c2 d_c4 Female Alice NULL 600 Female NULL Switch NULL Female NULL PS5 NULL Female NULL Xbox NULL Male Bob NULL 300 Male David NULL 500 Male NULL PS5 NULL Male NULL Xbox NULL Male NULL Switch NULL

[0215] The above table t1" includes the third columns to be aggregated d_c1, d_c2, the third column to be queried c3, and the third column to be summed c4, wherein the third column to be aggregated d_c1 is the result of the value function for the second column to be aggregated c1, the third column to be aggregated d_c2 is the result of the value function for the second column to be aggregated c2, the third column to be queried c3 corresponds to the second column to be queried, and the third column to be summed is the result of the summation function of the second value function on the second summation column.

[0216] Based on the above subquery, when rewriting the SQL statement to be processed, the at least one third column to be summed can be added to the target SQL statement, that is, the aggregate function for each third column to be aggregated in the result of the subquery, the at least one third column to be queried, the at least one third column to be summed, and a group by with the at least one third column to be queried as the key value are added to the target SQL statement, wherein the at least one third column to be queried corresponds one-to-one with the at least one second column to be queried, and the at least one third column to be summed is the result of multiple summation functions for the second value function. It can be understood that the target SQL statement can be an SQL query statement (i.e., a Select statement), and its query items include: the result of the aggregate function (such as a count function) for each third column to be aggregated in the result of the subquery, the at least one third column to be queried, and the at least one third column to be summed.

[0217] Continuing with the above example of the SQL statement to be processed, the table to be queried t1, the target query table t1′ and the result table t″ of the subquery, the target SQL statement obtained by rewriting the SQL statement to be processed based on the subquery can be:

[0218]

[0219]

[0220] It is understandable that after obtaining the target SQL statement, data query can be executed based on the target SQL statement. For example, after executing the data query based on the target SQL statement in the above example, the following table t1"' can be obtained:

[0221] Table t1"'

[0222] Count(c1) Count(c2) c3 Sum(c4) 1 3 Female 600 2 3 Male 800

[0223] Thus, the deduplication aggregation results and summation results of each first to-be-aggregated column c1 and c2 in each group of data grouped by c3 can be obtained.

[0224] Figure 2 This is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 2 At the hardware level, the device includes a processor 202, an internal bus 204, a network interface 206, a memory 208, and a non-volatile memory 210. Of course, it may also include hardware required for other tasks. One or more embodiments of this specification can be implemented based on software, such as the processor 202 reading the corresponding computer program from the non-volatile memory 210 into the memory 208 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0225] Please refer to Figure 3 , the SQL statement processing device can be applied to Figure 2 The device shown in the figure is used to implement the technical solution of this specification. The SQL statement processing device may include:

[0226] An acquisition module 301 is configured to acquire a SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated;

[0227] A subquery module 302 is configured to generate a target query table based on the table to be queried and the sequence number table, and to generate a subquery for the target query table, wherein the sequence number table includes a table consisting of the sequence numbers of each first column to be aggregated, and the subquery uses a group by operation to remove duplicates from each first column to be aggregated;

[0228] The rewriting module 303 is configured to rewrite the SQL statement to be processed according to the subquery to obtain a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.

[0229] In some embodiments of the present specification, the sequence number table includes a table obtained by combining the sequence numbers of each first column to be aggregated.

[0230] In some embodiments of this specification, when the sub-query module is used to generate a target query table according to the table to be queried and the sequence number table, it is specifically used to:

[0231] The table to be queried and the sequence number table are inner-joined or cross-joined to obtain the target query table.

[0232] In some embodiments of the present specification, the target query table includes a sequence number column and a plurality of second columns to be aggregated, the plurality of second columns to be aggregated correspond one-to-one to the plurality of first columns to be aggregated, and each sequence number in the sequence number column serves as a row label for data in the same row;

[0233] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0234] Add a first value-taking function for each second column to be aggregated and a group by with multiple third columns to be aggregated as key values in the subquery, wherein the first value-taking function is used to retain data with row labels corresponding to the sequence numbers of the second column to be aggregated, and to set data with row labels other than the sequence numbers corresponding to the second column to be aggregated to blank, the sequence number corresponding to the second column to be aggregated is the sequence number of the corresponding first column to be aggregated, and the multiple third columns to be aggregated are the results of multiple first value-taking functions for the second column to be aggregated.

[0235] In some embodiments of this specification, the rewriting module is specifically used to:

[0236] An aggregate function for each third to-be-aggregated column in the result of the subquery is added to the target SQL statement.

[0237] In some embodiments of the present specification, the table to be queried includes at least one first column to be queried, the SQL statement to be processed includes at least some of the first columns to be queried, and a group by statement with the at least one first column to be queried as a key value;

[0238] The target query table includes at least one second to-be-queried column, wherein the at least one second to-be-queried column corresponds one-to-one to the at least one first to-be-queried column;

[0239] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0240] Adding the at least one second to-be-queried column to the subquery, wherein the groupby in the subquery uses the plurality of third to-be-aggregated columns and the at least one third to-be-queried column as key values, wherein the at least one third to-be-queried column has a one-to-one correspondence with the at least one second to-be-queried column;

[0241] The rewriting module is specifically used for:

[0242] Add the at least one third column to be queried and a group by statement using the at least one third column to be queried as a key value in the target SQL statement.

[0243] In some embodiments of the present specification, the table to be queried includes at least one first column to be summed, and the SQL statement to be processed includes a summation function for each first column to be summed;

[0244] The target query table includes at least one second column to be summed, wherein the plurality of second columns to be summed correspond one-to-one to the plurality of first columns to be summed;

[0245] When the subquery module is used to generate a subquery for the target query table, it is specifically used to:

[0246] Adding a second value function for each second column to be summed within the subquery, and adding a summation function for each second value function, wherein the second value function is used to retain data whose row label is the sequence number corresponding to the second column to be summed, and to set data whose row label is not the sequence number corresponding to the second column to be summed to blank, and the sequence number corresponding to the second column to be summed is the sequence number of the corresponding first column to be summed;

[0247] The rewriting module is specifically used for:

[0248] The at least one third column to be summed is added to the target SQL statement, wherein the at least one third column to be summed is a result of multiple summation functions for the second value function.

[0249] In some embodiments of this specification, the sequence number of each first to-be-aggregated column is different; and / or,

[0250] The sequence number of each first column to be summed is different; and / or,

[0251] The sequence number of each first column to be summed is the same as the sequence number of any first column to be aggregated.

[0252] In some embodiments of this specification, a sequence number module is further included, which is used to:

[0253] Add a sequence number to each first column to be aggregated and each first column to be summed.

[0254] In some embodiments of this specification, the acquisition module is specifically configured to:

[0255] Determine whether the SQL statement used for data query contains multiple Distinct aggregate functions;

[0256] In the case that there are multiple SQL statements with Distinct aggregate functions in the SQL statement for data query, the SQL statement for data query is determined as the SQL statement to be processed.

[0257] In some embodiments of the present specification, an execution module is further included, which is used to:

[0258] Execute data query based on the target SQL statement.

[0259] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email transceiver, game console, tablet computer, wearable device, or any combination of these devices.

[0260] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0261] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0262] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, 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 technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0263] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0264] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0265] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "an," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0266] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0267] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when..." or "when..." or "in response to determining."

[0268] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included in the scope of protection of one or more embodiments of this specification.

Claims

1. A method for processing an SQL statement, comprising: Obtaining a SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated; Inner-join or cross-join the table to be queried and the sequence table to obtain a target query table, and generate a subquery for the target query table, wherein the sequence table includes a table consisting of the sequence numbers of each first column to be aggregated, the subquery is used to set to null the data with sequence numbers that do not correspond to the row labels in the first column to be aggregated, and perform a group by operation using the multiple first columns to be aggregated as key values, and the sequence numbers in the sequence table are the row labels of the data in the same row; The subquery and an aggregate function for each first column to be aggregated in a result of the subquery are determined as a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first column to be aggregated.

2. The SQL statement processing method according to claim 1, wherein the sequence number table includes a table obtained by combining the sequence numbers of each first column to be aggregated.

3. The method for processing SQL statements according to claim 1, wherein the target query table comprises a sequence number column and a plurality of second columns to be aggregated, the plurality of second columns to be aggregated corresponding to the plurality of first columns to be aggregated one by one, and each sequence number in the sequence number column serves as a row label for the same row of data; Generating a subquery for the target query table includes: Add a first value-taking function for each second column to be aggregated and a group by with multiple third columns to be aggregated as key values in the subquery, wherein the first value-taking function is used to retain data with row labels corresponding to the sequence numbers of the second column to be aggregated, and to set data with row labels other than the sequence numbers corresponding to the second column to be aggregated to blank, the sequence number corresponding to the second column to be aggregated is the sequence number of the corresponding first column to be aggregated, and the multiple third columns to be aggregated are the results of multiple first value-taking functions for the second column to be aggregated.

4. The method for processing an SQL statement according to claim 1, wherein the table to be queried includes at least one first column to be queried, the SQL statement to be processed includes the at least one first column to be queried, and a group by statement using the at least one first column to be queried as a key value; The target query table includes at least one second column to be queried, wherein: The at least one second column to be queried corresponds to the at least one first column to be queried in a one-to-one manner; The generating of a subquery for the target query table further includes: Adding the at least one second to-be-queried column to the subquery, wherein the group by statement in the subquery uses the plurality of third to-be-aggregated columns and the at least one third to-be-queried column as key values, wherein the at least one third to-be-queried column has a one-to-one correspondence with the at least one second to-be-queried column; The step of rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement includes: Add the at least one third column to be queried and a group by statement using the at least one third column to be queried as a key value in the target SQL statement.

5. The method for processing an SQL statement according to claim 1, wherein the table to be queried comprises at least one first column to be summed, and the SQL statement to be processed comprises a summation function for each first column to be summed; The target query table includes at least one second column to be summed, wherein: The plurality of second columns to be summed correspond one-to-one to the plurality of first columns to be summed; The generating of a subquery for the target query table further includes: Adding a second value function for each second column to be summed within the subquery, and adding a summation function for each second value function, wherein the second value function is used to retain data whose row label is the sequence number corresponding to the second column to be summed, and to set data whose row label is not the sequence number corresponding to the second column to be summed to blank, and the sequence number corresponding to the second column to be summed is the sequence number of the corresponding first column to be summed; The step of rewriting the SQL statement to be processed according to the subquery to obtain a target SQL statement includes: The at least one third column to be summed is added to the target SQL statement, wherein the at least one third column to be summed is a result of multiple summation functions for the second value function.

6. The method for processing SQL statements according to claim 5, wherein the sequence number of each first column to be aggregated is different; and / or, The sequence number of each first column to be summed is different; and / or, The sequence number of each first column to be summed is the same as the sequence number of any first column to be aggregated.

7. The method for processing SQL statements according to claim 5, further comprising: Add a sequence number to each first column to be aggregated and each first column to be summed.

8. The method for processing SQL statements according to claim 1, wherein obtaining the SQL statement to be processed comprises: Determine whether the SQL statement used for data query contains multiple Distinct aggregate functions; In the case that there are multiple SQL statements with Distinct aggregate functions in the SQL statement for data query, the SQL statement for data query is determined as the SQL statement to be processed.

9. The method for processing SQL statements according to claim 1, further comprising: Execute data query based on the target SQL statement.

10. A device for processing SQL statements, comprising: An acquisition module is configured to acquire a SQL statement to be processed, wherein the SQL statement to be processed includes a table to be queried and an aggregation function with Distinct for each first column to be aggregated in the table to be queried, and the table to be queried includes multiple first columns to be aggregated; A subquery module is configured to inner-join or cross-join the table to be queried and the sequence number table to obtain a target query table, and to generate a subquery for the target query table, wherein the sequence number table includes a table consisting of the sequence numbers of each first column to be aggregated, the subquery is configured to set to null the data with sequence numbers that do not correspond to the row labels in the first column to be aggregated, and to perform a group by operation using the multiple first columns to be aggregated as key values, and the sequence numbers in the sequence number table are the row labels of the data in the same row; The rewriting module is used to determine the subquery and the aggregation function for each first to-be-aggregated column in the result of the subquery as a target SQL statement, wherein the target SQL statement deduplicates and aggregates each first to-be-aggregated column.

11. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 9 by running the executable instructions.

12. A computer-readable storage medium having computer instructions stored thereon, wherein when the instructions are executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Method for generating complex structured query language (SQL) statement

    CN102222097A

  • Method and device for data aggregate query

    CN104504154A