WO2016112502A1 - Method, apparatus and computing device for storing query result - Google Patents

Method, apparatus and computing device for storing query result Download PDF

Info

Publication number
WO2016112502A1
WO2016112502A1 PCT/CN2015/070656 CN2015070656W WO2016112502A1 WO 2016112502 A1 WO2016112502 A1 WO 2016112502A1 CN 2015070656 W CN2015070656 W CN 2015070656W WO 2016112502 A1 WO2016112502 A1 WO 2016112502A1
Authority
WO
WIPO (PCT)
Prior art keywords
query
determining
target
primary key
request
Prior art date
Application number
PCT/CN2015/070656
Other languages
French (fr)
Chinese (zh)
Inventor
张军
林晓勇
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to CN201580001205.4A priority Critical patent/CN107735781B/en
Priority to PCT/CN2015/070656 priority patent/WO2016112502A1/en
Publication of WO2016112502A1 publication Critical patent/WO2016112502A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present invention relates to the field of databases and, more particularly, to methods and apparatus, computing devices that store query results.
  • TPC-H Transaction Processing Performance Council Benchmark TM H
  • TPC-H mainly involves the following concepts:
  • a fact table for storing at least one fact record, each fact record corresponding to a row in the fact table, and including a key value column and a metric value column, wherein the value in the key value column corresponds to a dimension of the fact record, for example, a commodity origin , item price, item quantity, transaction date, item type, item name, etc.; the value in the metric column corresponds to the subject matter of the fact table, for example, sales or sales volume, and so on.
  • the dimension table may include a name column and an attribute column.
  • the origin of the product includes three columns, a place name (locationName), a place number (locationId), and an address (Address). ), where the origin name is the name column, the origin number and address are attribute columns.
  • the key-value column in the fact table can correspond to the attribute column in the dimension table, and each key-value column in the fact table can correspond to a dimension table.
  • Temporary table for storing temporary data The temporary table can be roughly divided into a transaction-level temporary table and a session-level temporary table, wherein the transaction-level temporary table is automatically deleted after the transaction is committed, and the session-level temporary table is deleted after the session ends.
  • the primary key which uniquely identifies a column in the table, any two rows in a table have different primary key values, and the primary key does not allow null values.
  • the primary key of a table is the first column of the table.
  • a query statement can be decomposed into multiple query sub-statements and massively parallelized.
  • the Massively Parallel Processing (MPP) mechanism distributes the plurality of query sub-statements to a plurality of nodes of the cluster. Each node can query according to the received query sub-statement, and store the query result corresponding to the query sub-statement into the temporary table. After the plurality of nodes complete the query, the query statement may be used to perform an associative query on the temporary table obtained by each node to obtain a final query result.
  • MPP Massively Parallel Processing
  • the query table involved in the subquery in the complex query includes: a supplier table, a line item table, an orders table, a customer table, and a A country table named n1 and another country table named n2.
  • the query result obtained by the subquery is inserted into the shipping table, and then the data of the columns supp_nation, cust_nation, l_year, and the data of the column revenue obtained by summing the data of the column volume are selected from the table shipping.
  • the query statement corresponding to the above complex query may be decomposed into two query sub-sentences, wherein the first query sub-sentence is as shown in Table 2, and is used for table orders, table n1, table n2, and table customer. Perform an associative query and insert the query result into the temporary table q7_tmp_order_customer; the second query sub-statement is shown in Table 3, for the table lineitem, Table n1, table n2, and table supplier perform association query, and insert the query result into the temporary table q7_tmp_lineitem_supplier. Finally, the temporary table q7_tmp_order_customer and q7_tmp_lineitem_supplier can be correlated by the query statement shown in Table 4 to obtain the final query result.
  • the first query sub-sentence is as shown in Table 2, and is used for table orders, table n1, table n2, and table customer.
  • insert into[table A] indicates that the query result is inserted into the table A.
  • the primary key of the temporary table is not specified when the temporary table is created, the query result corresponding to the query substatement is stored.
  • the node When stored in a temporary table, the node will actively add a non-meaningful primary key to the temporary table. For example, as shown in Table 5, the node uses the column ID whose value is the row number as the primary key of the temporary table q7_tmp_lineitem_supplier, and uses the query result as Columns other than the primary key are inserted into the temporary table.
  • an index can be created for one column in at least one temporary table, but since the temporary table is only used by the current query, the cost of creating the index is high, and in addition, since the data of the temporary table needs to be inserted frequently, the index may be caused. Invalid.
  • the embodiments of the present invention provide a method, a device, and a computing device for storing query results, which can avoid the problem of low query efficiency when performing related queries in the prior art.
  • the first aspect provides a method for storing a query result, including: determining a plurality of query tables corresponding to the first query request, wherein the first query request is used to request an association query for the plurality of query tables; Determining a target query table in the plurality of query tables, wherein the fact table of the target query table does not exist in the plurality of query tables, and the target query table is at least one of the plurality of query tables except the target query table Querying a fact table of the table; determining, according to the target query table, a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; and the query result is obtained according to the primary key of the first table Stored to the first table.
  • the storing the query result to the first table according to the primary key of the first table includes: storing the query result in a column cluster manner according to the primary key of the first table To the first table.
  • the determining the target query table from the multiple query tables includes: determining at least one first associated query condition corresponding to the first query request, where The first associated query condition is composed of a first column in the first query table and a second column in the second query table, the plurality of query tables including the first query table and the first query table different from the first query table a second query table; determining an association relationship between the first query table and the second query table corresponding to the at least one first associated query condition; and according to the relationship between the first query table and the second query table, The target lookup table is determined in the first lookup table and the second lookup table.
  • determining the association relationship between the first query table and the second query table includes: determining a first column of the first query table Whether it is the primary key of the first query table; if the first column of the first query table is the primary key of the first query table, determining that the second query table is the fact table of the first query table; if the first query The first column of the table is a foreign key of the first query table, and the first query table is determined to be a fact table of the second query table.
  • the first query request corresponds to a first associated query condition
  • the third determining sub-unit is specifically configured to: if the second determining sub-unit determines the first The second lookup table is the fact table of the first query table, and the second query table is determined to be the target query table; if the second determining subunit determines that the first query table is the fact table of the second query table, The first query table is determined to be the target query table.
  • the first query request corresponds to multiple first associated query conditions; and according to the relationship between the first query table and the second query table, Determining the target query table from the first query table and the second query table, comprising: establishing an association relationship tree according to an association relationship between the first query table and the second query table, wherein, if the second The query table is a fact table of the first query table, and the second query table is a parent node of the first query table; the root node of the relationship tree is determined as the target query table.
  • determining the primary key of the first table according to the target query table includes: determining whether the target query table exists in multiple columns corresponding to the query result The non-federated primary key; if the non-federal primary key of the target query table exists in the plurality of columns, the non-union primary key of the target query table is determined as the primary key of the first table.
  • determining the primary key of the first table according to the target query table further includes: if the target query table does not exist in the multiple columns Determining, by the primary key, a second query request corresponding to the first query request, the second query request is used to request an association query for the first table and the second table; and determining, according to the second query request, the first table Primary key.
  • the determining, by the second query request, the primary key of the first table includes: determining at least one second associated query condition corresponding to the second query request
  • the second associated query condition is composed of a third column of the first table and a fourth column of the second table; determining a second target associated query condition from the at least one second associated query condition, the second
  • the target association query condition includes a primary key of the second table; the third column of the first table included in the second target association query condition is determined as a primary key of the first table.
  • the second aspect provides an apparatus for storing a query result, including: a first determining unit, configured to determine a plurality of query tables corresponding to the first query request, where the first query request is used to request a pair The plurality of lookup tables are associated with the query; the second determining unit is configured to determine a target query table from the plurality of query tables determined by the first determining unit, where the target query table does not exist in the plurality of query tables a fact table, and the target query table is a fact table of at least one query table of the plurality of query tables except the target query table; and a third determining unit, configured to determine the target query table according to the second determining unit Determining a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; and the storage unit is configured to use the primary key of the first table determined by the third determining unit to query the query The result is stored to the first table.
  • the storage unit is configured to: store the query result in the column cluster to the first table according to the primary key of the first table determined by the third determining unit.
  • the second determining unit includes: a first determining sub-unit, configured to determine at least one first associated query condition corresponding to the first query request, where The first associated query condition is composed of a first column in the first query table and a second column in the second query table, the plurality of query tables including the first query table and the first query table different from the first query table a second determining sub-unit, configured to determine an association relationship between the first query table and the second query table corresponding to the at least one first associated query condition determined by the first determining sub-unit; a determining subunit, configured to determine the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table determined by the second determining subunit .
  • the second determining sub-unit is specifically configured to: determine whether the first column in the first query table is a primary key of the first query table; The first column in the first query table is the primary key of the first query table, and the second query table is determined to be the fact table of the first query table; if the first column in the first query table is the first query The foreign key of the table determines that the first lookup table is a fact table of the second lookup table.
  • the first query request corresponds to a first associated query condition
  • the third determining sub-unit is specifically configured to: if the second determining sub-unit determines the first The second lookup table is the fact table of the first query table, and the second query table is determined to be the target query table; if the second determining subunit determines that the first query table is the fact table of the second query table, The first query table is determined to be the target query table.
  • the first query request is corresponding to multiple first associated query conditions; the third determining sub-unit is specifically configured to: determine, according to the second determining sub-unit Establishing an association relationship between the first query table and the second query table a tree, wherein the second query table is a fact table of the first query table, the second query table is a parent node of the first query table; and the root node of the relationship tree is determined as the target query table .
  • the third determining unit includes: a fourth determining sub-unit, configured to determine whether the target query table is not present in the multiple columns corresponding to the query result a first determining sub-unit, configured to determine, when the fourth determining sub-unit determines that the non-co-primary primary key of the target query table exists in the plurality of columns, determining the non-union primary key of the target query table as the first table Primary key.
  • the third determining unit further includes: a sixth determining subunit, configured to determine, if the fourth determining subunit, the target does not exist in the multiple columns Querying a non-joined primary key of the table, determining a second query request corresponding to the first query request, the second query request is used to request an association query for the first table and the second table; and the seventh determining subunit is configured to: Determining the primary key of the first table according to the second query request determined by the sixth determining subunit.
  • the seventh determining sub-unit is specifically configured to: determine at least one second associated query condition corresponding to the second query request, where the second associated query The condition is composed of a third column of the first table and a fourth column of the second table; determining a second target associated query condition from the at least one second associated query condition, the second target associated query condition including the second a primary key of the table; determining a third column of the first table included in the second target association query condition as a primary key of the first table.
  • a computing device comprising: a processor, a memory, and a bus; the memory is configured to store a computer to execute instructions, the processor is coupled to the memory via the bus, and when the computing device is running, the processor The computer-executed instructions stored in the memory are read to perform the method of storing the query results in the first aspect or any of the possible implementations of the first aspect.
  • the method and device for storing a query result and the computing device provided by the embodiment of the present invention determine a target query table from a plurality of query tables corresponding to the first query request, where the target query table is the multiple query a fact table of at least one query table other than the target query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a first one for storing the query result according to the target query table
  • the primary key of the table can avoid the problem that the query efficiency is low when the related query of the first table is subsequently performed due to the column having no practical meaning as the primary key of the first table in the prior art, thereby improving the efficiency of the related query.
  • FIG. 1 is a schematic flowchart of a method for storing a query result according to an embodiment of the present invention.
  • FIG. 2 is another schematic flowchart of a method for storing a query result according to an embodiment of the present invention.
  • FIG. 3 is a schematic diagram of an association tree in an example of a method for storing a query result according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of another association tree in an example of a method for storing a query result according to an embodiment of the present invention.
  • FIG. 5 is a schematic block diagram of an apparatus for storing a query result according to an embodiment of the present invention.
  • FIG. 6 is a schematic block diagram of another apparatus for storing a query result according to an embodiment of the present invention.
  • FIG. 7 is a schematic block diagram of a computing device provided by an embodiment of the present invention.
  • RDBMS Relational Database Management System
  • NoSQL non-relational
  • MPP-DB massively parallel processing database
  • the embodiment of the present invention is described by using a Structured Query Language (SQL) language as an example.
  • SQL Structured Query Language
  • the embodiment of the present invention may also adopt other languages, for example, an object-oriented query language (Hibernate Query Language, HQL).
  • HQL object-oriented query language
  • the embodiment of the present invention does not limit this.
  • FIG. 1 is a schematic flowchart of a method 100 for storing a query result according to an embodiment of the present invention.
  • the method 100 may be performed by a device that stores a query result.
  • the device for storing the query result may be specifically a standalone device or a module in the device, for example, the device for storing the query result. It may be a stand-alone or a cluster node, but the embodiment of the present invention is not limited thereto.
  • S110 Determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an association query for the plurality of query tables.
  • the device storing the query result may receive a first query request from the client, wherein the first query request from the client may be forwarded to the device storing the query result by the network device or other device.
  • the first query request may request an association query for the plurality of query tables.
  • the query statement corresponding to the first query request may be as shown in any table in Tables 1 to 4.
  • the first query request may be an independent query, or may be a subquery of a complex query, which is not limited by the embodiment of the present invention.
  • the device storing the query result may determine, according to the first query request, a plurality of query tables corresponding to the first query request, and perform an associative query on the plurality of first tables.
  • the query statement corresponding to the first query request may include a where statement, and the query condition defined by the where statement may include an associated query condition.
  • the associated query condition may be composed of column M in table A and column N in table B, and column M and column N may be connected by an equal sign in the query statement, for example, in the query condition shown in Table 1, the query statement
  • S120 Determine a target query table from the plurality of query tables, where the target query table is a fact table of at least one query table of the plurality of query tables except the target query table, and the plurality of query tables are There is no fact table for the target lookup table.
  • the plurality of lookup tables include the target lookup table.
  • the target query table may be a fact table of one or more other tables in the plurality of query tables, but the fact table of the target query table is not included in the plurality of query tables.
  • the device that stores the query result may determine the target query table from the plurality of query tables according to the query condition included in the first query request, but the embodiment of the present invention is not limited thereto.
  • the means for storing the query result can determine to store the query result to the first table in a plurality of ways.
  • the first query request may request to store the query result of the associated query for the plurality of query tables to the first table, where the first table may be a normal table or a temporary table, and correspondingly, the first query request
  • the corresponding query statement may include an insert into statement, and the device storing the query result determines the first table according to the first query request.
  • the device storing the query result may The first table may be a temporary table, but the embodiment of the present invention is not limited thereto.
  • the query result may include data of a plurality of columns corresponding to the target record in the plurality of query tables, wherein the data of the plurality of columns corresponding to the target record may include data of at least one column in the target record, or
  • the data obtained by performing the mathematical operation on the data of the at least one column in the target record may be an index value or a character string, which is not limited in the embodiment of the present invention.
  • the target query table is determined from the plurality of query tables corresponding to the first query request, wherein the target query table is the target query table among the plurality of query tables.
  • the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
  • the plurality of columns corresponding to the query result may include the primary key of the first table, and correspondingly, in S140, the device storing the query result may include the plurality of columns corresponding to the query result.
  • the other column than the primary key of the first table is inserted into the first table in the form of a non-primary key.
  • the device storing the query result may store a plurality of columns corresponding to the query result in a column family manner, so that the The primary key in the first table does not have a duplicate value, but the embodiment of the present invention is not limited thereto.
  • S140 storing the query result to the first table according to the primary key of the first table, including:
  • the query result is stored in the first table in the form of a column cluster according to the primary key of the first table.
  • the temporary table q7_tmp_order_customer obtained by the first query sub-statement shown in Table 2 may be stored in the form of a column cluster shown in Table 6, and the temporary table q7_tmp_lineitem_supplier obtained by the second query sub-statement shown in Table 3 may be The column cluster form shown in Table 7 is stored.
  • the device storing the query result may determine whether the first table exists, and if the first table does not exist, The means for storing the query result may first establish the first table, then insert the query result into the first table and store the first table. If the first table already exists, the device storing the query result may directly insert the query result into the first table, or first delete the first table and re-establish the first table, and then insert the query result into the newly created first
  • the first table is stored in a table, but the embodiment of the invention is not limited thereto.
  • the device storing the query result may determine the target query table from the plurality of lookup tables in a plurality of manners.
  • the device storing the query result may determine the target query table from the plurality of query tables according to the at least one first associated query condition corresponding to the first query request.
  • determining a target query table from the plurality of lookup tables including:
  • S121 Determine at least one first associated query condition corresponding to the first query request, where the first associated query condition is formed by a first column in the first query table and a second column in the second query table, where the multiple The lookup table includes the first lookup table and the second lookup table different from the first lookup table;
  • S123 Determine the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table.
  • the means for storing the query result may determine the target lookup table from the table lineitem, the table supplier, and the table n1.
  • S122 determining an association relationship between the first query table and the second query table, including:
  • first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
  • first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
  • the device storing the query result may determine the first A lookup table is a dimension table of the second lookup table, and the second lookup table is a fact table of the first lookup table.
  • the device storing the query result determines that the first column is a foreign key of the first query table, indicating that the second column is a primary key of the second query table, and at this time, the device storing the query result
  • the first query table may be determined as a fact table of the second query table, and the second query table is a dimension table of the first query table.
  • the device storing the query result may also determine whether the second column is the second query table a primary key, if the second column is the primary key of the second lookup table, the means for storing the query result may determine that the first lookup table is a fact table of the second lookup table; and if the second column is the first
  • the device that stores the result of the query may determine that the second lookup table is a fact table of the first lookup table, but the embodiment of the present invention is not limited thereto.
  • the term "primary key” may refer to a column capable of uniquely identifying a row, that is, a non-joined primary key.
  • the primary key corresponds to one column, and may also mean capable of A plurality of columns that uniquely identify one row or a column that can uniquely identify a row together with other columns, that is, one of a joint primary key or a joint primary key.
  • the primary key corresponds to one of the plurality of columns or columns, which is not limited in this embodiment of the present invention. .
  • the device storing the query result may determine the second query The table is the target query table. If the first query request corresponds to the plurality of first associated query conditions, the device storing the query result may determine an association relationship between the two query tables in each of the first associated query conditions, and according to the plurality of first The association relationship between the two query tables in each of the first associated query conditions in the associated query condition is determined, and the target query table is determined. Still taking the second query sub-sentence shown in FIG.
  • the device storing the query result may determine an association relationship between the table lineitem and the table supplier and an association relationship between the table supplier and the table n1.
  • the typical form of the table lineitem can be as shown in Table 8, wherein orderkey and linenumber are used as the joint primary key of the table lineitem, and an orderkey value and a linenumber value can jointly identify one row in the table.
  • the typical form of the table supplier can be as shown in Table 9, where suppkey is the non-union primary key of the table supplier, which can identify one row in the table separately.
  • a typical form of the table nation named table n1 can be as shown in Table 10, where nationkey is the primary key of table n1.
  • the first query request corresponds to a first associated query condition
  • the S123 determines the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table, including:
  • the second lookup table is a fact table of the first lookup table, determining that the second lookup table is the target lookup table
  • the first lookup table is a fact table of the second lookup table, it is determined that the first lookup table is the target lookup table.
  • the association relationship between the first query table and the second query table is obtained from the first query.
  • the target query table is determined in the table and the second query table, including:
  • the second query table is the first query table, and the second query table is the first Query the parent node of the table;
  • the root node of the association tree is determined as the target query table.
  • the device storing the query result may use the fact table as the parent node of the dimension table, and one node may have multiple child nodes.
  • the parent node of the root node does not exist in the relationship tree, that is, the fact table of the root node is not included in the relationship tree, and the child node of the root node exists in the relationship tree, that is, the root node exists.
  • the dimension table therefore, the device storing the query result can determine the root node of the association tree as the target query table.
  • the device storing the query result can establish the association as shown in FIG.
  • the relationship tree wherein the line item table is the root node of the relationship tree, and therefore, the device storing the query result may determine that the table lineitem is the target query table corresponding to the second query sub-statement.
  • the storage query node 4 can be established according to the first query sub-statement shown in Table 2, wherein the root node of the association relationship tree is an orders table, so the storage query node
  • the device may determine that the table orders are the target query tables corresponding to the first query sub-statement shown in Table 2, but the embodiment of the present invention is not limited thereto.
  • S130 determining, according to the target query table, the primary key of the first table, including:
  • the non-union primary key of the target query table exists in the plurality of columns, the non-union primary key of the target query table is determined as the primary key of the first table.
  • the device storing the query result may determine whether the primary key of the target query table is a federated primary key or a non-unified primary key. If the primary key of the target query table is a joint primary key, the device storing the query result may determine the corresponding query result.
  • a non-federated primary key for the target query table does not exist in more than one column.
  • the target query table corresponding to the second query sub-statement is a table lineitem
  • the primary key of the table lineitem is a joint primary key composed of orderkey and linenumber
  • the device storing the query result may further determine whether a non-union primary key of the target query table exists in the multiple columns corresponding to the query result.
  • the target query table corresponding to the first query sub-statement is the table orders
  • the primary key of the table orders is orderkey
  • the device storing the query result can determine the first Whether the plurality of columns o_orderkey, n1.n_name, and n2.n_name corresponding to a query sub-statement includes the primary key orderkey of the table orders. Since the plurality of columns includes o_orderkey, the device storing the query result may use o_orderkey as the primary key of the temporary table q7_tmp_order_customer, but the embodiment of the present invention is not limited thereto.
  • S130 determining a primary key of the first table according to the target query table, further includes:
  • the second query request is used to request the first table and the first query The second table performs an associated query
  • the primary key of the first table is determined.
  • the non-federated primary key of the target query table does not exist, that is, the primary key of the target query table is specifically a union primary key, or if the primary key of the target query table is a non-union primary key, but the multiple columns corresponding to the query result do not include the The non-union primary key of the target query table, and the non-union primary key of the target query table does not exist in the multiple columns corresponding to the query result.
  • the device that stores the query result can be confirmed Determining whether there is a second query request corresponding to the first query request, if there is no second query request corresponding to the first query request, the device storing the query result may use a column having no meaning as the first The primary key of a table.
  • the device storing the query result may determine the primary key of the first table according to the second query request.
  • the second query request is used to perform an associative query on the first table and the second table
  • the first table is a temporary table q7_tmp_lineitem_supplier
  • the query statement shown in Table 4 is used for the temporary tables q7_tmp_order_customer and q7_tmp_lineitem_supplier
  • the query statement shown in Table 4 can be used as the second query request corresponding to the first query request shown in Table 3.
  • the device storing the query result may determine the primary key of the temporary table q7_tmp_lineitem_supplier according to the query statement shown in Table 4, but the embodiment of the present invention is not limited thereto.
  • the means for storing the query result may determine the primary key of the first table according to the second query request in a plurality of manners.
  • determining the primary key of the first table according to the second query request includes:
  • the third column of the first table included in the second target association query condition is determined as the primary key of the first table.
  • the second associated query condition may be composed of a third column of the first table and a fourth column of the second table
  • the device storing the query result may be from the at least one second associated query condition corresponding to the second query request Determining a second target association query condition, wherein the second target association query condition is composed of a third column of the first table and a fourth column of the second table, and the fourth column is a primary key of the second table.
  • the device storing the query result may determine the third column of the first table in the second target association query condition as the primary key of the first table, but the embodiment of the present invention is not limited thereto.
  • the second query request may be specifically used to request an association query for the first table and the at least one second table.
  • the device storing the query result may be from the multiple before the device storing the query result determines the second target association query condition Determining, in the second table, the second target table, wherein the second target table is a fact table of at least one of the plurality of second tables, and the fact that the second target table does not exist in the plurality of second tables table.
  • the device storing the query result may determine the second target query condition from the at least one second associated query condition corresponding to the second query request, where the second target query bar
  • the device is composed of a primary key of the second target table and a third column of the first table, and the device storing the query result may use the third column of the first table in the second target query condition as the first table
  • the primary key but the embodiment of the present invention is not limited thereto.
  • the query statement shown in Table 4 is the second query request corresponding to the second query sub-sentence, and the second query request is used for the first table.
  • the temporary table q7_tmp_lineitem_supplier, named table n2 and a second table (temporary table q7_tmp_order_customer, named table n1) for the associated query.
  • the primary key l_orderkey of the temporary table q7_tmp_lineitem_supplier corresponds to the primary key o_orderkey of the temporary table q7_tmp_order_customer, and there is no duplicate data in both.
  • the direct query can be performed without establishing an index, thereby Improve query efficiency and speed.
  • the target query table is determined from the plurality of query tables corresponding to the first query request, wherein the target query table is the target query table among the plurality of query tables.
  • the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
  • first, second, and third are used only to distinguish different contents, and should not be construed as limiting the embodiments of the present invention.
  • Embodiment of the present invention The first table and the second table are only for distinguishing different tables.
  • the first column in the first query table and the second column in the second query table are only for distinguishing among the related query conditions belonging to the first query table. Query the column and the query column belonging to the second query table.
  • the third column in the first table and the fourth column in the second table are only for distinguishing different columns, and the respective columns are not in the table. The specific location creates a limit.
  • FIG. 5 schematically illustrates an apparatus 200 for storing query results in accordance with an embodiment of the present invention.
  • the apparatus 200 includes:
  • the first determining unit 210 is configured to determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an associated query for the plurality of query tables;
  • a second determining unit 220 configured to determine a target query table from the plurality of query tables determined by the first determining unit 210, wherein a fact table of the target query table does not exist in the plurality of query tables, and the target query
  • the table is a fact table of at least one query table of the plurality of query tables except the target query table;
  • the third determining unit 230 is configured to determine a primary key of the first table according to the target query table determined by the second determining unit 220, where the first table is configured to store a query result corresponding to the first query request;
  • the storage unit 240 is configured to store the query result to the first table according to the primary key of the first table determined by the third determining unit 230.
  • the apparatus for storing a query result determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables.
  • the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
  • the apparatus 200 may further include:
  • a receiving unit configured to receive the first query request from the client before the first determining unit 210 determines the plurality of query tables corresponding to the first query request;
  • the query unit is configured to perform an associative query on the plurality of lookup tables according to the first query request received by the receiving unit.
  • the storage unit 240 is specifically configured to store the query result obtained by the query unit to the first table.
  • the storage unit 240 is configured to: store the query result to the first table in a column cluster manner according to the primary key of the first table determined by the third determining unit 230.
  • the second determining unit 220 includes:
  • a first determining subunit configured to determine at least one first associated query condition corresponding to the first query request, where the first associated query condition is determined by a first column in the first query table and a second query table a second column, the plurality of lookup tables including the first lookup table and the second lookup table different from the first lookup table;
  • a second determining subunit configured to determine an association relationship between the first query table and the second query table corresponding to the first associated query condition determined by the first determining subunit;
  • a third determining subunit configured to determine the target from the first query table and the second query table according to the association relationship between the first query table and the second query table determined by the second determining subunit Query the table.
  • the second determining subunit is specifically configured to:
  • first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
  • first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
  • the first query request corresponds to a first associated query condition
  • the third determining subunit is specifically configured to:
  • the second determining subunit determines that the second query table is a fact table of the first query table, determining that the second query table is the target query table;
  • the second determining subunit determines that the first query table is a fact table of the second query table, determining that the first query table is the target query table.
  • the first query request corresponds to multiple first associated query conditions.
  • the third determining sub-unit is specifically configured to:
  • the root node of the association tree is determined as the target query table.
  • the third determining unit 230 includes:
  • a fourth determining subunit configured to determine whether a non-union primary key of the target query table exists in multiple columns corresponding to the query result
  • a fifth determining subunit configured to determine, as the fourth determining subunit, the non-union primary key of the target query table in the plurality of columns, and determine the non-union primary key of the target query table as the primary key of the first table.
  • the third determining unit further includes:
  • a sixth determining subunit configured to: if the fourth determining subunit determines that the non-joined primary key of the target query table does not exist in the plurality of columns, determine a second query request corresponding to the first query request, the second query The request is used to request an association query for the first table and the second table;
  • a seventh determining subunit configured to determine a primary key of the first table according to the second query request determined by the sixth determining subunit.
  • the seventh determining subunit is specifically configured to:
  • the third column of the first table included in the second target association query condition is determined as the primary key of the first table.
  • the apparatus 200 for storing query results according to an embodiment of the present invention may correspond to an execution body of the method 100 of storing a query result according to an embodiment of the present invention, and storing the above and other operations of the respective modules in the apparatus 200 of the query result and/or
  • the functions are respectively implemented in order to implement the corresponding processes of the respective methods in FIG. 1 to FIG. 4, and are not described herein for brevity.
  • the apparatus for storing a query result determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables.
  • the column that has no practical meaning is used as the primary key of the first table.
  • the problem of inefficient query is caused by subsequent association query on the first table, thereby improving the efficiency of the associated query.
  • FIG. 6 schematically illustrates another apparatus 300 for storing query results in accordance with an embodiment of the present invention.
  • the apparatus 300 includes:
  • the processor 310 is configured to: determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an associated query for the plurality of query tables; and determine a target query table from the plurality of query tables The fact table of the target query table does not exist in the plurality of query tables, and the target query table is a fact table of at least one query table of the plurality of query tables except the target query table; according to the target Querying a table, determining a primary key of the first table, where the first table is configured to store a query result corresponding to the first query request;
  • the memory 320 is configured to store the query result to the first table according to the primary key of the first table determined by the processor 310.
  • the apparatus for storing a query result determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables.
  • the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
  • the processor 310 may be a central processing unit ("CPU"), and the processor 310 may also be other general-purpose processors, digital signal processors (DSPs). , an application specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, and the like.
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • the memory 320 can include read only memory and random access memory and provides instructions and data to the processor 310. A portion of the memory 320 may also include a non-volatile random access memory. For example, the memory 320 can also store information of the device type.
  • each step of the foregoing method may be completed by an integrated logic circuit of hardware in the processor 310 or an instruction in a form of software.
  • the steps of the method disclosed in the embodiments of the present invention may be directly implemented as a hardware processor, or may be performed by a combination of hardware and software modules in the processor.
  • Software modules can be located in random access memory, flash memory, read-only memory, programmable only Read memory or electrically erasable programmable memory, registers, etc. are well-known storage media in the field.
  • the storage medium is located in the memory 320, and the processor 310 reads the information in the memory 320 and combines the hardware to perform the steps of the above method. To avoid repetition, it will not be described in detail here.
  • the apparatus 200 may further include:
  • a receiver configured to receive the first query request from the client before the processor 310 determines the plurality of query tables corresponding to the first query request;
  • the processor 310 is further configured to perform an association query on the plurality of lookup tables according to the first query request received by the receiver.
  • the memory 320 is specifically configured to store the query result obtained by the processor 310 to the first table.
  • the memory 320 is specifically configured to: store the query result to the first table in a column cluster manner according to the primary key of the first table determined by the processor 310.
  • the processor 310 is specifically configured to:
  • the table includes the first lookup table and the second lookup table different from the first lookup table;
  • the processor 310 is specifically configured to:
  • first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
  • first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
  • the first query request corresponds to a first associated query condition
  • processor 310 is specifically configured to:
  • the second query table is a fact table of the first query table, determining that the second query table is the target query table;
  • the first query table is a fact table of the second query table, determining that the first query table is The target query table.
  • the first query request corresponds to multiple first associated query conditions.
  • the processor 310 is specifically configured to:
  • the second query table is the first query table, and the second query table is the first Query the parent node of the table;
  • the root node of the association tree is determined as the target query table.
  • the processor 310 is further configured to:
  • the non-union primary key of the target query table is determined as the primary key of the first table.
  • the processor 310 is further configured to:
  • the second query request is used to request to perform the first table and the second table Associated query;
  • the primary key of the first table is determined.
  • the processor 310 is specifically configured to:
  • the third column of the first table included in the second target association query condition is determined as the primary key of the first table.
  • the apparatus 300 for storing query results according to an embodiment of the present invention may correspond to an execution body of the method 100 of storing a query result according to an embodiment of the present invention, and storing the above and other operations of the respective modules in the apparatus 300 of the query result and/or
  • the functions are respectively implemented in order to implement the corresponding processes of the respective methods in FIG. 1 to FIG. 4, and are not described herein for brevity.
  • the apparatus for storing a query result determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a number for storing the query result according to the target query table.
  • the primary key of a table can avoid the problem that the query efficiency is low when the related query of the first table is subsequently performed due to the column having no practical meaning as the primary key of the first table in the prior art, thereby improving the efficiency of the associated query.
  • FIG. 7 schematically illustrates a computing device 400 in accordance with an embodiment of the present invention.
  • the computing device 400 includes a processor 402, a memory 404, and a bus 410.
  • the processor 402 and the memory 404 implement a communication connection with each other through the bus 410.
  • the processor 402 can be a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), or one or more integrated circuits for executing related programs.
  • CPU central processing unit
  • ASIC application specific integrated circuit
  • the memory 404 may be a read only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM).
  • Memory 404 can store operating systems and other applications.
  • the program code for implementing the technical solution provided by the embodiment of the present invention is stored in the memory 404 and executed by the processor 402.
  • the memory 404 can be used to store executable instructions, as well as to store various information, such as query results.
  • the processor 402 can read the information stored by the memory 404 via the bus system 410 or store the query results to the memory 404.
  • the processor 402 can execute executable instructions stored by the memory 404 to determine a plurality of lookup tables corresponding to the first query request, wherein the first query request is for requesting the plurality of lookup tables
  • the query table performs an association query; the target query table is determined from the plurality of query tables, wherein the fact table of the target query table does not exist in the plurality of query tables, and the target query table is the plurality of query tables a fact table of at least one query table other than the target query table; determining, according to the target query table, a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; The primary key of the table stores the query result to the first table.
  • the computing device can also include an input/output interface 406 and a communication interface 408.
  • the input/output interface 406 is for receiving input data and information, and outputting data such as operation results.
  • Communication interface 408 enables communication between computing device 400 and other devices or communication networks using transceivers such as, but not limited to, transceivers.
  • Bus 410 may include a path for communicating information between various components of computing device 400, such as processor 402, memory 404, input/output interface 406, and communication interface 408.
  • FIG. 7 and the foregoing description are applicable to performing various methods for storing query results provided by the embodiments of the present invention.
  • the various method flows shown in FIG. 1 to FIG. 4 are omitted for brevity. .
  • computing device 400 illustrated in FIG. 7 only shows the processor 402, the memory 404, the input/output interface 406, the communication interface 408, and the bus 410, those skilled in the art will appreciate in a particular implementation.
  • the computing device 400 also includes other devices necessary to achieve proper operation.
  • computing device 400 may also include hardware devices that implement other additional functions, depending on the particular needs.
  • computing device 400 may also only include the components necessary to implement embodiments of the present invention, and does not necessarily include all of the devices shown in FIG.
  • association relationship describing the associated object indicates that there may be three relationships.
  • a and/or B may indicate that A exists separately, and A and B exist simultaneously, and B cases exist alone.
  • the character / in this paper generally indicates that the contextual object is an OR relationship.
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .

Abstract

Provided are a method and apparatus for storing a query result. The method comprises: determining multiple query tables corresponding to a first query request, wherein the first query request is used for requesting to perform a correlated subquery on the multiple query tables (S110); determining a target query table from the multiple query tables, wherein the target query table is a fact table of at least one query table in the multiple query tables except the target query table, and a fact table of the target query table does not exist in the multiple query tables (S120); determining a major key of a first table according to the target query table, wherein the first table is used for storing a query result corresponding to the first query request (S130); and storing the query result into the first table according to the major key of the first table (S140). The method and apparatus for storing a query result can avoid the problem in the prior art that the query efficiency is low when a correlated subquery is performed on the first tabled, thus improving the correlated subquery efficiency.

Description

存储查询结果的方法和装置、计算设备Method and device for storing query result, computing device 技术领域Technical field
本发明涉及数据库领域,并且更具体地,涉及存储查询结果的方法和装置、计算设备。The present invention relates to the field of databases and, more particularly, to methods and apparatus, computing devices that store query results.
背景技术Background technique
事务处理性能委员会基准(Transaction Processing Performance Council BenchmarkTMH,TPC-H)主要用来模拟真实商业的应用环境,包括模拟对真实商业交易数据库的动态查询,以作为决策支持与数据库应用系统的参考。Transaction Processing Performance Council Benchmark TM H (TPC-H) is mainly used to simulate the real business application environment, including simulating dynamic query of real business transaction database as a reference for decision support and database application system.
TPC-H主要涉及如下概念:TPC-H mainly involves the following concepts:
事实表,用于存储至少一个事实记录,每个事实记录对应事实表中的一行,并且包括键值列和度量值列,其中,键值列中的值对应事实记录的维度,例如,商品产地、商品价格、商品数量、交易日期、商品种类、商品名称,等等;度量值列中的值对应于事实表的主题内容,例如,销售额或销售量,等等。a fact table for storing at least one fact record, each fact record corresponding to a row in the fact table, and including a key value column and a metric value column, wherein the value in the key value column corresponds to a dimension of the fact record, for example, a commodity origin , item price, item quantity, transaction date, item type, item name, etc.; the value in the metric column corresponds to the subject matter of the fact table, for example, sales or sales volume, and so on.
维度表,用于存储事实记录的维度特性,维度表可以包括名称列和属性列,例如,商品产地这个维度表中包括三个列,产地名称(locationName)、产地编号(locationId)和地址(Address),其中,产地名称为名称列,产地编号和地址为属性列。事实表中的键值列可以对应于维度表中的属性列,事实表中的每个键值列都可以对应于一个维度表。A dimension table for storing the dimension characteristics of the fact record. The dimension table may include a name column and an attribute column. For example, the origin of the product includes three columns, a place name (locationName), a place number (locationId), and an address (Address). ), where the origin name is the name column, the origin number and address are attribute columns. The key-value column in the fact table can correspond to the attribute column in the dimension table, and each key-value column in the fact table can correspond to a dimension table.
临时表,用于存储临时数据。临时表大致可分为事务级临时表和会话级临时表,其中,事务级临时表在事务提交后自动删除,会话级临时表在会话结束后删除。Temporary table for storing temporary data. The temporary table can be roughly divided into a transaction-level temporary table and a session-level temporary table, wherein the transaction-level temporary table is automatically deleted after the transaction is committed, and the session-level temporary table is deleted after the session ends.
主键,唯一标识表中的一列,一个表中任意两行具有不同的主键值,并且主键不允许有空值。一般地,表的主键为表的第一列。The primary key, which uniquely identifies a column in the table, any two rows in a table have different primary key values, and the primary key does not allow null values. In general, the primary key of a table is the first column of the table.
外键,用于连接两个表,如果表A中的列M与表B中的列N相对应,即列M与列N对应于相同的属性,例如,均对应于订单号,并且列M为表A中的主键,则列N为表B中的外键。事实表的外键对应于维度表的主键。Foreign key, used to join two tables, if the column M in the table A corresponds to the column N in the table B, that is, the column M and the column N correspond to the same attribute, for example, both correspond to the order number, and the column M For the primary key in Table A, column N is the foreign key in Table B. The foreign key of the fact table corresponds to the primary key of the dimension table.
在数据库系统中,当进行多张表关联的复杂查询时,如果多张表的数据量较大,则可以将一个查询语句分解成多个查询子语句,并通过大规模并行 处理(Massively Parallel Processing,MPP)机制将该多个查询子语句分发到集群的多个节点上。每个节点可以根据接收到的查询子语句进行查询,并将该查询子语句对应的查询结果存放到临时表中。在该多个节点完成查询后,可以采用查询语句对各节点获得的临时表进行关联查询,以获得最终的查询结果。In the database system, when multiple tables are associated with complex queries, if the data volume of multiple tables is large, a query statement can be decomposed into multiple query sub-statements and massively parallelized. The Massively Parallel Processing (MPP) mechanism distributes the plurality of query sub-statements to a plurality of nodes of the cluster. Each node can query according to the received query sub-statement, and store the query result corresponding to the query sub-statement into the temporary table. After the plurality of nodes complete the query, the query statement may be used to perform an associative query on the temporary table obtained by each node to obtain a final query result.
以TPC-H的Q7查询和SQL为例,如果要查询发货日期在1995年至1997年之间、并且供应商所属国和客户所属国中的一个为法国,另一个为德国的交易记录,可以采用如表1所示的查询语句。Take TPC-H's Q7 query and SQL as an example. If you want to query the delivery date between 1995 and 1997, and one of the supplier's country and the customer's country is France, the other is the German transaction record. You can use the query as shown in Table 1.
表1 TPC-H Q7查询语句示例Table 1 TPC-H Q7 query statement example
Figure PCTCN2015070656-appb-000001
Figure PCTCN2015070656-appb-000001
Figure PCTCN2015070656-appb-000002
Figure PCTCN2015070656-appb-000002
其中,在SQL语言中,“select[A]from[TABLE B]where[C]”表示从表B中选取符合查询条件C的记录对应的列A的数据。上述例子中涉及到复杂查询,其中,该复杂查询中的子查询涉及到的查询表包括:供应商(supplier)表、项目(lineitem)表、订单(orders)表、客户(customer)表、被命名为n1的国家(nation)表和被命名为n2的另一个国家(nation)表。该子查询获得的查询结果被插入出货(shipping)表,然后从表shipping中选取列supp_nation、cust_nation、l_year的数据以及通过对列volume的数据进行求和获得的列revenue的数据。Among them, in the SQL language, "select[A]from[TABLE B]where[C]" indicates that the data of the column A corresponding to the record matching the query condition C is selected from the table B. The above example involves a complex query, wherein the query table involved in the subquery in the complex query includes: a supplier table, a line item table, an orders table, a customer table, and a A country table named n1 and another country table named n2. The query result obtained by the subquery is inserted into the shipping table, and then the data of the columns supp_nation, cust_nation, l_year, and the data of the column revenue obtained by summing the data of the column volume are selected from the table shipping.
为了提高查询效率,可以将上述复杂查询对应的查询语句分解成两个查询子语句,其中,第一个查询子语句如表2所示,用于对表orders、表n1、表n2和表customer进行关联查询,并将查询结果插入临时表q7_tmp_order_customer;第二个查询子语句如表3所示,用于对表lineitem、 表n1、表n2和表supplier进行关联查询,并将查询结果插入临时表q7_tmp_lineitem_supplier中。最后,可以通过表4所示的查询语句对临时表q7_tmp_order_customer和q7_tmp_lineitem_supplier进行关联查询,以获得最终的查询结果。In order to improve query efficiency, the query statement corresponding to the above complex query may be decomposed into two query sub-sentences, wherein the first query sub-sentence is as shown in Table 2, and is used for table orders, table n1, table n2, and table customer. Perform an associative query and insert the query result into the temporary table q7_tmp_order_customer; the second query sub-statement is shown in Table 3, for the table lineitem, Table n1, table n2, and table supplier perform association query, and insert the query result into the temporary table q7_tmp_lineitem_supplier. Finally, the temporary table q7_tmp_order_customer and q7_tmp_lineitem_supplier can be correlated by the query statement shown in Table 4 to obtain the final query result.
表2 第一个查询子语句Table 2 first query substatement
Figure PCTCN2015070656-appb-000003
Figure PCTCN2015070656-appb-000003
表3 第二个查询子语句Table 3 second query substatement
Figure PCTCN2015070656-appb-000004
Figure PCTCN2015070656-appb-000004
表4 用于对两个临时表进行关联查询的查询语句Table 4 Query statements for associating queries between two temporary tables
Figure PCTCN2015070656-appb-000005
Figure PCTCN2015070656-appb-000005
表5 临时表q7_tmp_lineitem_supplier示例Table 5 Temporary table q7_tmp_lineitem_supplier example
Figure PCTCN2015070656-appb-000006
Figure PCTCN2015070656-appb-000006
其中,“insert into[table A]”表示将查询结果插入表A中。然而,由于在建立临时表时并未指定临时表的主键,在将查询子语句对应的查询结果存 储至临时表时,节点会主动为该临时表添加一个无实际意义的主键,例如,如表5所示,节点将数值为行号的列ID作为临时表q7_tmp_lineitem_supplier的主键,并将查询结果作为主键以外的其他列插入临时表中。这样,在对多个临时表进行关联查询时,该多个临时表中的一个或多个列中会存在重复值,在查询过程中需要对每条记录进行过滤,导致多表关联查询的效率低下。为了解决上述问题,可以对至少一个临时表中的一列创建索引,但由于临时表仅供当前查询使用,创建索引的代价较高,此外,由于临时表的数据需频繁插入,因此可能会造成索引失效。Where "insert into[table A]" indicates that the query result is inserted into the table A. However, since the primary key of the temporary table is not specified when the temporary table is created, the query result corresponding to the query substatement is stored. When stored in a temporary table, the node will actively add a non-meaningful primary key to the temporary table. For example, as shown in Table 5, the node uses the column ID whose value is the row number as the primary key of the temporary table q7_tmp_lineitem_supplier, and uses the query result as Columns other than the primary key are inserted into the temporary table. In this way, when performing an associative query on multiple temporary tables, there may be duplicate values in one or more of the multiple temporary tables, and each record needs to be filtered during the query process, resulting in the efficiency of the multi-table associated query. low. In order to solve the above problem, an index can be created for one column in at least one temporary table, but since the temporary table is only used by the current query, the cost of creating the index is high, and in addition, since the data of the temporary table needs to be inserted frequently, the index may be caused. Invalid.
发明内容Summary of the invention
本发明实施例提供一种存储查询结果的方法和装置、计算设备,能够避免现有技术中进行关联查询时查询效率低下的问题。The embodiments of the present invention provide a method, a device, and a computing device for storing query results, which can avoid the problem of low query efficiency when performing related queries in the prior art.
第一方面,提供了一种存储查询结果的方法,包括:确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对该多个查询表进行关联查询;从该多个查询表中确定目标查询表,其中,该多个查询表中不存在该目标查询表的事实表,并且该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表;根据该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果;根据该第一表的主键,将该查询结果存储至该第一表。The first aspect provides a method for storing a query result, including: determining a plurality of query tables corresponding to the first query request, wherein the first query request is used to request an association query for the plurality of query tables; Determining a target query table in the plurality of query tables, wherein the fact table of the target query table does not exist in the plurality of query tables, and the target query table is at least one of the plurality of query tables except the target query table Querying a fact table of the table; determining, according to the target query table, a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; and the query result is obtained according to the primary key of the first table Stored to the first table.
在第一种可能的实现方式中,该根据该第一表的主键,将该查询结果存储至该第一表,包括:根据该第一表的主键,以列簇的方式将该查询结果存储至该第一表。In a first possible implementation manner, the storing the query result to the first table according to the primary key of the first table includes: storing the query result in a column cluster manner according to the primary key of the first table To the first table.
结合上述可能的实现方式,在第二种可能的实现方式中,该从该多个查询表中确定目标查询表,包括:确定该第一查询请求对应的至少一个第一关联查询条件,其中,该第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,该多个查询表包括该第一查询表和不同于该第一查询表的该第二查询表;确定该至少一个第一关联查询条件对应的第一查询表与该第二查询表之间的关联关系;根据该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表。In combination with the foregoing possible implementation manner, in the second possible implementation, the determining the target query table from the multiple query tables includes: determining at least one first associated query condition corresponding to the first query request, where The first associated query condition is composed of a first column in the first query table and a second column in the second query table, the plurality of query tables including the first query table and the first query table different from the first query table a second query table; determining an association relationship between the first query table and the second query table corresponding to the at least one first associated query condition; and according to the relationship between the first query table and the second query table, The target lookup table is determined in the first lookup table and the second lookup table.
结合上述可能的实现方式,在第三种可能的实现方式中,该确定该第一查询表与该第二查询表之间的关联关系,包括:确定该第一查询表的第一列 是否为该第一查询表的主键;若该第一查询表的第一列为该第一查询表的主键,确定该第二查询表为该第一查询表的事实表;若该第一查询表的第一列为该第一查询表的外键,确定该第一查询表为该第二查询表的事实表。In combination with the foregoing possible implementation manner, in a third possible implementation manner, determining the association relationship between the first query table and the second query table includes: determining a first column of the first query table Whether it is the primary key of the first query table; if the first column of the first query table is the primary key of the first query table, determining that the second query table is the fact table of the first query table; if the first query The first column of the table is a foreign key of the first query table, and the first query table is determined to be a fact table of the second query table.
结合上述可能的实现方式,在第四种可能的实现方式中,该第一查询请求对应一个第一关联查询条件;该第三确定子单元具体用于:若该第二确定子单元确定该第二查询表为该第一查询表的事实表,则确定该第二查询表为该目标查询表;若该第二确定子单元确定该第一查询表为该第二查询表的事实表,则确定该第一查询表为该目标查询表。In combination with the foregoing possible implementation manner, in a fourth possible implementation manner, the first query request corresponds to a first associated query condition, and the third determining sub-unit is specifically configured to: if the second determining sub-unit determines the first The second lookup table is the fact table of the first query table, and the second query table is determined to be the target query table; if the second determining subunit determines that the first query table is the fact table of the second query table, The first query table is determined to be the target query table.
结合上述可能的实现方式,在第五种可能的实现方式中,该第一查询请求对应多个第一关联查询条件;该根据该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表,包括:根据该第一查询表与该第二查询表之间的关联关系,建立关联关系树,其中,若该第二查询表为该第一查询表的事实表,该第二查询表为该第一查询表的父节点;将该关联关系树的根节点确定为该目标查询表。In combination with the foregoing possible implementation manner, in a fifth possible implementation, the first query request corresponds to multiple first associated query conditions; and according to the relationship between the first query table and the second query table, Determining the target query table from the first query table and the second query table, comprising: establishing an association relationship tree according to an association relationship between the first query table and the second query table, wherein, if the second The query table is a fact table of the first query table, and the second query table is a parent node of the first query table; the root node of the relationship tree is determined as the target query table.
结合上述可能的实现方式,在第六种可能的实现方式中,该根据该目标查询表,确定该第一表的主键,包括:确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键;若该多个列中存在该目标查询表的非联合主键,将该目标查询表的非联合主键确定为该第一表的主键。In combination with the foregoing possible implementation manner, in a sixth possible implementation manner, determining the primary key of the first table according to the target query table includes: determining whether the target query table exists in multiple columns corresponding to the query result The non-federated primary key; if the non-federal primary key of the target query table exists in the plurality of columns, the non-union primary key of the target query table is determined as the primary key of the first table.
结合上述可能的实现方式,在第七种可能的实现方式中,该根据该目标查询表,确定该第一表的主键,还包括:若该多个列中不存在该目标查询表的非联合主键,确定与该第一查询请求对应的第二查询请求,该第二查询请求用于请求对该第一表和第二表进行关联查询;根据该第二查询请求,确定该第一表的主键。In combination with the foregoing possible implementation manner, in a seventh possible implementation manner, determining the primary key of the first table according to the target query table, further includes: if the target query table does not exist in the multiple columns Determining, by the primary key, a second query request corresponding to the first query request, the second query request is used to request an association query for the first table and the second table; and determining, according to the second query request, the first table Primary key.
结合上述可能的实现方式,在第八种可能的实现方式中,该根据该第二查询请求,确定该第一表的主键,包括:确定该第二查询请求对应的至少一个第二关联查询条件,其中,该第二关联查询条件由该第一表的第三列和该第二表的第四列构成;从该至少一个第二关联查询条件中确定第二目标关联查询条件,该第二目标关联查询条件包括该第二表的主键;将该第二目标关联查询条件中包括的该第一表的第三列确定为该第一表的主键。In combination with the foregoing possible implementation manners, in the eighth possible implementation, the determining, by the second query request, the primary key of the first table includes: determining at least one second associated query condition corresponding to the second query request The second associated query condition is composed of a third column of the first table and a fourth column of the second table; determining a second target associated query condition from the at least one second associated query condition, the second The target association query condition includes a primary key of the second table; the third column of the first table included in the second target association query condition is determined as a primary key of the first table.
第二方面,提供了一种存储查询结果的装置,包括:第一确定单元,用于确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对 该多个查询表进行关联查询;第二确定单元,用于从该第一确定单元确定的该多个查询表中确定目标查询表,其中,该多个查询表中不存在该目标查询表的事实表,并且该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表;第三确定单元,用于根据该第二确定单元确定的该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果;存储单元,用于根据该第三确定单元确定的该第一表的主键,将该查询结果存储至该第一表。The second aspect provides an apparatus for storing a query result, including: a first determining unit, configured to determine a plurality of query tables corresponding to the first query request, where the first query request is used to request a pair The plurality of lookup tables are associated with the query; the second determining unit is configured to determine a target query table from the plurality of query tables determined by the first determining unit, where the target query table does not exist in the plurality of query tables a fact table, and the target query table is a fact table of at least one query table of the plurality of query tables except the target query table; and a third determining unit, configured to determine the target query table according to the second determining unit Determining a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; and the storage unit is configured to use the primary key of the first table determined by the third determining unit to query the query The result is stored to the first table.
在第一种可能的实现方式中,该存储单元具体用于:根据该第三确定单元确定的该第一表的主键,以列簇的方式将该查询结果存储至该第一表。In a first possible implementation, the storage unit is configured to: store the query result in the column cluster to the first table according to the primary key of the first table determined by the third determining unit.
结合上述可能的实现方式,在第二种可能的实现方式中,该第二确定单元包括:第一确定子单元,用于确定该第一查询请求对应的至少一个第一关联查询条件,其中,该第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,该多个查询表包括该第一查询表和不同于该第一查询表的该第二查询表;第二确定子单元,用于确定该第一确定子单元确定的该至少一个第一关联查询条件对应的该第一查询表与该第二查询表之间的关联关系;第三确定子单元,用于根据该第二确定子单元确定的该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表。In combination with the foregoing possible implementation manner, in a second possible implementation manner, the second determining unit includes: a first determining sub-unit, configured to determine at least one first associated query condition corresponding to the first query request, where The first associated query condition is composed of a first column in the first query table and a second column in the second query table, the plurality of query tables including the first query table and the first query table different from the first query table a second determining sub-unit, configured to determine an association relationship between the first query table and the second query table corresponding to the at least one first associated query condition determined by the first determining sub-unit; a determining subunit, configured to determine the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table determined by the second determining subunit .
结合上述可能的实现方式,在第三种可能的实现方式中,该第二确定子单元具体用于:确定该第一查询表中的第一列是否为该第一查询表的主键;若该第一查询表中的第一列为该第一查询表的主键,确定该第二查询表为该第一查询表的事实表;若该第一查询表中的第一列为该第一查询表的外键,确定该第一查询表为该第二查询表的事实表。In combination with the foregoing possible implementation manner, in a third possible implementation, the second determining sub-unit is specifically configured to: determine whether the first column in the first query table is a primary key of the first query table; The first column in the first query table is the primary key of the first query table, and the second query table is determined to be the fact table of the first query table; if the first column in the first query table is the first query The foreign key of the table determines that the first lookup table is a fact table of the second lookup table.
结合上述可能的实现方式,在第四种可能的实现方式中,该第一查询请求对应一个第一关联查询条件;该第三确定子单元具体用于:若该第二确定子单元确定该第二查询表为该第一查询表的事实表,则确定该第二查询表为该目标查询表;若该第二确定子单元确定该第一查询表为该第二查询表的事实表,则确定该第一查询表为该目标查询表。In combination with the foregoing possible implementation manner, in a fourth possible implementation manner, the first query request corresponds to a first associated query condition, and the third determining sub-unit is specifically configured to: if the second determining sub-unit determines the first The second lookup table is the fact table of the first query table, and the second query table is determined to be the target query table; if the second determining subunit determines that the first query table is the fact table of the second query table, The first query table is determined to be the target query table.
结合上述可能的实现方式,在第五种可能的实现方式中,该第一查询请求对应多个第一关联查询条件;该第三确定子单元具体用于:根据该第二确定子单元确定的该第一查询表与该第二查询表之间的关联关系,建立关联关 系树,其中,若该第二查询表为该第一查询表的事实表,该第二查询表为该第一查询表的父节点;将该关联关系树的根节点确定为该目标查询表。In combination with the foregoing possible implementation manner, in a fifth possible implementation, the first query request is corresponding to multiple first associated query conditions; the third determining sub-unit is specifically configured to: determine, according to the second determining sub-unit Establishing an association relationship between the first query table and the second query table a tree, wherein the second query table is a fact table of the first query table, the second query table is a parent node of the first query table; and the root node of the relationship tree is determined as the target query table .
结合上述可能的实现方式,在第六种可能的实现方式中,该第三确定单元包括:第四确定子单元,用于确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键;第五确定子单元,用于若该第四确定子单元确定该多个列中存在该目标查询表的非联合主键,将该目标查询表的非联合主键确定为该第一表的主键。In combination with the foregoing possible implementation manner, in a sixth possible implementation manner, the third determining unit includes: a fourth determining sub-unit, configured to determine whether the target query table is not present in the multiple columns corresponding to the query result a first determining sub-unit, configured to determine, when the fourth determining sub-unit determines that the non-co-primary primary key of the target query table exists in the plurality of columns, determining the non-union primary key of the target query table as the first table Primary key.
结合上述可能的实现方式,在第七种可能的实现方式中,该第三确定单元还包括:第六确定子单元,用于若该第四确定子单元确定该多个列中不存在该目标查询表的非联合主键,确定与该第一查询请求对应的第二查询请求,该第二查询请求用于请求对该第一表和第二表进行关联查询;第七确定子单元,用于根据该第六确定子单元确定的该第二查询请求,确定该第一表的主键。In conjunction with the foregoing possible implementation manner, in a seventh possible implementation, the third determining unit further includes: a sixth determining subunit, configured to determine, if the fourth determining subunit, the target does not exist in the multiple columns Querying a non-joined primary key of the table, determining a second query request corresponding to the first query request, the second query request is used to request an association query for the first table and the second table; and the seventh determining subunit is configured to: Determining the primary key of the first table according to the second query request determined by the sixth determining subunit.
结合上述可能的实现方式,在第八种可能的实现方式中,该第七确定子单元具体用于:确定该第二查询请求对应的至少一个第二关联查询条件,其中,该第二关联查询条件由该第一表的第三列和该第二表的第四列构成;从该至少一个第二关联查询条件中确定第二目标关联查询条件,该第二目标关联查询条件包括该第二表的主键;将该第二目标关联查询条件中包括的该第一表的第三列确定为该第一表的主键。With reference to the foregoing possible implementation manners, in the eighth possible implementation, the seventh determining sub-unit is specifically configured to: determine at least one second associated query condition corresponding to the second query request, where the second associated query The condition is composed of a third column of the first table and a fourth column of the second table; determining a second target associated query condition from the at least one second associated query condition, the second target associated query condition including the second a primary key of the table; determining a third column of the first table included in the second target association query condition as a primary key of the first table.
第三方面,提供了一种计算设备,包括:处理器、存储器和总线;该存储器用于存储计算机执行指令,该处理器与该存储器通过该总线连接,当该计算设备运行时,该处理器读取该存储器存储的该计算机执行指令,以执行第一方面或第一方面的任一种可能的实现方式中的存储查询结果的方法。In a third aspect, a computing device is provided, comprising: a processor, a memory, and a bus; the memory is configured to store a computer to execute instructions, the processor is coupled to the memory via the bus, and when the computing device is running, the processor The computer-executed instructions stored in the memory are read to perform the method of storing the query results in the first aspect or any of the possible implementations of the first aspect.
基于上述技术方案,本发明实施例提供的存储查询结果的方法和装置、计算设备,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。 Based on the foregoing technical solution, the method and device for storing a query result and the computing device provided by the embodiment of the present invention determine a target query table from a plurality of query tables corresponding to the first query request, where the target query table is the multiple query a fact table of at least one query table other than the target query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a first one for storing the query result according to the target query table The primary key of the table can avoid the problem that the query efficiency is low when the related query of the first table is subsequently performed due to the column having no practical meaning as the primary key of the first table in the prior art, thereby improving the efficiency of the related query.
附图说明DRAWINGS
为了更清楚地说明本发明实施例的技术方案,下面将对本发明实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面所描述的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings to be used in the embodiments of the present invention or the description of the prior art will be briefly described below. Obviously, the drawings described below are only the present invention. For some embodiments, other drawings may be obtained from those of ordinary skill in the art without departing from the drawings.
图1是本发明实施例提供的存储查询结果的方法的示意性流程图。FIG. 1 is a schematic flowchart of a method for storing a query result according to an embodiment of the present invention.
图2是本发明实施例提供的存储查询结果的方法的另一示意性流程图。FIG. 2 is another schematic flowchart of a method for storing a query result according to an embodiment of the present invention.
图3是本发明实施例提供的存储查询结果的方法示例中的关联关系树的示意图。FIG. 3 is a schematic diagram of an association tree in an example of a method for storing a query result according to an embodiment of the present invention.
图4是本发明实施例提供的存储查询结果的方法示例中的另一关联关系树的示意图。FIG. 4 is a schematic diagram of another association tree in an example of a method for storing a query result according to an embodiment of the present invention.
图5是本发明实施例提供的存储查询结果的装置的示意性框图。FIG. 5 is a schematic block diagram of an apparatus for storing a query result according to an embodiment of the present invention.
图6是本发明实施例提供的另一存储查询结果的装置的示意性框图。FIG. 6 is a schematic block diagram of another apparatus for storing a query result according to an embodiment of the present invention.
图7是本发明实施例提供的计算设备的示意性框图。FIG. 7 is a schematic block diagram of a computing device provided by an embodiment of the present invention.
具体实施方式detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明的一部分实施例,而不是全部实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都应属于本发明保护的范围。The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is obvious that the described embodiments are a part of the embodiments of the present invention, but not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the scope of the present invention.
应理解,本发明实施例的技术方案可以应用于各种数据库系统,例如,关系型数据库管理系统(Relational Database Management System,RDBMS),非关系型(NoSQL)数据库系统,大规模并行处理数据库(Massively Parallel Processing Database,MPP-DB),等等,本发明实施例对此不做限定。It should be understood that the technical solutions of the embodiments of the present invention can be applied to various database systems, for example, a Relational Database Management System (RDBMS), a non-relational (NoSQL) database system, and a massively parallel processing database (Massively). Parallel Processing Database, MPP-DB, and the like, which are not limited by the embodiment of the present invention.
还应理解,本发明实施例以结构化查询语言(Structured Query Language,SQL)语言为例进行描述,但本发明实施例也可以采用其他语言,例如,面向对象的查询语言(Hibernate Query Language,HQL),等等,本发明实施例对此不做限定。It should be understood that the embodiment of the present invention is described by using a Structured Query Language (SQL) language as an example. However, the embodiment of the present invention may also adopt other languages, for example, an object-oriented query language (Hibernate Query Language, HQL). The embodiment of the present invention does not limit this.
图1是本发明实施例的存储查询结果的方法100的示意性流程图,该方法100可以由存储查询结果的装置执行。具体地,该存储查询结果的装置可以具体为独立设备或者为设备中的一个模块,例如,该存储查询结果的装置 可以为单机或集群节点(cluster node),但本发明实施例不限于此。FIG. 1 is a schematic flowchart of a method 100 for storing a query result according to an embodiment of the present invention. The method 100 may be performed by a device that stores a query result. Specifically, the device for storing the query result may be specifically a standalone device or a module in the device, for example, the device for storing the query result. It may be a stand-alone or a cluster node, but the embodiment of the present invention is not limited thereto.
S110,确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对该多个查询表进行关联查询。S110. Determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an association query for the plurality of query tables.
该存储查询结果的装置可以接收来自客户端的第一查询请求,其中,来自客户端的第一查询请求可以通过网络设备或其它设备转发至该存储查询结果的装置。该第一查询请求可以请求对该多个查询表进行关联查询,例如,该第一查询请求对应的查询语句可以如表1至表4中的任意表所示。该第一查询请求可以为一个独立查询,也可以为一个复杂查询的子查询,本发明实施例对此不做限定。The device storing the query result may receive a first query request from the client, wherein the first query request from the client may be forwarded to the device storing the query result by the network device or other device. The first query request may request an association query for the plurality of query tables. For example, the query statement corresponding to the first query request may be as shown in any table in Tables 1 to 4. The first query request may be an independent query, or may be a subquery of a complex query, which is not limited by the embodiment of the present invention.
该存储查询结果的装置可以根据该第一查询请求,确定该第一查询请求对应的多个查询表,并对该多个第一表进行关联查询。此时,该第一查询请求对应的查询语句中可以包括where语句,并且where语句所限定的查询条件中可以包括关联查询条件。关联查询条件可以由表A中的列M和表B中的列N构成,并且列M和列N可以在查询语句中由等号连接,例如,在表1所示的查询条件中,查询语句“where s_suppkey=l_suppkey”对应于一个关联查询条件,该关联查询条件由表supplier中的列suppkey与表lineitem中的列suppkey构成,但本发明实施例不限于此。The device storing the query result may determine, according to the first query request, a plurality of query tables corresponding to the first query request, and perform an associative query on the plurality of first tables. At this time, the query statement corresponding to the first query request may include a where statement, and the query condition defined by the where statement may include an associated query condition. The associated query condition may be composed of column M in table A and column N in table B, and column M and column N may be connected by an equal sign in the query statement, for example, in the query condition shown in Table 1, the query statement The "where s_suppkey=l_suppkey" corresponds to an associated query condition, which is composed of the column suction key in the table supplier and the column suppkey in the table lineitem, but the embodiment of the present invention is not limited thereto.
S120,从该多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表。S120. Determine a target query table from the plurality of query tables, where the target query table is a fact table of at least one query table of the plurality of query tables except the target query table, and the plurality of query tables are There is no fact table for the target lookup table.
该多个查询表包括该目标查询表。该目标查询表可以为该多个查询表中的一个或多个其它表的事实表,但该多个查询表中不包括该目标查询表的事实表。具体地,该存储查询结果的装置可以根据该第一查询请求中包括的查询条件,从该多个查询表中确定该目标查询表,但本发明实施例不限于此。The plurality of lookup tables include the target lookup table. The target query table may be a fact table of one or more other tables in the plurality of query tables, but the fact table of the target query table is not included in the plurality of query tables. Specifically, the device that stores the query result may determine the target query table from the plurality of query tables according to the query condition included in the first query request, but the embodiment of the present invention is not limited thereto.
S130,根据该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果。S130. Determine, according to the target query table, a primary key of the first table, where the first table is configured to store a query result corresponding to the first query request.
该存储查询结果的装置可以通过多种方式确定将查询结果存储至该第一表。可选地,该第一查询请求可以请求将对该多个查询表进行关联查询的查询结果存储至第一表,该第一表可以为普通表或临时表,相应地,该第一查询请求对应的查询语句可以包括insert into语句,并且该存储查询结果的装置根据该第一查询请求确定该第一表。或者,该存储查询结果的装置可以 主动确定将该第一查询请求对应的查询结果存储至该第一表,此时,该第一表可以为临时表,但本发明实施例不限于此。The means for storing the query result can determine to store the query result to the first table in a plurality of ways. Optionally, the first query request may request to store the query result of the associated query for the plurality of query tables to the first table, where the first table may be a normal table or a temporary table, and correspondingly, the first query request The corresponding query statement may include an insert into statement, and the device storing the query result determines the first table according to the first query request. Alternatively, the device storing the query result may The first table may be a temporary table, but the embodiment of the present invention is not limited thereto.
S140,根据该第一表的主键,将该查询结果存储至该第一表。S140. Store the query result to the first table according to the primary key of the first table.
该查询结果可以包括该多个查询表中符合查询条件的目标记录对应的多个列的数据,其中,该目标记录对应的多个列的数据可以包括该目标记录中的至少一列的数据,或者包括由对该目标记录中的至少一列的数据进行数学运算获得的数据,这里的数据可以指数值或字符串,本发明实施例对此不做限定。The query result may include data of a plurality of columns corresponding to the target record in the plurality of query tables, wherein the data of the plurality of columns corresponding to the target record may include data of at least one column in the target record, or The data obtained by performing the mathematical operation on the data of the at least one column in the target record may be an index value or a character string, which is not limited in the embodiment of the present invention.
因此,根据本发明实施例的存储查询结果的方法,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, according to the method for storing the query result, the target query table is determined from the plurality of query tables corresponding to the first query request, wherein the target query table is the target query table among the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a primary key of the first table for storing the query result according to the target query table, can avoid existing In the technology, the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
在本发明实施例中,该查询结果对应的多个列可以包括该第一表的主键,相应地,在S140中,该存储查询结果的装置可以将该查询结果对应的多个列中除该第一表的主键之外的其它列以非主键的形式插入该第一表。可选地,如果该查询结果对应的该第一表的主键存在重复值,则该存储查询结果的装置可以以列簇(Column Family)的方式存储该查询结果对应的多个列,以使得该第一表中的主键不存在重复值,但本发明实施例不限于此。In the embodiment of the present invention, the plurality of columns corresponding to the query result may include the primary key of the first table, and correspondingly, in S140, the device storing the query result may include the plurality of columns corresponding to the query result. The other column than the primary key of the first table is inserted into the first table in the form of a non-primary key. Optionally, if the primary key of the first table corresponding to the query result has a duplicate value, the device storing the query result may store a plurality of columns corresponding to the query result in a column family manner, so that the The primary key in the first table does not have a duplicate value, but the embodiment of the present invention is not limited thereto.
可选地,S140,根据该第一表的主键,将该查询结果存储至该第一表,包括:Optionally, S140, storing the query result to the first table according to the primary key of the first table, including:
根据该第一表的主键,以列簇的方式将该查询结果存储至该第一表。The query result is stored in the first table in the form of a column cluster according to the primary key of the first table.
例如,由表2所示的第一个查询子语句获得的临时表q7_tmp_order_customer可以以表6所示的列簇形式存储,由表3所示的第二个查询子语句获得的临时表q7_tmp_lineitem_supplier可以以表7所示的列簇形式存储。For example, the temporary table q7_tmp_order_customer obtained by the first query sub-statement shown in Table 2 may be stored in the form of a column cluster shown in Table 6, and the temporary table q7_tmp_lineitem_supplier obtained by the second query sub-statement shown in Table 3 may be The column cluster form shown in Table 7 is stored.
表6 以列簇的形式存储的临时表q7_tmp_order_customerTable 6 Temporary table q7_tmp_order_customer stored as a column cluster
Figure PCTCN2015070656-appb-000007
Figure PCTCN2015070656-appb-000007
Figure PCTCN2015070656-appb-000008
Figure PCTCN2015070656-appb-000008
表7 以列簇的形式存储的临时表q7_tmp_lineitem_supplierTable 7 Temporary table q7_tmp_lineitem_supplier stored as a column cluster
Figure PCTCN2015070656-appb-000009
Figure PCTCN2015070656-appb-000009
可选地,作为另一实施例,在将该查询结果插入并存储至该第一表之前,该存储查询结果的装置可以确定该第一表是否存在,如果该第一表不存在,则该存储查询结果的装置可以首先建立该第一表,然后将该查询结果插入该第一表并存储该第一表。如果该第一表已存在,则该存储查询结果的装置可以直接将查询结果插入该第一表,或者首先删除该第一表并重新建立该第一表,然后将查询结果插入新建的该第一表并存储该第一表,但本发明实施例不限于此。Optionally, as another embodiment, before the query result is inserted and stored in the first table, the device storing the query result may determine whether the first table exists, and if the first table does not exist, The means for storing the query result may first establish the first table, then insert the query result into the first table and store the first table. If the first table already exists, the device storing the query result may directly insert the query result into the first table, or first delete the first table and re-establish the first table, and then insert the query result into the newly created first The first table is stored in a table, but the embodiment of the invention is not limited thereto.
在S120中,该存储查询结果的装置可以通过多种方式从该多个查询表中确定该目标查询表。作为一个可选实施例,该存储查询结果的装置可以根据该第一查询请求对应的至少一个第一关联查询条件,从该多个查询表中确定该目标查询表。 In S120, the device storing the query result may determine the target query table from the plurality of lookup tables in a plurality of manners. As an optional embodiment, the device storing the query result may determine the target query table from the plurality of query tables according to the at least one first associated query condition corresponding to the first query request.
可选地,如图2所示,S120,从该多个查询表中确定目标查询表,包括:Optionally, as shown in FIG. 2, S120, determining a target query table from the plurality of lookup tables, including:
S121,确定该第一查询请求对应的至少一个第一关联查询条件,其中,该第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,该多个查询表包括该第一查询表和不同于该第一查询表的该第二查询表;S121. Determine at least one first associated query condition corresponding to the first query request, where the first associated query condition is formed by a first column in the first query table and a second column in the second query table, where the multiple The lookup table includes the first lookup table and the second lookup table different from the first lookup table;
S122,确定该第一关联查询条件对应的第一查询表和所述第二查询表之间的关联关系;S122. Determine an association relationship between the first query table and the second query table corresponding to the first associated query condition.
S123,根据该第一查询表和该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表。S123. Determine the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table.
具体地,在该第一查询请求对应的查询语句中,该第一查询表的第一列与该第二查询表的第二列可以以等号连接。以表3所示的第二个查询子语句为例,该查询子语句中包括两个关联查询条件,即由表lineitem的列suppkey与表supplier的列suppkey构成的关联查询条件“l_suppkey=s_suppkey”和由表supplier中的列nationkey和表n1中的列nationkey构成的关联查询条件“s_nationkey=n1.n_nationkey”。该存储查询结果的装置可以从表lineitem、表supplier和表n1中确定该目标查询表。Specifically, in the query statement corresponding to the first query request, the first column of the first query table and the second column of the second query table may be connected by an equal sign. Taking the second query sub-sentence shown in Table 3 as an example, the query sub-statement includes two associated query conditions, that is, the associated query condition "l_suppkey=s_suppkey" consisting of the column suppkey of the table lineitem and the column suppkey of the table supplier. The associated query condition "s_nationkey=n1.n_nationkey" consists of the column nationkey in the table supplier and the column nationkey in the table n1. The means for storing the query result may determine the target lookup table from the table lineitem, the table supplier, and the table n1.
可选地,作为另一实施例,S122,确定该第一查询表和所述第二查询表之间的关联关系,包括:Optionally, as another embodiment, S122, determining an association relationship between the first query table and the second query table, including:
确定该第一查询表的第一列是否为该第一查询表的主键;Determining whether the first column of the first lookup table is a primary key of the first lookup table;
若该第一查询表的第一列为该第一查询表的主键,确定该第二查询表为该第一查询表的事实表;If the first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
若该第一查询表的第一列为该第一查询表的外键,确定该第一查询表为该第二查询表的事实表。If the first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
如果该存储查询结果的装置确定该第一列为该第一查询表的主键,则表明该第二列为该第二查询表的外键,此时,该存储查询结果的装置可以确定该第一查询表为该第二查询表的维度表,该第二查询表为该第一查询表的事实表。可选地,如果该存储查询结果的装置确定该第一列为该第一查询表的外键,则表明该第二列为该第二查询表的主键,此时,该存储查询结果的装置可以确定该第一查询表为该第二查询表的事实表,该第二查询表为该第一查询表的维度表。If the device storing the query result determines that the first column is the primary key of the first query table, it indicates that the second column is a foreign key of the second query table, and at this time, the device storing the query result may determine the first A lookup table is a dimension table of the second lookup table, and the second lookup table is a fact table of the first lookup table. Optionally, if the device storing the query result determines that the first column is a foreign key of the first query table, indicating that the second column is a primary key of the second query table, and at this time, the device storing the query result The first query table may be determined as a fact table of the second query table, and the second query table is a dimension table of the first query table.
或者,该存储查询结果的装置也可以确定该第二列是否为该第二查询表 的主键,如果该第二列为该第二查询表的主键,则该存储查询结果的装置可以确定该第一查询表为该第二查询表的事实表;而如果该第二列为该第二查询表的外键,则该存储查询结果的装置可以确定该第二查询表为该第一查询表的事实表,但本发明实施例不限于此。Alternatively, the device storing the query result may also determine whether the second column is the second query table a primary key, if the second column is the primary key of the second lookup table, the means for storing the query result may determine that the first lookup table is a fact table of the second lookup table; and if the second column is the first The device that stores the result of the query may determine that the second lookup table is a fact table of the first lookup table, but the embodiment of the present invention is not limited thereto.
应理解,在本发明实施例中,除非明确说明或者从上下文可以直接看出,术语“主键”可以指能够唯一标识一行的一列,即非联合主键,此时,主键对应一列,也可以指能够唯一标识一行的多列或能够与其它列共同唯一标识一行的一列,即联合主键或联合主键之一,此时,主键对应多列或多列中的一列,本发明实施例对此不做限定。It should be understood that, in the embodiment of the present invention, unless explicitly stated or directly from the context, the term "primary key" may refer to a column capable of uniquely identifying a row, that is, a non-joined primary key. In this case, the primary key corresponds to one column, and may also mean capable of A plurality of columns that uniquely identify one row or a column that can uniquely identify a row together with other columns, that is, one of a joint primary key or a joint primary key. In this case, the primary key corresponds to one of the plurality of columns or columns, which is not limited in this embodiment of the present invention. .
如果该第一查询请求对应一个第一关联查询条件,并且该存储查询结果的装置确定该第二查询表为该第一查询表的事实表,则该存储查询结果的装置可以确定该第二查询表为该目标查询表。如果该第一查询请求对应多个第一关联查询条件,则该存储查询结果的装置可以确定每个第一关联查询条件中的两个查询表之间的关联关系,并且根据该多个第一关联查询条件中的每个第一关联查询条件中的两个查询表之间的关联关系,确定该目标查询表。仍以图3所示的第二个查询子语句为例,该存储查询结果的装置可以确定表lineitem与表supplier之间的关联关系以及表supplier与表n1之间的关联关系。其中,表lineitem的典型形式可以如表8所示,其中,orderkey和linenumber作为表lineitem的联合主键,一个orderkey的值和一个linenumber的值能够共同标识表中的一行。表supplier的典型形式可以如表9所示,其中,suppkey为表supplier的非联合主键,能够单独标识表中的一行。命名为表n1的表nation的典型形式可以如表10所示,其中,nationkey为表n1的主键。此时,由表8和表9可以得知,suppkey为表lineitem的外键并且为表supplier的主键,则表lineitem为表supplier的事实表;由表9和表10可以得知,nationkey为表supplier的外键并且为表n1的主键,则表supplier为表n1的事实表。在表lineitem、supplier和n1这三个查询表中,表lineitem为表supplier的事实表,并且表lineitem、supplier和n1中不存在表lineitem的事实表,因此,该存储查询结果的装置可以确定表lineitem为目标查询表。If the first query request corresponds to a first associated query condition, and the device storing the query result determines that the second query table is a fact table of the first query table, the device storing the query result may determine the second query The table is the target query table. If the first query request corresponds to the plurality of first associated query conditions, the device storing the query result may determine an association relationship between the two query tables in each of the first associated query conditions, and according to the plurality of first The association relationship between the two query tables in each of the first associated query conditions in the associated query condition is determined, and the target query table is determined. Still taking the second query sub-sentence shown in FIG. 3 as an example, the device storing the query result may determine an association relationship between the table lineitem and the table supplier and an association relationship between the table supplier and the table n1. The typical form of the table lineitem can be as shown in Table 8, wherein orderkey and linenumber are used as the joint primary key of the table lineitem, and an orderkey value and a linenumber value can jointly identify one row in the table. The typical form of the table supplier can be as shown in Table 9, where suppkey is the non-union primary key of the table supplier, which can identify one row in the table separately. A typical form of the table nation named table n1 can be as shown in Table 10, where nationkey is the primary key of table n1. At this point, it can be known from Table 8 and Table 9, that suppkey is the foreign key of the table lineitem and is the primary key of the table supplier, then the table lineitem is the fact table of the table supplier; as shown in Table 9 and Table 10, the nationkey is the table. The foreign key of the supplier is the primary key of the table n1, and the table supplier is the fact table of the table n1. In the three lookup tables of table lineitem, supplier and n1, the table lineitem is the fact table of the table supplier, and the fact table of the table lineitem does not exist in the table lineitem, supplier and n1, therefore, the device storing the query result can determine the table Lineitem is the target query table.
图8 表lineitem示例Figure 8 table lineitem example
Figure PCTCN2015070656-appb-000010
Figure PCTCN2015070656-appb-000010
图9 表supplier示例Figure 9 table supplier example
Figure PCTCN2015070656-appb-000011
Figure PCTCN2015070656-appb-000011
图10 表nation示例Figure 10 Table nation example
Figure PCTCN2015070656-appb-000012
Figure PCTCN2015070656-appb-000012
可选地,作为另一实施例,该第一查询请求对应一个第一关联查询条件;Optionally, in another embodiment, the first query request corresponds to a first associated query condition;
相应地,S123,根据该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表,包括:Correspondingly, the S123 determines the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table, including:
若该第二查询表为该第一查询表的事实表,则确定该第二查询表为该目标查询表;If the second lookup table is a fact table of the first lookup table, determining that the second lookup table is the target lookup table;
若该第一查询表为该第二查询表的事实表,则确定该第一查询表为该目标查询表。If the first lookup table is a fact table of the second lookup table, it is determined that the first lookup table is the target lookup table.
可选地,作为另一实施例,如果该第一查询请求对应多个第一关联查询条件,则该根据该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表,包括:Optionally, as another embodiment, if the first query request corresponds to multiple first associated query conditions, the association relationship between the first query table and the second query table is obtained from the first query. The target query table is determined in the table and the second query table, including:
根据该第一查询表与该第二查询表之间的关联关系,建立关联关系树,其中,若该第二查询表为该第一查询表的事实表,该第二查询表为该第一查询表的父节点;And establishing, according to the association relationship between the first query table and the second query table, the second query table is the first query table, and the second query table is the first Query the parent node of the table;
将该关联关系树的根节点确定为该目标查询表。The root node of the association tree is determined as the target query table.
在建立关联关系树时,该存储查询结果的装置可以将事实表作为维度表的父节点,一个节点可以有多个子节点。此时,由于该关联关系树不存在根节点的父节点,即该关联关系树中不包括根节点的事实表,并且该关联关系树中存在该根节点的子节点,即存在该根节点的维度表,因此,该存储查询结果的装置可以将该关联关系树的根节点确定为该目标查询表。仍以表3所示的第二个查询子语句为例,根据表lineitem为表supplier的事实表以及表supplier为表n1的事实表,该存储查询结果的装置可以建立如图3所示的关联关系树,其中,项目(lineitem)表为该关联关系树的根节点,因此,该存储查询结果的装置可以确定表lineitem为该第二查询子语句对应的目标查询表。类似地,可以根据表2所示的第一个查询子语句建立如图4所示的关联关系树,其中,该关联关系树的根节点为订单(orders)表,因此该存储查询结 果的装置可以确定表orders为表2所示的第一个查询子语句对应的目标查询表,但本发明实施例不限于此。When the association tree is established, the device storing the query result may use the fact table as the parent node of the dimension table, and one node may have multiple child nodes. At this time, since the parent node of the root node does not exist in the relationship tree, that is, the fact table of the root node is not included in the relationship tree, and the child node of the root node exists in the relationship tree, that is, the root node exists. The dimension table, therefore, the device storing the query result can determine the root node of the association tree as the target query table. Still taking the second query sub-sentence shown in Table 3 as an example, according to the table factitem is the fact table of the table supplier and the table supplier is the fact table of the table n1, the device storing the query result can establish the association as shown in FIG. The relationship tree, wherein the line item table is the root node of the relationship tree, and therefore, the device storing the query result may determine that the table lineitem is the target query table corresponding to the second query sub-statement. Similarly, the association tree shown in FIG. 4 can be established according to the first query sub-statement shown in Table 2, wherein the root node of the association relationship tree is an orders table, so the storage query node The device may determine that the table orders are the target query tables corresponding to the first query sub-statement shown in Table 2, but the embodiment of the present invention is not limited thereto.
可选地,作为另一实施例,S130,根据该目标查询表,确定该第一表的主键,包括:Optionally, as another embodiment, S130, determining, according to the target query table, the primary key of the first table, including:
确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键;Determining whether a non-union primary key of the target query table exists in multiple columns corresponding to the query result;
若该多个列中存在该目标查询表的非联合主键,将该目标查询表的非联合主键确定为该第一表的主键。If the non-union primary key of the target query table exists in the plurality of columns, the non-union primary key of the target query table is determined as the primary key of the first table.
具体地,该存储查询结果的装置可以确定该目标查询表的主键是联合主键还是非联合主键,如果该目标查询表的主键为联合主键,则该存储查询结果的装置可以确定该查询结果对应的多个列中不存在该目标查询表的非联合主键。以表3所示的第二个查询子语句为例,该第二个查询子语句对应的目标查询表为表lineitem,而表lineitem的主键为由orderkey和linenumber组成的联合主键,则该存储查询结果的装置可以确定该查询结果对应的多个列中不包括表orders的非联合主键,但本发明实施例不限于此。Specifically, the device storing the query result may determine whether the primary key of the target query table is a federated primary key or a non-unified primary key. If the primary key of the target query table is a joint primary key, the device storing the query result may determine the corresponding query result. A non-federated primary key for the target query table does not exist in more than one column. Taking the second query sub-sentence shown in Table 3 as an example, the target query table corresponding to the second query sub-statement is a table lineitem, and the primary key of the table lineitem is a joint primary key composed of orderkey and linenumber, then the stored query The resulting device may determine a non-joined primary key that does not include the table orders in the plurality of columns corresponding to the query result, but the embodiment of the present invention is not limited thereto.
可选地,如果该目标查询表的主键为非联合主键,则该存储查询结果的装置可以进一步确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键。以表2所示的第一个查询子语句为例,该第一个查询子语句对应的目标查询表为表orders,并且表orders的主键为orderkey,则该存储查询结果的装置可以确定该第一个查询子语句对应的多个列o_orderkey、n1.n_name和n2.n_name中是否包括表orders的主键orderkey。由于该多个列中包括o_orderkey,则该存储查询结果的装置可以将o_orderkey作为临时表q7_tmp_order_customer的主键,但本发明实施例不限于此。Optionally, if the primary key of the target query table is a non-union primary key, the device storing the query result may further determine whether a non-union primary key of the target query table exists in the multiple columns corresponding to the query result. Taking the first query sub-sentence shown in Table 2 as an example, the target query table corresponding to the first query sub-statement is the table orders, and the primary key of the table orders is orderkey, then the device storing the query result can determine the first Whether the plurality of columns o_orderkey, n1.n_name, and n2.n_name corresponding to a query sub-statement includes the primary key orderkey of the table orders. Since the plurality of columns includes o_orderkey, the device storing the query result may use o_orderkey as the primary key of the temporary table q7_tmp_order_customer, but the embodiment of the present invention is not limited thereto.
可选地,作为另一实施例,S130,根据该目标查询表,确定该第一表的主键,还包括:Optionally, as another embodiment, S130, determining a primary key of the first table according to the target query table, further includes:
若该查询结果对应的多个列中不存在该目标查询表的非联合主键,确定与该第一查询请求对应的第二查询请求,该第二查询请求用于请求对该第一表和第二表进行关联查询;If the non-joined primary key of the target query table does not exist in the multiple columns corresponding to the query result, determining a second query request corresponding to the first query request, the second query request is used to request the first table and the first query The second table performs an associated query;
根据该第二查询请求,确定该第一表的主键。According to the second query request, the primary key of the first table is determined.
如果该目标查询表的非联合主键不存在,即该目标查询表的主键具体为联合主键,或者如果该目标查询表的主键为非联合主键,但该查询结果对应的多个列中不包括该目标查询表的非联合主键,则该查询结果对应的多个列中不存在该目标查询表的非联合主键。此时,该存储查询结果的装置可以确 定是否存在与该第一查询请求对应的第二查询请求,如果不存在与该第一查询请求对应的第二查询请求,则该存储查询结果的装置可以将一个无实际意义的列作为该第一表的主键。如果存在与该第一查询请求对应的第二查询请求,则该存储查询结果的装置可以根据该第二查询请求确定该第一表的主键。具体地,该第二查询请求用于对该第一表和第二表进行关联查询,例如,该第一表为临时表q7_tmp_lineitem_supplier,并且表4所示的查询语句用于对临时表q7_tmp_order_customer和q7_tmp_lineitem_supplier进行关联查询,因此,表4所示的查询语句可以作为表3所示的第一查询请求对应的第二查询请求。此时,该存储查询结果的装置可以根据表4所示的查询语句确定临时表q7_tmp_lineitem_supplier的主键,但本发明实施例不限于此。If the non-federated primary key of the target query table does not exist, that is, the primary key of the target query table is specifically a union primary key, or if the primary key of the target query table is a non-union primary key, but the multiple columns corresponding to the query result do not include the The non-union primary key of the target query table, and the non-union primary key of the target query table does not exist in the multiple columns corresponding to the query result. At this point, the device that stores the query result can be confirmed Determining whether there is a second query request corresponding to the first query request, if there is no second query request corresponding to the first query request, the device storing the query result may use a column having no meaning as the first The primary key of a table. If there is a second query request corresponding to the first query request, the device storing the query result may determine the primary key of the first table according to the second query request. Specifically, the second query request is used to perform an associative query on the first table and the second table, for example, the first table is a temporary table q7_tmp_lineitem_supplier, and the query statement shown in Table 4 is used for the temporary tables q7_tmp_order_customer and q7_tmp_lineitem_supplier The association query is performed. Therefore, the query statement shown in Table 4 can be used as the second query request corresponding to the first query request shown in Table 3. At this time, the device storing the query result may determine the primary key of the temporary table q7_tmp_lineitem_supplier according to the query statement shown in Table 4, but the embodiment of the present invention is not limited thereto.
该存储查询结果的装置可以通过多种方式根据该第二查询请求确定该第一表的主键。作为一个可选实施例,该根据该第二查询请求,确定该第一表的主键,包括:The means for storing the query result may determine the primary key of the first table according to the second query request in a plurality of manners. As an optional embodiment, determining the primary key of the first table according to the second query request includes:
确定该第二查询请求对应的至少一个第二关联查询条件,其中,该第二关联查询条件由该第一表的第三列和该第二表的第四列构成;Determining at least one second associated query condition corresponding to the second query request, wherein the second associated query condition is composed of a third column of the first table and a fourth column of the second table;
从该至少一个第二关联查询条件中确定第二目标关联查询条件,该第二目标关联查询条件包括该第二表的主键;Determining, from the at least one second associated query condition, a second target associated query condition, the second target associated query condition including a primary key of the second table;
将该第二目标关联查询条件中包括的该第一表的第三列确定为该第一表的主键。The third column of the first table included in the second target association query condition is determined as the primary key of the first table.
该第二关联查询条件可以由该第一表的第三列和该第二表的第四列构成,该存储查询结果的装置可以从该第二查询请求对应的至少一个第二关联查询条件中确定第二目标关联查询条件,其中,该第二目标关联查询条件由第一表的第三列和该第二表的第四列组成,并且该第四列为该第二表的主键。该存储查询结果的装置可以将该第二目标关联查询条件中的第一表的第三列确定为该第一表的主键,但本发明实施例不限于此。The second associated query condition may be composed of a third column of the first table and a fourth column of the second table, and the device storing the query result may be from the at least one second associated query condition corresponding to the second query request Determining a second target association query condition, wherein the second target association query condition is composed of a third column of the first table and a fourth column of the second table, and the fourth column is a primary key of the second table. The device storing the query result may determine the third column of the first table in the second target association query condition as the primary key of the first table, but the embodiment of the present invention is not limited thereto.
该第二查询请求可以具体用于请求对该第一表和至少一个第二表进行关联查询。可选地,作为另一实施例,如果该第二表的个数为多个,在该存储查询结果的装置确定该第二目标关联查询条件之前,该存储查询结果的装置可以从该多个第二表中确定第二目标表,其中,该第二目标表为该多个第二表中的至少一个表的事实表,并且该多个第二表中不存在该第二目标表的事实表。此时,该存储查询结果的装置可以从该第二查询请求对应的至少一个第二关联查询条件中确定该第二目标查询条件,其中,该第二目标查询条 件由该第二目标表的主键和该第一表的第三列构成,并且该存储查询结果的装置可以将该第二目标查询条件中的该第一表的第三列作为该第一表的主键,但本发明实施例不限于此。The second query request may be specifically used to request an association query for the first table and the at least one second table. Optionally, as another embodiment, if the number of the second table is multiple, the device storing the query result may be from the multiple before the device storing the query result determines the second target association query condition Determining, in the second table, the second target table, wherein the second target table is a fact table of at least one of the plurality of second tables, and the fact that the second target table does not exist in the plurality of second tables table. At this time, the device storing the query result may determine the second target query condition from the at least one second associated query condition corresponding to the second query request, where the second target query bar The device is composed of a primary key of the second target table and a third column of the first table, and the device storing the query result may use the third column of the first table in the second target query condition as the first table The primary key, but the embodiment of the present invention is not limited thereto.
仍以表3所示的第二个查询子语句为例,表4所示的查询语句为该第二个查询子语句对应的第二查询请求,该第二查询请求用于对该第一表(临时表q7_tmp_lineitem_supplier,命名为表n2)和一个第二表(临时表q7_tmp_order_customer,命名为表n1)进行关联查询。此时,表4所示的查询语句中包括三个第二关联查询条件,“n2.l_orderkey=n1.o_orderkey”、“n1.cust_nation=n2.cust_nation”和“n1.supp_nation=n2.supp_nation”,其中,这三个第二关联查询条件中的第二目标关联查询条件为“n2.l_orderkey=n1.o_orderkey”,该目标关联查询条件由表n1的主键o_orderkey和表n2的列l_orderkey构成,则该存储查询结果的装置可以将该l_orderkey作为该临时表q7_tmp_lineitem_supplier的主键。此时,临时表q7_tmp_lineitem_supplier的主键l_orderkey与临时表q7_tmp_order_customer的主键o_orderkey相对应,两者均不存在重复数据,此时,在进行表4所示的关联查询时,可以直接查询而无需建立索引,从而提高查询效率和速度。Taking the second query sub-sentence shown in Table 3 as an example, the query statement shown in Table 4 is the second query request corresponding to the second query sub-sentence, and the second query request is used for the first table. (The temporary table q7_tmp_lineitem_supplier, named table n2) and a second table (temporary table q7_tmp_order_customer, named table n1) for the associated query. At this time, the query statement shown in Table 4 includes three second associated query conditions, "n2.l_orderkey=n1.o_orderkey", "n1.cust_nation=n2.cust_nation", and "n1.supp_nation=n2.supp_nation", The second target association query condition in the three second association query conditions is “n2.l_orderkey=n1.o_orderkey”, and the target association query condition is formed by the primary key o_orderkey of the table n1 and the column l_orderkey of the table n2, then the The device storing the query result may use the l_orderkey as the primary key of the temporary table q7_tmp_lineitem_supplier. At this time, the primary key l_orderkey of the temporary table q7_tmp_lineitem_supplier corresponds to the primary key o_orderkey of the temporary table q7_tmp_order_customer, and there is no duplicate data in both. At this time, when the related query shown in Table 4 is performed, the direct query can be performed without establishing an index, thereby Improve query efficiency and speed.
因此,根据本发明实施例的存储查询结果的方法,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, according to the method for storing the query result, the target query table is determined from the plurality of query tables corresponding to the first query request, wherein the target query table is the target query table among the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a primary key of the first table for storing the query result according to the target query table, can avoid existing In the technology, the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
应注意,表1至表4的例子是为了帮助本领域技术人员更好地理解本发明实施例,而非要限制本发明实施例的范围。本领域技术人员根据所给出的表1至表4所示的例子,显然可以进行各种等价的修改或变化,这样的修改或变化也落入本发明实施例的范围内。It should be noted that the examples of Tables 1 to 4 are intended to assist those skilled in the art to better understand the embodiments of the present invention and are not intended to limit the scope of the embodiments of the present invention. It will be obvious to those skilled in the art that various modifications and changes can be made in accordance with the examples shown in Tables 1 through 4, and such modifications or variations are also within the scope of the embodiments of the present invention.
还应理解,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本发明实施例的实施过程构成任何限定。It should be understood that the size of the sequence numbers of the above processes does not imply a sequence of executions, and the order of execution of the processes should be determined by its function and internal logic, and should not be construed as limiting the implementation of the embodiments of the present invention.
还应理解,在本发明实施例中,术语“第一”、“第二”和“第三”仅仅是为了区分不同的内容,不应对本发明实施例构成任何限定。本发明实施例 中的第一表和第二表仅仅是为了区分不同的表,第一查询表中的第一列、第二查询表中的第二列仅仅为了区分关联查询条件中的属于第一查询表的查询列和属于第二查询表的查询列,类似地,第一表中的第三列和第二表中的第四列也仅仅为了区分不同的列,而不应对该各个列在表中的具体位置造成限定。It should also be understood that in the embodiments of the present invention, the terms "first", "second", and "third" are used only to distinguish different contents, and should not be construed as limiting the embodiments of the present invention. Embodiment of the present invention The first table and the second table are only for distinguishing different tables. The first column in the first query table and the second column in the second query table are only for distinguishing among the related query conditions belonging to the first query table. Query the column and the query column belonging to the second query table. Similarly, the third column in the first table and the fourth column in the second table are only for distinguishing different columns, and the respective columns are not in the table. The specific location creates a limit.
上文中结合图1至图4,详细描述了根据本发明实施例的存储查询结果的方法,下面将结合图5至图7,描述根据本发明实施例的存储查询结果的装置。The method for storing the query result according to the embodiment of the present invention is described in detail above with reference to FIG. 1 to FIG. 4, and an apparatus for storing the query result according to an embodiment of the present invention will be described below with reference to FIG. 5 to FIG.
图5示意性地示出了根据本发明实施例的存储查询结果的装置200。如图5所示,该装置200包括:FIG. 5 schematically illustrates an apparatus 200 for storing query results in accordance with an embodiment of the present invention. As shown in FIG. 5, the apparatus 200 includes:
第一确定单元210,用于确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对该多个查询表进行关联查询;The first determining unit 210 is configured to determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an associated query for the plurality of query tables;
第二确定单元220,用于从该第一确定单元210确定的该多个查询表中确定目标查询表,其中,该多个查询表中不存在该目标查询表的事实表,并且该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表;a second determining unit 220, configured to determine a target query table from the plurality of query tables determined by the first determining unit 210, wherein a fact table of the target query table does not exist in the plurality of query tables, and the target query The table is a fact table of at least one query table of the plurality of query tables except the target query table;
第三确定单元230,用于根据该第二确定单元220确定的该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果;The third determining unit 230 is configured to determine a primary key of the first table according to the target query table determined by the second determining unit 220, where the first table is configured to store a query result corresponding to the first query request;
存储单元240,用于根据该第三确定单元230确定的该第一表的主键,将该查询结果存储至该第一表。The storage unit 240 is configured to store the query result to the first table according to the primary key of the first table determined by the third determining unit 230.
因此,根据本发明实施例的存储查询结果的装置,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, the apparatus for storing a query result according to an embodiment of the present invention determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a primary key of the first table for storing the query result according to the target query table, can avoid existing In the technology, the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
可选地,作为另一实施例,该装置200还可以包括:Optionally, as another embodiment, the apparatus 200 may further include:
接收单元,用于在该第一确定单元210确定第一查询请求对应的多个查询表之前,接收来自客户端的该第一查询请求; a receiving unit, configured to receive the first query request from the client before the first determining unit 210 determines the plurality of query tables corresponding to the first query request;
查询单元,用于根据该接收单元接收的该第一查询请求,对该多个查询表进行关联查询。The query unit is configured to perform an associative query on the plurality of lookup tables according to the first query request received by the receiving unit.
此时,该存储单元240具体用于将该查询单元获得的查询结果存储至该第一表。At this time, the storage unit 240 is specifically configured to store the query result obtained by the query unit to the first table.
可选地,该存储单元240具体用于:根据该第三确定单元230确定的该第一表的主键,以列簇的方式将该查询结果存储至该第一表。Optionally, the storage unit 240 is configured to: store the query result to the first table in a column cluster manner according to the primary key of the first table determined by the third determining unit 230.
可选地,作为另一实施例,该第二确定单元220包括:Optionally, as another embodiment, the second determining unit 220 includes:
第一确定子单元,用于确定该第一查询请求对应的至少一个第一关联查询条件,其中,该第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,该多个查询表包括该第一查询表和不同于该第一查询表的该第二查询表;a first determining subunit, configured to determine at least one first associated query condition corresponding to the first query request, where the first associated query condition is determined by a first column in the first query table and a second query table a second column, the plurality of lookup tables including the first lookup table and the second lookup table different from the first lookup table;
第二确定子单元,用于确定该第一确定子单元确定的该第一关联查询条件对应的该第一查询表与该第二查询表之间的关联关系;a second determining subunit, configured to determine an association relationship between the first query table and the second query table corresponding to the first associated query condition determined by the first determining subunit;
第三确定子单元,用于根据该第二确定子单元确定的该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表。a third determining subunit, configured to determine the target from the first query table and the second query table according to the association relationship between the first query table and the second query table determined by the second determining subunit Query the table.
可选地,作为另一实施例,该第二确定子单元具体用于:Optionally, as another embodiment, the second determining subunit is specifically configured to:
确定该第一查询表的第一列是否为该第一查询表的主键;Determining whether the first column of the first lookup table is a primary key of the first lookup table;
若该第一查询表的第一列为该第一查询表的主键,确定该第二查询表为该第一查询表的事实表;If the first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
若该第一查询表的第一列为该第一查询表的外键,确定该第一查询表为该第二查询表的事实表。If the first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
可选地,作为另一实施例,该第一查询请求对应一个第一关联查询条件;Optionally, in another embodiment, the first query request corresponds to a first associated query condition;
相应地,该第三确定子单元具体用于:Correspondingly, the third determining subunit is specifically configured to:
若该第二确定子单元确定该第二查询表为该第一查询表的事实表,则确定该第二查询表为该目标查询表;If the second determining subunit determines that the second query table is a fact table of the first query table, determining that the second query table is the target query table;
若该第二确定子单元确定该第一查询表为该第二查询表的事实表,则确定该第一查询表为该目标查询表。And if the second determining subunit determines that the first query table is a fact table of the second query table, determining that the first query table is the target query table.
可选地,作为另一实施例,该第一查询请求对应多个第一关联查询条件,此时,该第三确定子单元具体用于:Optionally, in another embodiment, the first query request corresponds to multiple first associated query conditions. In this case, the third determining sub-unit is specifically configured to:
根据该第二确定子单元确定的该第一查询表与该第二查询表之间的关 联关系,建立关联关系树,其中,若该第二查询表为该第一查询表的事实表,该第二查询表为该第一查询表的父节点;Determining between the first lookup table and the second lookup table according to the second determining subunit And establishing a relationship tree, where the second query table is a fact table of the first query table, and the second query table is a parent node of the first query table;
将该关联关系树的根节点确定为该目标查询表。The root node of the association tree is determined as the target query table.
可选地,作为另一实施例,该第三确定单元230包括:Optionally, as another embodiment, the third determining unit 230 includes:
第四确定子单元,用于确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键;a fourth determining subunit, configured to determine whether a non-union primary key of the target query table exists in multiple columns corresponding to the query result;
第五确定子单元,用于若该第四确定子单元确定该多个列中存在该目标查询表的非联合主键,将该目标查询表的非联合主键确定为该第一表的主键。And a fifth determining subunit, configured to determine, as the fourth determining subunit, the non-union primary key of the target query table in the plurality of columns, and determine the non-union primary key of the target query table as the primary key of the first table.
可选地,作为另一实施例,该第三确定单元还包括:Optionally, in another embodiment, the third determining unit further includes:
第六确定子单元,用于若该第四确定子单元确定该多个列中不存在该目标查询表的非联合主键,确定与该第一查询请求对应的第二查询请求,该第二查询请求用于请求对该第一表和第二表进行关联查询;a sixth determining subunit, configured to: if the fourth determining subunit determines that the non-joined primary key of the target query table does not exist in the plurality of columns, determine a second query request corresponding to the first query request, the second query The request is used to request an association query for the first table and the second table;
第七确定子单元,用于根据该第六确定子单元确定的该第二查询请求,确定该第一表的主键。And a seventh determining subunit, configured to determine a primary key of the first table according to the second query request determined by the sixth determining subunit.
可选地,作为另一实施例,该第七确定子单元具体用于:Optionally, in another embodiment, the seventh determining subunit is specifically configured to:
确定该第二查询请求对应的至少一个第二关联查询条件,其中,该第二关联查询条件由该第一表的第三列和该第二表的第四列构成;Determining at least one second associated query condition corresponding to the second query request, wherein the second associated query condition is composed of a third column of the first table and a fourth column of the second table;
从该至少一个第二关联查询条件中确定第二目标关联查询条件,该第二目标关联查询条件包括该第二表的主键;Determining, from the at least one second associated query condition, a second target associated query condition, the second target associated query condition including a primary key of the second table;
将该第二目标关联查询条件中包括的该第一表的第三列确定为该第一表的主键。The third column of the first table included in the second target association query condition is determined as the primary key of the first table.
根据本发明实施例的存储查询结果的装置200可对应于根据本发明实施例的存储查询结果的方法100的执行主体,并且存储查询结果的装置200中的各个模块的上述和其它操作和/或功能分别为了实现图1至图4中的各个方法的相应流程,为了简洁,在此不再赘述。The apparatus 200 for storing query results according to an embodiment of the present invention may correspond to an execution body of the method 100 of storing a query result according to an embodiment of the present invention, and storing the above and other operations of the respective modules in the apparatus 200 of the query result and/or The functions are respectively implemented in order to implement the corresponding processes of the respective methods in FIG. 1 to FIG. 4, and are not described herein for brevity.
因此,根据本发明实施例的存储查询结果的装置,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键 而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, the apparatus for storing a query result according to an embodiment of the present invention determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a primary key of the first table for storing the query result according to the target query table, can avoid existing In the technology, the column that has no practical meaning is used as the primary key of the first table. The problem of inefficient query is caused by subsequent association query on the first table, thereby improving the efficiency of the associated query.
图6示意性地示出了根据本发明实施例的另一存储查询结果的装置300。如图6所示,该装置300包括:FIG. 6 schematically illustrates another apparatus 300 for storing query results in accordance with an embodiment of the present invention. As shown in FIG. 6, the apparatus 300 includes:
处理器310,用于:确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对该多个查询表进行关联查询;从该多个查询表中确定目标查询表,其中,该多个查询表中不存在该目标查询表的事实表,并且该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表;根据该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果;The processor 310 is configured to: determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an associated query for the plurality of query tables; and determine a target query table from the plurality of query tables The fact table of the target query table does not exist in the plurality of query tables, and the target query table is a fact table of at least one query table of the plurality of query tables except the target query table; according to the target Querying a table, determining a primary key of the first table, where the first table is configured to store a query result corresponding to the first query request;
存储器320,用于根据该处理器310确定的该第一表的主键,将该查询结果存储至该第一表。The memory 320 is configured to store the query result to the first table according to the primary key of the first table determined by the processor 310.
因此,根据本发明实施例的存储查询结果的装置,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, the apparatus for storing a query result according to an embodiment of the present invention determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a primary key of the first table for storing the query result according to the target query table, can avoid existing In the technology, the column with no practical meaning is used as the primary key of the first table, which causes the query efficiency to be low when the related query is performed on the first table, thereby improving the efficiency of the related query.
应理解,在本发明实施例中,该处理器310可以是中央处理单元(Central Processing Unit,简称为“CPU”),该处理器310还可以是其他通用处理器、数字信号处理器(DSP)、专用集成电路(ASIC)、现成可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in the embodiment of the present invention, the processor 310 may be a central processing unit ("CPU"), and the processor 310 may also be other general-purpose processors, digital signal processors (DSPs). , an application specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, and the like. The general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
该存储器320可以包括只读存储器和随机存取存储器,并向处理器310提供指令和数据。存储器320的一部分还可以包括非易失性随机存取存储器。例如,存储器320还可以存储设备类型的信息。The memory 320 can include read only memory and random access memory and provides instructions and data to the processor 310. A portion of the memory 320 may also include a non-volatile random access memory. For example, the memory 320 can also store information of the device type.
在实现过程中,上述方法的各步骤可以通过处理器310中的硬件的集成逻辑电路或者软件形式的指令完成。结合本发明实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只 读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器320,处理器310读取存储器320中的信息,结合其硬件完成上述方法的步骤。为避免重复,这里不再详细描述。In the implementation process, each step of the foregoing method may be completed by an integrated logic circuit of hardware in the processor 310 or an instruction in a form of software. The steps of the method disclosed in the embodiments of the present invention may be directly implemented as a hardware processor, or may be performed by a combination of hardware and software modules in the processor. Software modules can be located in random access memory, flash memory, read-only memory, programmable only Read memory or electrically erasable programmable memory, registers, etc. are well-known storage media in the field. The storage medium is located in the memory 320, and the processor 310 reads the information in the memory 320 and combines the hardware to perform the steps of the above method. To avoid repetition, it will not be described in detail here.
可选地,作为另一实施例,该装置200还可以包括:Optionally, as another embodiment, the apparatus 200 may further include:
接收器,用于在该处理器310确定第一查询请求对应的多个查询表之前,接收来自客户端的该第一查询请求;a receiver, configured to receive the first query request from the client before the processor 310 determines the plurality of query tables corresponding to the first query request;
相应地,该处理器310还用于根据该接收器接收的该第一查询请求,对该多个查询表进行关联查询。Correspondingly, the processor 310 is further configured to perform an association query on the plurality of lookup tables according to the first query request received by the receiver.
此时,该存储器320具体用于将该处理器310获得的查询结果存储至该第一表。At this time, the memory 320 is specifically configured to store the query result obtained by the processor 310 to the first table.
可选地,该存储器320具体用于:根据该处理器310确定的该第一表的主键,以列簇的方式将该查询结果存储至该第一表。Optionally, the memory 320 is specifically configured to: store the query result to the first table in a column cluster manner according to the primary key of the first table determined by the processor 310.
可选地,作为另一实施例,该处理器310具体用于:Optionally, as another embodiment, the processor 310 is specifically configured to:
确定该第一查询请求对应的至少一个第一关联查询条件,其中,该第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,该多个查询表包括该第一查询表和不同于该第一查询表的该第二查询表;Determining at least one first associated query condition corresponding to the first query request, wherein the first associated query condition is composed of a first column in the first query table and a second column in the second query table, the multiple queries The table includes the first lookup table and the second lookup table different from the first lookup table;
确定该第一关联查询条件对应的该第一查询表与该第二查询表之间的关联关系;Determining an association relationship between the first query table and the second query table corresponding to the first associated query condition;
根据该第一查询表与该第二查询表之间的关联关系,从该第一查询表和该第二查询表中确定该目标查询表。Determining the target query table from the first query table and the second query table according to the association relationship between the first query table and the second query table.
可选地,作为另一实施例,该处理器310具体用于:Optionally, as another embodiment, the processor 310 is specifically configured to:
确定该第一查询表的第一列是否为该第一查询表的主键;Determining whether the first column of the first lookup table is a primary key of the first lookup table;
若该第一查询表的第一列为该第一查询表的主键,确定该第二查询表为该第一查询表的事实表;If the first column of the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
若该第一查询表的第一列为该第一查询表的外键,确定该第一查询表为该第二查询表的事实表。If the first column of the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
可选地,作为另一实施例,该第一查询请求对应一个第一关联查询条件;Optionally, in another embodiment, the first query request corresponds to a first associated query condition;
相应地,该处理器310具体用于:Correspondingly, the processor 310 is specifically configured to:
若确定该第二查询表为该第一查询表的事实表,则确定该第二查询表为该目标查询表;If it is determined that the second query table is a fact table of the first query table, determining that the second query table is the target query table;
若确定该第一查询表为该第二查询表的事实表,则确定该第一查询表为 该目标查询表。If it is determined that the first query table is a fact table of the second query table, determining that the first query table is The target query table.
可选地,作为另一实施例,该第一查询请求对应多个第一关联查询条件,此时,该处理器310具体用于:Optionally, in another embodiment, the first query request corresponds to multiple first associated query conditions. In this case, the processor 310 is specifically configured to:
根据该第一查询表与该第二查询表之间的关联关系,建立关联关系树,其中,若该第二查询表为该第一查询表的事实表,该第二查询表为该第一查询表的父节点;And establishing, according to the association relationship between the first query table and the second query table, the second query table is the first query table, and the second query table is the first Query the parent node of the table;
将该关联关系树的根节点确定为该目标查询表。The root node of the association tree is determined as the target query table.
可选地,作为另一实施例,该处理器310还用于:Optionally, as another embodiment, the processor 310 is further configured to:
确定该查询结果对应的多个列中是否存在该目标查询表的非联合主键;Determining whether a non-union primary key of the target query table exists in multiple columns corresponding to the query result;
若确定该多个列中存在该目标查询表的非联合主键,将该目标查询表的非联合主键确定为该第一表的主键。If it is determined that the non-union primary key of the target query table exists in the plurality of columns, the non-union primary key of the target query table is determined as the primary key of the first table.
可选地,作为另一实施例,该处理器310还用于:Optionally, as another embodiment, the processor 310 is further configured to:
若确定该多个列中不存在该目标查询表的非联合主键,确定与该第一查询请求对应的第二查询请求,该第二查询请求用于请求对该第一表和第二表进行关联查询;If it is determined that the non-joined primary key of the target query table does not exist in the plurality of columns, determining a second query request corresponding to the first query request, the second query request is used to request to perform the first table and the second table Associated query;
根据该第二查询请求,确定该第一表的主键。According to the second query request, the primary key of the first table is determined.
可选地,作为另一实施例,该该处理器310具体用于:Optionally, in another embodiment, the processor 310 is specifically configured to:
确定该第二查询请求对应的至少一个第二关联查询条件,其中,该第二关联查询条件由该第一表的第三列和该第二表的第四列构成;Determining at least one second associated query condition corresponding to the second query request, wherein the second associated query condition is composed of a third column of the first table and a fourth column of the second table;
从该至少一个第二关联查询条件中确定第二目标关联查询条件,该第二目标关联查询条件包括该第二表的主键;Determining, from the at least one second associated query condition, a second target associated query condition, the second target associated query condition including a primary key of the second table;
将该第二目标关联查询条件中包括的该第一表的第三列确定为该第一表的主键。The third column of the first table included in the second target association query condition is determined as the primary key of the first table.
根据本发明实施例的存储查询结果的装置300可对应于根据本发明实施例的存储查询结果的方法100的执行主体,并且存储查询结果的装置300中的各个模块的上述和其它操作和/或功能分别为了实现图1至图4中的各个方法的相应流程,为了简洁,在此不再赘述。The apparatus 300 for storing query results according to an embodiment of the present invention may correspond to an execution body of the method 100 of storing a query result according to an embodiment of the present invention, and storing the above and other operations of the respective modules in the apparatus 300 of the query result and/or The functions are respectively implemented in order to implement the corresponding processes of the respective methods in FIG. 1 to FIG. 4, and are not described herein for brevity.
因此,根据本发明实施例的存储查询结果的装置,从第一查询请求对应的多个查询表中确定目标查询表,其中,该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表,并且该多个查询表中不存在该目标查询表的事实表,并且根据该目标查询表确定用于存储查询结果的第 一表的主键,能够避免现有技术中由于将无实际意义的列作为第一表的主键而造成后续对第一表进行关联查询时查询效率低下的问题,从而提高关联查询的效率。Therefore, the apparatus for storing a query result according to an embodiment of the present invention determines a target query table from a plurality of query tables corresponding to the first query request, wherein the target query table is the target query table of the plurality of query tables. a fact table of at least one query table, and a fact table of the target query table does not exist in the plurality of query tables, and determining a number for storing the query result according to the target query table The primary key of a table can avoid the problem that the query efficiency is low when the related query of the first table is subsequently performed due to the column having no practical meaning as the primary key of the first table in the prior art, thereby improving the efficiency of the associated query.
图7示意性地示出了根据本发明实施例的计算设备400。如图7所示,该计算设备400包括:处理器402、存储器404和总线410。其中,处理器402和存储器404通过总线410实现彼此之间的通信连接。FIG. 7 schematically illustrates a computing device 400 in accordance with an embodiment of the present invention. As shown in FIG. 7, the computing device 400 includes a processor 402, a memory 404, and a bus 410. The processor 402 and the memory 404 implement a communication connection with each other through the bus 410.
处理器402可以采用通用的中央处理器(Central Processing Unit,CPU),微处理器,应用专用集成电路(Application Specific Integrated Circuit,ASIC),或者一个或多个集成电路,用于执行相关程序,以实现本发明实施例所提供的技术方案。The processor 402 can be a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), or one or more integrated circuits for executing related programs. The technical solution provided by the embodiment of the present invention is implemented.
存储器404可以是只读存储器(Read Only Memory,ROM),静态存储设备,动态存储设备或者随机存取存储器(Random Access Memory,RAM)。存储器404可以存储操作系统和其他应用程序。在通过软件或者固件来实现本发明实施例提供的技术方案时,用于实现本发明实施例提供的技术方案的程序代码保存在存储器404中,并由处理器402来执行。The memory 404 may be a read only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). Memory 404 can store operating systems and other applications. When the technical solution provided by the embodiment of the present invention is implemented by software or firmware, the program code for implementing the technical solution provided by the embodiment of the present invention is stored in the memory 404 and executed by the processor 402.
具体地,存储器404可以用于存储可执行指令,也可以用于存储各种信息,例如,查询结果。处理器402可以通过总线系统410读取该存储器404存储的信息,或者将查询结果存储至存储器404。此外,当该计算设备400运行时,处理器402可以执行存储器404存储的可执行指令,以确定第一查询请求对应的多个查询表,其中,该第一查询请求用于请求对该多个查询表进行关联查询;从该多个查询表中确定目标查询表,其中,该多个查询表中不存在该目标查询表的事实表,并且该目标查询表为该多个查询表中除该目标查询表之外的至少一个查询表的事实表;根据该目标查询表,确定第一表的主键,其中,该第一表用于存储该第一查询请求对应的查询结果;根据该第一表的主键,将该查询结果存储至该第一表。In particular, the memory 404 can be used to store executable instructions, as well as to store various information, such as query results. The processor 402 can read the information stored by the memory 404 via the bus system 410 or store the query results to the memory 404. Moreover, when the computing device 400 is running, the processor 402 can execute executable instructions stored by the memory 404 to determine a plurality of lookup tables corresponding to the first query request, wherein the first query request is for requesting the plurality of lookup tables The query table performs an association query; the target query table is determined from the plurality of query tables, wherein the fact table of the target query table does not exist in the plurality of query tables, and the target query table is the plurality of query tables a fact table of at least one query table other than the target query table; determining, according to the target query table, a primary key of the first table, wherein the first table is configured to store a query result corresponding to the first query request; The primary key of the table stores the query result to the first table.
可选地,如图7所示,该计算设备还可以包括输入/输出接口406和通信接口408。输入/输出接口406用于接收输入的数据和信息,输出操作结果等数据。Optionally, as shown in FIG. 7, the computing device can also include an input/output interface 406 and a communication interface 408. The input/output interface 406 is for receiving input data and information, and outputting data such as operation results.
通信接口408使用例如但不限于收发器一类的收发装置,来实现计算设备400与其他设备或通信网络之间的通信。 Communication interface 408 enables communication between computing device 400 and other devices or communication networks using transceivers such as, but not limited to, transceivers.
总线410可包括一通路,在计算设备400各个部件(例如处理器402、存储器404、输入/输出接口406和通信接口408)之间传送信息。 Bus 410 may include a path for communicating information between various components of computing device 400, such as processor 402, memory 404, input/output interface 406, and communication interface 408.
图7所示的硬件结构以及上述描述适用于执行本发明实施例所提供的各种存储查询结果的方法,例如,图1至图4所示的各种方法流程,为了简洁,这里不再赘述。The hardware structure shown in FIG. 7 and the foregoing description are applicable to performing various methods for storing query results provided by the embodiments of the present invention. For example, the various method flows shown in FIG. 1 to FIG. 4 are omitted for brevity. .
应注意,尽管图7所示的计算设备400仅仅示出了处理器402、存储器404、输入/输出接口406、通信接口408以及总线410,但是在具体实现过程中,本领域的技术人员应当明白,计算设备400还包含实现正常运行所必须的其他器件。同时,根据具体需要,本领域的技术人员应当明白,计算设备400还可包含实现其他附加功能的硬件器件。此外,本领域的技术人员应当明白,计算设备400也可仅仅包含实现本发明实施例所必须的器件,而不必包含图7中所示的全部器件。It should be noted that although the computing device 400 illustrated in FIG. 7 only shows the processor 402, the memory 404, the input/output interface 406, the communication interface 408, and the bus 410, those skilled in the art will appreciate in a particular implementation. The computing device 400 also includes other devices necessary to achieve proper operation. Also, those skilled in the art will appreciate that computing device 400 may also include hardware devices that implement other additional functions, depending on the particular needs. Moreover, those skilled in the art will appreciate that computing device 400 may also only include the components necessary to implement embodiments of the present invention, and does not necessarily include all of the devices shown in FIG.
应理解,在本发明实施例中,术语和/或仅仅是一种描述关联对象的关联关系,表示可以存在三种关系。例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符/,一般表示前后关联对象是一种或的关系。It should be understood that in the embodiments of the present invention, the term and/or merely an association relationship describing the associated object indicates that there may be three relationships. For example, A and/or B may indicate that A exists separately, and A and B exist simultaneously, and B cases exist alone. In addition, the character / in this paper generally indicates that the contextual object is an OR relationship.
本领域普通技术人员可以意识到,结合本文中所公开的实施例中描述的各方法步骤和单元,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各实施例的步骤及组成。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。本领域普通技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Those skilled in the art will appreciate that the various method steps and elements described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both, in order to clearly illustrate hardware and software. Interchangeability, the steps and composition of the various embodiments have been generally described in terms of function in the foregoing description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the solution. Different methods may be used to implement the described functionality for each particular application, but such implementation should not be considered to be beyond the scope of the present invention.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。 In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本发明实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The integrated unit, if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium. A number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。 The above is only the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any equivalent person can be easily conceived within the technical scope of the present invention by any person skilled in the art. Modifications or substitutions are intended to be included within the scope of the invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims (19)

  1. 一种存储查询结果的方法,其特征在于,包括:A method for storing query results, comprising:
    确定第一查询请求对应的多个查询表,其中,所述第一查询请求用于请求对所述多个查询表进行关联查询;Determining, by the first query request, a plurality of query tables, where the first query request is used to request an association query on the plurality of query tables;
    从所述多个查询表中确定目标查询表,其中,所述多个查询表中不存在所述目标查询表的事实表,并且所述目标查询表为所述多个查询表中除所述目标查询表之外的至少一个查询表的事实表;Determining, from the plurality of query tables, a target query table, wherein the fact table of the target query table does not exist in the plurality of query tables, and the target query table is the plurality of query tables except a fact table of at least one lookup table other than the target lookup table;
    根据所述目标查询表,确定第一表的主键,其中,所述第一表用于存储所述第一查询请求对应的查询结果;Determining, according to the target query table, a primary key of the first table, where the first table is configured to store a query result corresponding to the first query request;
    根据所述第一表的主键,将所述查询结果存储至所述第一表。The query result is stored to the first table according to the primary key of the first table.
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述第一表的主键,将所述查询结果存储至所述第一表,包括:The method according to claim 1, wherein the storing the query result to the first table according to the primary key of the first table comprises:
    根据所述第一表的主键,以列簇的方式将所述查询结果存储至所述第一表。The query result is stored in the first table in a column cluster manner according to the primary key of the first table.
  3. 根据权利要求1或2所述的方法,其特征在于,所述从所述多个查询表中确定目标查询表,包括:The method according to claim 1 or 2, wherein the determining the target query table from the plurality of lookup tables comprises:
    确定所述第一查询请求对应的至少一个第一关联查询条件,其中,所述第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,所述多个查询表包括所述第一查询表和不同于所述第一查询表的所述第二查询表;Determining at least one first associated query condition corresponding to the first query request, where the first associated query condition is formed by a first column in the first query table and a second column in the second query table, The plurality of lookup tables include the first lookup table and the second lookup table different from the first lookup table;
    确定所述至少一个关联查询条件对应的所述第一查询表与所述第二查询表之间的关联关系;Determining an association relationship between the first query table and the second query table corresponding to the at least one associated query condition;
    根据所述第一查询表与所述第二查询表之间的关联关系,从所述第一查询表和所述第二查询表中确定所述目标查询表。Determining the target query table from the first query table and the second query table according to an association relationship between the first query table and the second query table.
  4. 根据权利要求3所述的方法,其特征在于,所述确定所述至少一个关联查询条件对应的所述第一查询表与所述第二查询表之间的关联关系,包括:The method according to claim 3, wherein the determining the association relationship between the first query table and the second query table corresponding to the at least one associated query condition comprises:
    确定所述第一查询表中的第一列是否为所述第一查询表的主键;Determining whether the first column in the first query table is a primary key of the first query table;
    若所述第一查询表中的第一列为所述第一查询表的主键,确定所述第二查询表为所述第一查询表的事实表;If the first column in the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
    若所述第一查询表中的第一列为所述第一查询表的外键,确定所述第一 查询表为所述第二查询表的事实表。Determining the first if the first column in the first lookup table is a foreign key of the first lookup table The lookup table is a fact table of the second lookup table.
  5. 根据权利要求4所述的方法,其特征在于,所述第一查询请求对应一个第一关联查询条件;The method according to claim 4, wherein the first query request corresponds to a first associated query condition;
    所述根据所述第一查询表与所述第二查询表之间的关联关系,从所述第一查询表和所述第二查询表中确定所述目标查询表,包括:Determining, according to the association relationship between the first query table and the second query table, the target query table from the first query table and the second query table, including:
    若所述第二查询表为所述第一查询表的事实表,则确定所述第二查询表为所述目标查询表;If the second lookup table is a fact table of the first lookup table, determining that the second query table is the target lookup table;
    若所述第一查询表为所述第二查询表的事实表,则确定所述第一查询表为所述目标查询表。And if the first query table is a fact table of the second query table, determining that the first query table is the target query table.
  6. 根据权利要求3或4所述的方法,其特征在于,所述第一查询请求对应多个第一关联查询条件;The method according to claim 3 or 4, wherein the first query request corresponds to a plurality of first associated query conditions;
    所述根据所述第一查询表与所述第二查询表之间的关联关系,从所述第一查询表和所述第二查询表中确定所述目标查询表,包括:Determining, according to the association relationship between the first query table and the second query table, the target query table from the first query table and the second query table, including:
    根据所述第一查询表与所述第二查询表之间的关联关系,建立关联关系树,其中,若所述第二查询表为所述第一查询表的事实表,所述第二查询表为所述第一查询表的父节点;Establishing an association relationship tree according to the association relationship between the first query table and the second query table, where the second query table is a fact table of the first query table, the second query The table is the parent node of the first query table;
    将所述关联关系树的根节点确定为所述目标查询表。The root node of the association tree is determined as the target lookup table.
  7. 根据权利要求1至6中任一项所述的方法,其特征在于,所述根据所述目标查询表,确定所述第一表的主键,包括:The method according to any one of claims 1 to 6, wherein the determining the primary key of the first table according to the target query table comprises:
    确定所述查询结果对应的多个列中是否存在所述目标查询表的非联合主键;Determining whether a non-union primary key of the target query table exists in a plurality of columns corresponding to the query result;
    若所述多个列中存在所述目标查询表的非联合主键,将所述目标查询表的非联合主键确定为所述第一表的主键。If the non-union primary key of the target query table exists in the plurality of columns, determining the non-union primary key of the target query table as the primary key of the first table.
  8. 根据权利要求7所述的方法,其特征在于,所述根据所述目标查询表,确定所述第一表的主键,还包括:The method according to claim 7, wherein the determining the primary key of the first table according to the target query table further comprises:
    若所述多个列中不存在所述目标查询表的非联合主键,确定与所述第一查询请求对应的第二查询请求,所述第二查询请求用于请求对所述第一表和第二表进行关联查询;Determining, according to the non-joined primary key of the target query table, the second query request corresponding to the first query request, where the second query request is used to request the first table and The second table performs an associated query;
    根据所述第二查询请求,确定所述第一表的主键。Determining a primary key of the first table according to the second query request.
  9. 根据权利要求8所述的方法,其特征在于,所述根据所述第二查询请求,确定所述第一表的主键,包括: The method according to claim 8, wherein the determining the primary key of the first table according to the second query request comprises:
    确定所述第二查询请求对应的至少一个第二关联查询条件,其中,所述第二关联查询条件由所述第一表的第三列和所述第二表的第四列构成;Determining at least one second associated query condition corresponding to the second query request, wherein the second associated query condition is composed of a third column of the first table and a fourth column of the second table;
    从所述至少一个第二关联查询条件中确定第二目标关联查询条件,所述第二目标关联查询条件包括所述第二表的主键;Determining, from the at least one second associated query condition, a second target association query condition, where the second target association query condition includes a primary key of the second table;
    将所述第二目标关联查询条件中包括的所述第一表的第三列确定为所述第一表的主键。The third column of the first table included in the second target association query condition is determined as the primary key of the first table.
  10. 一种存储查询结果的装置,其特征在于,包括:An apparatus for storing a query result, comprising:
    第一确定单元,用于确定第一查询请求对应的多个查询表,其中,所述第一查询请求用于请求对所述多个查询表进行关联查询;a first determining unit, configured to determine a plurality of query tables corresponding to the first query request, where the first query request is used to request an associated query for the multiple query tables;
    第二确定单元,用于从所述第一确定单元确定的所述多个查询表中确定目标查询表,其中,所述多个查询表中不存在所述目标查询表的事实表,并且所述目标查询表为所述多个查询表中除所述目标查询表之外的至少一个查询表的事实表;a second determining unit, configured to determine a target query table from the plurality of query tables determined by the first determining unit, wherein a fact table of the target query table does not exist in the plurality of query tables, and The target query table is a fact table of at least one query table of the plurality of query tables except the target query table;
    第三确定单元,用于根据所述第二确定单元确定的所述目标查询表,确定第一表的主键,其中,所述第一表用于存储所述第一查询请求对应的查询结果;a third determining unit, configured to determine a primary key of the first table according to the target query table determined by the second determining unit, where the first table is configured to store a query result corresponding to the first query request;
    存储单元,用于根据所述第三确定单元确定的所述第一表的主键,将所述查询结果存储至所述第一表。a storage unit, configured to store the query result to the first table according to the primary key of the first table determined by the third determining unit.
  11. 根据权利要求10所述的装置,其特征在于,所述存储单元具体用于:The device according to claim 10, wherein the storage unit is specifically configured to:
    根据所述第三确定单元确定的所述第一表的主键,以列簇的方式将所述查询结果存储至所述第一表。And storing, according to the primary key of the first table determined by the third determining unit, the query result to the first table in a column cluster manner.
  12. 根据权利要求10或11所述的装置,其特征在于,所述第二确定单元包括:The apparatus according to claim 10 or 11, wherein the second determining unit comprises:
    第一确定子单元,用于确定所述第一查询请求对应的至少一个第一关联查询条件,其中,所述第一关联查询条件由第一查询表中的第一列和第二查询表中的第二列构成,所述多个查询表包括所述第一查询表和不同于所述第一查询表的所述第二查询表;a first determining sub-unit, configured to determine at least one first associated query condition corresponding to the first query request, where the first associated query condition is included in a first column and a second query table in the first query table The second column is configured, the plurality of lookup tables including the first lookup table and the second lookup table different from the first lookup table;
    第二确定子单元,用于确定所述第一确定子单元确定的所述至少一个关联查询条件对应的所述第一查询表与所述第二查询表之间的关联关系;a second determining subunit, configured to determine an association relationship between the first query table and the second query table corresponding to the at least one associated query condition determined by the first determining subunit;
    第三确定子单元,用于根据所述第二确定子单元确定的所述第一查询表 与所述第二查询表之间的关联关系,从所述第一查询表和所述第二查询表中确定所述目标查询表。a third determining subunit, configured to determine the first query table according to the second determining subunit And the association relationship with the second query table, determining the target query table from the first query table and the second query table.
  13. 根据权利要求12所述的装置,其特征在于,所述第二确定子单元具体用于:The apparatus according to claim 12, wherein the second determining subunit is specifically configured to:
    确定所述第一查询表中的第一列是否为所述第一查询表的主键;Determining whether the first column in the first query table is a primary key of the first query table;
    若所述第一查询表中的第一列为所述第一查询表的主键,确定所述第二查询表为所述第一查询表的事实表;If the first column in the first query table is the primary key of the first query table, determining that the second query table is a fact table of the first query table;
    若所述第一查询表中的第一列为所述第一查询表的外键,确定所述第一查询表为所述第二查询表的事实表。If the first column in the first query table is a foreign key of the first query table, determining that the first query table is a fact table of the second query table.
  14. 根据权利要求13所述的装置,其特征在于,所述第一查询请求对应一个第一关联查询条件;The apparatus according to claim 13, wherein the first query request corresponds to a first associated query condition;
    所述第三确定子单元具体用于:The third determining subunit is specifically configured to:
    若所述第二确定子单元确定所述第二查询表为所述第一查询表的事实表,则确定所述第二查询表为所述目标查询表;If the second determining subunit determines that the second query table is a fact table of the first query table, determining that the second query table is the target query table;
    若所述第二确定子单元确定所述第一查询表为所述第二查询表的事实表,则确定所述第一查询表为所述目标查询表。And if the second determining subunit determines that the first query table is a fact table of the second query table, determining that the first query table is the target query table.
  15. 根据权利要求12或13所述的装置,其特征在于,所述第一查询请求对应多个第一关联查询条件;The apparatus according to claim 12 or 13, wherein the first query request corresponds to a plurality of first associated query conditions;
    所述第三确定子单元具体用于:The third determining subunit is specifically configured to:
    根据所述第二确定子单元确定的所述第一查询表与所述第二查询表之间的关联关系,建立关联关系树,其中,若所述第二查询表为所述第一查询表的事实表,所述第二查询表为所述第一查询表的父节点;Establishing an association relationship tree according to the association relationship between the first query table and the second query table determined by the second determining subunit, where the second query table is the first query table a fact table, the second query table is a parent node of the first query table;
    将所述关联关系树的根节点确定为所述目标查询表。The root node of the association tree is determined as the target lookup table.
  16. 根据权利要求10至15中任一项所述的装置,其特征在于,所述第三确定单元包括:The apparatus according to any one of claims 10 to 15, wherein the third determining unit comprises:
    第四确定子单元,用于确定所述查询结果对应的多个列中是否存在所述目标查询表的非联合主键;a fourth determining subunit, configured to determine whether a non-joined primary key of the target query table exists in multiple columns corresponding to the query result;
    第五确定子单元,用于若所述第四确定子单元确定所述多个列中存在所述目标查询表的非联合主键,将所述目标查询表的非联合主键确定为所述第一表的主键。a fifth determining subunit, configured to determine, as the first determining subunit, a non-union primary key of the target query table in the plurality of columns, determining a non-union primary key of the target query table as the first The primary key of the table.
  17. 根据权利要求16所述的装置,其特征在于,所述第三确定单元还 包括:The apparatus according to claim 16, wherein said third determining unit further include:
    第六确定子单元,用于若所述第四确定子单元确定所述多个列中不存在所述目标查询表的非联合主键,确定与所述第一查询请求对应的第二查询请求,所述第二查询请求用于请求对所述第一表和第二表进行关联查询;a sixth determining subunit, configured to: if the fourth determining subunit determines that the non-joined primary key of the target query table does not exist in the plurality of columns, determine a second query request corresponding to the first query request, The second query request is used to request an association query for the first table and the second table;
    第七确定子单元,用于根据所述第六确定子单元确定的所述第二查询请求,确定所述第一表的主键。a seventh determining subunit, configured to determine a primary key of the first table according to the second query request determined by the sixth determining subunit.
  18. 根据权利要求17所述的装置,其特征在于,所述第七确定子单元具体用于:The apparatus according to claim 17, wherein the seventh determining subunit is specifically configured to:
    确定所述第二查询请求对应的至少一个第二关联查询条件,其中,所述第二关联查询条件由所述第一表的第三列和所述第二表的第四列构成;Determining at least one second associated query condition corresponding to the second query request, wherein the second associated query condition is composed of a third column of the first table and a fourth column of the second table;
    从所述至少一个第二关联查询条件中确定第二目标关联查询条件,所述第二目标关联查询条件包括所述第二表的主键;Determining, from the at least one second associated query condition, a second target association query condition, where the second target association query condition includes a primary key of the second table;
    将所述第二目标关联查询条件中包括的所述第一表的第三列确定为所述第一表的主键。The third column of the first table included in the second target association query condition is determined as the primary key of the first table.
  19. 一种计算设备,其特征在于,包括:处理器、存储器和总线;A computing device, comprising: a processor, a memory, and a bus;
    所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述总线连接,当所述计算设备运行时,所述处理器读取所述存储器存储的所述计算机执行指令,以执行权利要求1至9中任一项所述的方法。 The memory is configured to store computer execution instructions, the processor is coupled to the memory via the bus, and when the computing device is in operation, the processor reads the computer execution instructions stored in the memory to The method of any one of claims 1 to 9.
PCT/CN2015/070656 2015-01-14 2015-01-14 Method, apparatus and computing device for storing query result WO2016112502A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201580001205.4A CN107735781B (en) 2015-01-14 2015-01-14 Method and device for storing query result and computing equipment
PCT/CN2015/070656 WO2016112502A1 (en) 2015-01-14 2015-01-14 Method, apparatus and computing device for storing query result

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2015/070656 WO2016112502A1 (en) 2015-01-14 2015-01-14 Method, apparatus and computing device for storing query result

Publications (1)

Publication Number Publication Date
WO2016112502A1 true WO2016112502A1 (en) 2016-07-21

Family

ID=56405107

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/070656 WO2016112502A1 (en) 2015-01-14 2015-01-14 Method, apparatus and computing device for storing query result

Country Status (2)

Country Link
CN (1) CN107735781B (en)
WO (1) WO2016112502A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110597849A (en) * 2018-05-25 2019-12-20 北京国双科技有限公司 Data query method and device
CN112699149A (en) * 2020-12-31 2021-04-23 青岛海尔科技有限公司 Target data acquisition method and device, storage medium and electronic device
CN114896280A (en) * 2022-03-22 2022-08-12 杭州未名信科科技有限公司 Data query method and system

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109683987B (en) * 2018-12-19 2022-02-01 珠海港联科技有限公司 Configurable software dynamic interface loading and data processing method
CN111143481A (en) * 2019-12-20 2020-05-12 中国建设银行股份有限公司 Method, device and equipment for connecting unassociated look-up table and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060026199A1 (en) * 2004-07-15 2006-02-02 Mariano Crea Method and system to load information in a general purpose data warehouse database
US20100280991A1 (en) * 2009-05-01 2010-11-04 International Business Machines Corporation Method and system for versioning data warehouses
CN102521416A (en) * 2011-12-28 2012-06-27 用友软件股份有限公司 Data correlation query method and data correlation query device
CN102968420A (en) * 2011-08-31 2013-03-13 国际商业机器公司 Database query method and system
CN103473267A (en) * 2013-08-09 2013-12-25 深圳市中科新业信息科技发展有限公司 Data storage query method and system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070027860A1 (en) * 2005-07-28 2007-02-01 International Business Machines Corporation Method and apparatus for eliminating partitions of a database table from a join query using implicit limitations on a partition key value
CN101197876B (en) * 2006-12-06 2012-02-29 中兴通讯股份有限公司 Method and system for multi-dimensional analysis of message service data
US8285709B2 (en) * 2009-05-12 2012-10-09 Teradata Us, Inc. High-concurrency query operator and method
CN101916261B (en) * 2010-07-28 2013-07-17 北京播思软件技术有限公司 Data partitioning method for distributed parallel database system
CN104166740A (en) * 2014-09-10 2014-11-26 税友软件集团股份有限公司 Data inquiry method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060026199A1 (en) * 2004-07-15 2006-02-02 Mariano Crea Method and system to load information in a general purpose data warehouse database
US20100280991A1 (en) * 2009-05-01 2010-11-04 International Business Machines Corporation Method and system for versioning data warehouses
CN102968420A (en) * 2011-08-31 2013-03-13 国际商业机器公司 Database query method and system
CN102521416A (en) * 2011-12-28 2012-06-27 用友软件股份有限公司 Data correlation query method and data correlation query device
CN103473267A (en) * 2013-08-09 2013-12-25 深圳市中科新业信息科技发展有限公司 Data storage query method and system

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110597849A (en) * 2018-05-25 2019-12-20 北京国双科技有限公司 Data query method and device
CN110597849B (en) * 2018-05-25 2022-03-22 北京国双科技有限公司 Data query method and device
CN112699149A (en) * 2020-12-31 2021-04-23 青岛海尔科技有限公司 Target data acquisition method and device, storage medium and electronic device
CN112699149B (en) * 2020-12-31 2023-09-19 青岛海尔科技有限公司 Target data acquisition method and device, storage medium and electronic device
CN114896280A (en) * 2022-03-22 2022-08-12 杭州未名信科科技有限公司 Data query method and system

Also Published As

Publication number Publication date
CN107735781B (en) 2020-03-10
CN107735781A (en) 2018-02-23

Similar Documents

Publication Publication Date Title
US20220382778A1 (en) Aggregation framework system architecture and method
US10318551B2 (en) Reporting and summarizing metrics in sparse relationships on an OLTP database
US11544284B2 (en) Aggregation framework system architecture and method
US10366100B2 (en) Aggregation framework system architecture and method
US9767149B2 (en) Joining data across a parallel database and a distributed processing system
WO2016112502A1 (en) Method, apparatus and computing device for storing query result
WO2021068549A1 (en) Data processing method, platform and system
US10152682B2 (en) Configurable data accumulators
US9582553B2 (en) Systems and methods for analyzing existing data models
US9760604B2 (en) System and method for adaptive filtering of data requests
US9305074B2 (en) Skew-aware storage and query execution on distributed database systems
US11132363B2 (en) Distributed computing framework and distributed computing method
TW202004526A (en) Index creating method and apparatus based on NoSQL database of mobile terminal
US20230161765A1 (en) System and method for disjunctive joins using a lookup table
WO2020215830A1 (en) Method for outer join of table of database, and system
US10552406B2 (en) Maintaining object and query result consistency in a triplestore database
CN106326295B (en) Semantic data storage method and device
WO2016119508A1 (en) Method for recognizing large-scale objects based on spark system
WO2016119276A1 (en) Large-scale object recognition method based on hadoop frame
US20220391390A1 (en) System and method for disjunctive joins
US9805121B2 (en) Management of different database systems and/or environments
US9323812B2 (en) Hybrid bifurcation of intersection nodes
CN113268483A (en) Request processing method and device, electronic equipment and storage medium
US9965517B2 (en) Windowless real-time joins
US20180285420A1 (en) Efficient distributed joining of two large data sets

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15877421

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15877421

Country of ref document: EP

Kind code of ref document: A1