CN107735781B - Method and device for storing query result and computing equipment - Google Patents

Method and device for storing query result and computing equipment Download PDF

Info

Publication number
CN107735781B
CN107735781B CN201580001205.4A CN201580001205A CN107735781B CN 107735781 B CN107735781 B CN 107735781B CN 201580001205 A CN201580001205 A CN 201580001205A CN 107735781 B CN107735781 B CN 107735781B
Authority
CN
China
Prior art keywords
query
determining
target
lookup table
lookup
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201580001205.4A
Other languages
Chinese (zh)
Other versions
CN107735781A (en
Inventor
张军
林晓勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Publication of CN107735781A publication Critical patent/CN107735781A/en
Application granted granted Critical
Publication of CN107735781B publication Critical patent/CN107735781B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

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

Abstract

A method and apparatus for storing query results. The method comprises the following steps: determining a plurality of query tables corresponding to a first query request, wherein the first query request is used for requesting to perform association query on the plurality of query tables (S110); determining a target look-up table from the plurality of look-up tables, wherein the target look-up table is a fact table of at least one of the plurality of look-up tables other than the target look-up table, and the fact table of the target look-up table is not present in the plurality of look-up tables (S120); determining a primary 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); the query result is stored to the first table according to the primary key of the first table (S140). The method and the device for storing the query result can avoid the problem of low query efficiency when the first table is subjected to associated query in the prior art, thereby improving the efficiency of the associated query.

Description

Method and device for storing query result and computing equipment
Technical Field
The present invention relates to the field of databases, and more particularly, to a method and apparatus for storing query results, and a computing device.
Background
Transaction Processing Performance Committee (Transaction Processing Performance Council benchmark)TMH, TPC-H) is mainly used to simulate the application environment of real business, including simulating dynamic queries to the real business transaction database as a reference for decision support and database application system.
TPC-H mainly relates to the following concept:
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 measure value column, wherein values in the key value column correspond to dimensions of the fact record, such as commodity origin, commodity price, commodity quantity, transaction date, commodity category, commodity name, and the like; the values in the measure value column correspond to the subject matter of the fact table, such as sales or sales volume, and so on.
The dimension table is used for storing dimension characteristics of the fact records, and the dimension table can comprise a name column and an attribute column, for example, the dimension table of the commodity production area comprises three columns, a production area name (locationName), a production area number (locationId) and an Address (Address), wherein the production area name is the name column, and the production area number and the Address are the attribute columns. The key columns in the fact table may correspond to attribute columns in the dimension table, and each key column in the fact table may correspond to a dimension table.
And the temporary table is used for storing temporary data. The temporary tables can be broadly divided into transaction-level temporary tables, which are automatically deleted after a transaction is committed, and session-level temporary tables, which are deleted after a session is ended.
The primary key uniquely identifies a column in the table, any two rows in one table have different primary key values, and the primary key is not allowed to have a null value. Typically, the primary key of a table is the first column of the table.
A foreign key for linking the two tables, if column M in Table A corresponds to column N in Table B, i.e., column M and column N correspond to the same attribute, e.g., both correspond to an order number, and column M is the primary key in Table A, then 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.
In a database system, when complex queries related to multiple tables are performed, if the data size of the multiple tables is large, one query statement may be decomposed into multiple query sub-statements, and the multiple query sub-statements are distributed to multiple nodes of a cluster through a Massively Parallel Processing (MPP) mechanism. Each node can inquire according to the received inquiry sub-statement and store the inquiry result corresponding to the inquiry sub-statement into a temporary table. After the plurality of nodes complete the query, the query statement may be used to perform an association query on the temporary table obtained by each node to obtain a final query result.
Taking the Q7 query and SQL for TPC-H as an example, if the shipping date is to be queried between 1995 and 1997, and one of the country of the supplier and the country of the customer is france and the other is a transaction record in germany, the query statement as shown in table 1 can be used.
TABLE 1 TPC-H Q7 query statement example
Figure GWB0000003079010000041
Figure GWB0000003079010000051
In the SQL language, "select [ A ] from [ TABLE B ] where [ C ] indicates the data of the column A corresponding to the record satisfying the query condition C is selected from the TABLE B. The above example relates to a complex query, wherein the lookup table related to the sub-queries in the complex query comprises: a supplier (supplier) table, a project (lineitem) table, an orders (orders) table, a customer (customer) table, a country (nation) table named n1, and another country (nation) table named n2. The query result obtained by the sub-query is inserted into a shipping (mapping) table, and then data of columns supp _ nation, cust _ nation and l _ year and data of column revenue obtained by summing the data of column volume are selected from the table mapping.
In order to improve the query efficiency, the query statement corresponding to the complex query may be decomposed into two query sub-statements, where the first query sub-statement is shown in table 2 and is used to perform association query on table orders, table n1, table n2, and table customer, and insert the query result into the temporary table q7_ tmp _ order _ customer; the second query sub-statement is shown in Table 3, and is used to perform associative queries on table lineitem, table n1, table n2, and table supplier, and insert the query results into the temporary table q7_ tmp _ lineitem _ supplier. Finally, the associative query can be performed on the temporary tables q7_ tmp _ order _ customer and q7_ tmp _ lineitem _ supplier through the query statement shown in table 4 to obtain the final query result.
TABLE 2 first query sub-statement
Figure GWB0000003079010000061
TABLE 3 second query sub-statement
Figure GWB0000003079010000062
TABLE 4 query statement for associative querying of two temporary tables
Figure GWB0000003079010000063
Table 5 temporary table q7_ tmp _ lineitem _ supplier example
ID l_orderkey supp_nation cust_nation l_year volume
Wherein "insert _ int [ table A ]" indicates that the query result is inserted into Table A. However, since the primary key of the temporary table is not specified when the temporary table is created, when the query result corresponding to the query sub-statement is stored in the temporary table, the node may actively add a primary key having no practical meaning to the temporary table, for example, as shown in table 5, the node uses the column ID with the row number as the primary key of the temporary table q7_ tmp _ lineitem _ supper, and inserts the query result into the temporary table as the other columns besides the primary key. Thus, when a plurality of temporary tables are subjected to association query, one or more columns in the plurality of temporary tables have repeated values, and each record needs to be filtered in the query process, so that the efficiency of multi-table association query is low. In order to solve the above problem, an index may be created for a column in at least one temporary table, but since the temporary table is only used for the current query, the index is expensive to create, and further, since the data of the temporary table needs to be frequently inserted, the index may be invalid.
Disclosure of Invention
The embodiment of the invention provides a method and a device for storing query results and computing equipment, which can solve the problem of low query efficiency in association query in the prior art.
In a first aspect, a method for storing query results is provided, including: determining a plurality of query tables corresponding to a first query request, wherein the first query request is used for requesting to perform association query on the plurality of query tables; determining a target look-up table from the plurality of look-up tables, wherein a fact table of the target look-up table does not exist in the plurality of look-up tables, and the target look-up table is a fact table of at least one look-up table of the plurality of look-up tables other than the target look-up table; determining a primary 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; and storing the query result to the first table according to the primary key of 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: and storing the query result to the first table in a column cluster mode according to the primary key of the first table.
With reference to the foregoing possible implementation manners, in a second possible implementation manner, the determining a target lookup table from the plurality of lookup tables includes: 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 a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table; determining the association relationship between the first lookup table and the second lookup table corresponding to the at least one first association query condition; and determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table.
With reference to the foregoing possible implementation manners, in a third possible implementation manner, the determining an association relationship between the first lookup table and the second lookup table includes: determining whether a first column of the first lookup table is a primary key of the first lookup table; if the first row of the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table; and if the first row of the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
With reference to the foregoing possible implementation manners, in a fourth possible implementation manner, 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 lookup table is the fact table of the first lookup table, determining that the second lookup table is the target lookup table; if the second determining subunit determines that the first lookup table is the fact table of the second lookup table, it determines that the first lookup table is the target lookup table.
With reference to the foregoing possible implementation manners, in a fifth possible implementation manner, the first query request corresponds to a plurality of first associated query conditions; determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table, including: establishing an association relation tree according to the association relation between the first query table and the second query table, wherein if 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 determining the root node of the incidence relation tree as the target lookup table.
With reference to the foregoing possible implementation manners, in a sixth possible implementation manner, the determining a primary key of the first table according to the target lookup table includes: determining whether non-joint primary keys of the target query table exist in a plurality of columns corresponding to the query result; if the non-associative primary key of the target lookup table exists in the plurality of columns, the non-associative primary key of the target lookup table is determined to be the primary key of the first table.
With reference to the foregoing possible implementation manners, in a seventh possible implementation manner, the determining a primary key of the first table according to the target lookup table further includes: if the non-joint 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, wherein the second query request is used for requesting to perform correlation query on the first table and the second table; determining a primary key of the first table according to the second query request.
With reference to the foregoing possible implementation manners, in an eighth possible implementation manner, the determining a 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 formed by 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 comprising the primary key of the second table; and determining the third column of the first table included in the second target association query condition as the primary key of the first table.
In a second aspect, an apparatus for storing query results is provided, including: the device comprises a first determining unit, a second determining unit and a searching unit, wherein the first determining unit is used for determining a plurality of query tables corresponding to a first query request, and the first query request is used for requesting to perform correlation query on the plurality of query tables; a second determining unit configured to determine a target lookup table from the plurality of lookup tables determined by the first determining unit, wherein a fact table of the target lookup table does not exist in the plurality of lookup tables, and the target lookup table is a fact table of at least one lookup table other than the target lookup table in the plurality of lookup tables; a third determining unit, configured to determine a primary key of a first table according to the target query table determined by the second determining unit, where the first table is used to store a query result corresponding to the first query request; and the storage unit is used for storing the query result to the first table according to the primary key of the first table determined by the third determination unit.
In a first possible implementation manner, the storage unit is specifically configured to: and storing the query result to the first table in a column cluster mode according to the primary key of the first table determined by the third determination unit.
With reference to the foregoing possible implementation manners, in a second possible implementation manner, the second determining unit 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 formed by a first column in a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table; a second determining subunit, configured to determine an association relationship between the first lookup table and the second lookup table corresponding to the at least one first associated query condition determined by the first determining subunit; and a third determining subunit, configured to determine the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table determined by the second determining subunit.
With reference to the foregoing possible implementation manners, in a third possible implementation manner, the second determining subunit is specifically configured to: determining whether a first column in the first lookup table is a primary key of the first lookup table; if the first row in the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table; and if the first row in the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
With reference to the foregoing possible implementation manners, in a fourth possible implementation manner, 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 lookup table is the fact table of the first lookup table, determining that the second lookup table is the target lookup table; if the second determining subunit determines that the first lookup table is the fact table of the second lookup table, it determines that the first lookup table is the target lookup table.
With reference to the foregoing possible implementation manners, in a fifth possible implementation manner, the first query request corresponds to a plurality of first associated query conditions; the third determining subunit is specifically configured to: establishing an association relation tree according to the association relation between the first query table and the second query table determined by the second determining subunit, wherein if the second query table is the fact table of the first query table, the second query table is the parent node of the first query table; and determining the root node of the incidence relation tree as the target lookup table.
With reference to the foregoing possible implementation manners, in a sixth possible implementation manner, the third determining unit includes: a fourth determining subunit, configured to determine whether a non-joint primary key of the target lookup table exists in a plurality of columns corresponding to the query result; a fifth determining subunit, configured to determine, if the fourth determining subunit determines that the non-associative primary key of the target lookup table exists in the plurality of columns, the non-associative primary key of the target lookup table as the primary key of the first table.
With reference to the foregoing possible implementation manners, in a seventh possible implementation manner, the third determining unit further includes: a sixth determining subunit, configured to determine, if the fourth determining subunit determines that the non-joint primary key of the target query table does not exist in the multiple columns, a second query request corresponding to the first query request, where the second query request is used to request for performing association query on the first table and the second table; a seventh determining subunit, configured to determine 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 an eighth possible implementation manner, 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 formed by 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 comprising the primary key of the second table; and determining the third column of the first table included in the second target association query condition as the 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 used for storing computer-executable instructions, the processor is connected with the memory through the bus, and when the computing device runs, the processor reads the computer-executable instructions stored in the memory to execute the method for storing the query result in the first aspect or any possible implementation manner of the first aspect.
Based on the foregoing technical solution, the method, the apparatus, and the computing device for storing query results provided in the embodiments of the present invention determine a target query table from a plurality of query tables corresponding to a first query request, 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 fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table used for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without practical meaning is used as a primary key of the first table in subsequent association query on the first table can be avoided, and efficiency of association query is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments of the present invention or in the description of the prior art will be briefly described below, and it is obvious that the drawings described below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic flow chart diagram of a method for storing query results according to an embodiment of the present invention.
FIG. 2 is another schematic flow chart of a method for storing query results 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 query results 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 query results according to an embodiment of the present invention.
FIG. 5 is a schematic block diagram of an apparatus for storing query results according to an embodiment of the present invention.
FIG. 6 is a schematic block diagram of another apparatus for storing query results 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.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, shall fall within the scope of protection of the present invention.
It should be understood that the technical solution of the embodiment of the present invention may be applied to various Database systems, for example, a Relational Database Management System (RDBMS), a non-Relational Database System (NoSQL), a Massively Parallel Processing Database (MPP-DB), and the like, and the embodiment of the present invention is not limited thereto.
It should be further understood that, in the embodiment of the present invention, a Structured Query Language (SQL) Language is taken as an example for description, but other languages, for example, an object oriented Query Language (HQL), may also be used in the embodiment of the present invention, and the embodiment of the present invention does not limit this.
FIG. 1 is a schematic flow chart diagram of a method 100 of storing query results, which method 100 may be performed by a device storing query results, according to an embodiment of the present invention. Specifically, the apparatus for storing a query result may be specifically a stand-alone device or a module in a device, for example, the apparatus for storing a query result may be a stand-alone node or a cluster node (cluster node), but the embodiment of the present invention is not limited thereto.
S110, determining a plurality of query tables corresponding to a first query request, wherein the first query request is used for requesting to perform correlation query on the plurality of query tables.
The means for storing the query result may receive a first query request from a client, where the first query request from the client may be forwarded to the means for storing the query result through a network device or other device. The first query request may request to perform an association query on the plurality of query tables, for example, a query statement corresponding to the first query request may be as shown in any table of tables 1 to 4. The first query request may be an independent query or a sub-query of a complex query, which is not limited in the embodiment of the present invention.
The device for 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 association 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 a column M in table a and a column N in table B, and the column M and the 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 "where _ supply ═ l _ supply" corresponds to one associated query condition, and the associated query condition is composed of a column supply in table supplier and a column supply in table lineitem, but the embodiment of the present invention is not limited thereto.
And S120, determining a target query table from the plurality of query tables, wherein the target query table is a fact table of at least one query table except the target query table in the plurality of query tables, and the fact table of the target query table does not exist in the plurality of query tables.
The plurality of look-up tables includes the target look-up table. The target look-up table may be a fact table of one or more other tables of the plurality of look-up tables, but a fact table of the plurality of look-up tables that does not include the target look-up table. Specifically, the apparatus for storing a query result may determine the target query table from the plurality of query tables according to a query condition included in the first query request, but the embodiment of the present invention is not limited thereto.
S130, determining a primary 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.
The means for storing the query result may determine to store the query result to the first table in a number of ways. Optionally, the first query request may request to store query results of performing association query on the multiple query tables to a first table, where the first table may be a normal table or a temporary table, and accordingly, the query statement corresponding to the first query request may include an insert inter statement, and the apparatus for storing query results determines the first table according to the first query request. Alternatively, the device for storing query results may actively determine to store the query results corresponding to the first query request to the first table, and in this case, the first table may be a temporary table, 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.
The query result may include data of a plurality of columns corresponding to target records meeting the query condition in the plurality of query tables, where the data of the plurality of columns corresponding to the target records may include data of at least one column in the target records, or include data obtained by performing a mathematical operation on the data of at least one column in the target records, where the data may be an index value or a character string, which is not limited in this embodiment of the present invention.
Therefore, according to the method for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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, the fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as the primary key of the first table in a subsequent association query on the first table can be avoided, and efficiency of the association query is improved.
In an embodiment of the present invention, the plurality of columns corresponding to the query result may include the primary key of the first table, and accordingly, in S140, the apparatus for storing the query result may insert other columns of the plurality of columns corresponding to the query result except for the primary key of the first table into the first table in a non-primary key manner. Optionally, if there is a duplicate value in the primary key of the first table corresponding to the query result, the apparatus for storing the query result may store a plurality of columns corresponding to the query result in a Column cluster (Column Family) manner, so that there is no duplicate value in the primary key of the first table, but the embodiment of the present invention is not limited thereto.
Optionally, S140, storing the query result to the first table according to the primary key of the first table, includes:
and storing the query result to the first table in a column cluster mode according to the primary key of the first table.
For example, the temporary table q7_ tmp _ order _ customer obtained from 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 _ suplier obtained from the second query sub-statement shown in Table 3 may be stored in the form of a column cluster shown in Table 7.
Table 6 temporary table q7_ tmp _ order _ customer stored in the form of a column cluster
Figure GWB0000003079010000131
Figure GWB0000003079010000141
Table 7 temporary table q7_ tmp _ lineitem _ supplier stored in the form of a column cluster
Figure GWB0000003079010000142
Alternatively, as another embodiment, before inserting and storing the query result into the first table, the means for 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 create the first table, and then insert the query result into the first table and store the first table. The apparatus for storing the query result may directly insert the query result into the first table if the first table already exists, or may first delete the first table and rebuild the first table, and then insert the query result into the newly built first table and store the first table, but the embodiment of the present invention is not limited thereto.
In S120, the means for storing the query result may determine the target look-up table from the plurality of look-up tables in a variety of ways. As an alternative embodiment, the means for storing the query result may determine the target query table from the plurality of query tables according to at least one first associated query condition corresponding to the first query request.
Optionally, as shown in fig. 2, S120, determining a target lookup table from the plurality of lookup tables includes:
s121, 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 a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table;
s122, determining the association relation between the first lookup table and the second lookup table corresponding to the first association lookup condition;
s123, 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.
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 equal signs. Taking the second query sub-statement shown in table 3 as an example, the query sub-statement includes two associated query conditions, that is, an associated query condition "l _ response ═ s _ response" composed of a column response of the table lineitem and a column response of the table sublist, and an associated query condition "s _ response ═ n _ response" composed of a column response of the table sublist and a column response of the table n1. The means for storing the query results may determine the target query table from the tables lineitem, table supplier, and table n1.
Optionally, as another embodiment, the step S122 of determining an association relationship between the first lookup table and the second lookup table includes:
determining whether a first column of the first lookup table is a primary key of the first lookup table;
if the first row of the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table;
and if the first row of the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
If the means for storing the query result determines that the first column is the primary key of the first lookup table, it indicates that the second column is the foreign key of the second lookup table, and at this time, the means for storing the query result may determine that the first lookup table is the dimension table of the second lookup table, and the second lookup table is the fact table of the first lookup table. Alternatively, if the means for storing the query result determines that the first column is the foreign key of the first lookup table, indicating that the second column is the primary key of the second lookup table, at this time, the means for storing the query result may determine that the first lookup table is the fact table of the second lookup table, and the second lookup table is the dimension table of the first lookup table.
Or, the means for storing the query result may also determine whether the second column is the primary key of the second lookup table, and 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 the fact table of the second lookup table; and if the second column is the foreign key of the second lookup table, the device for storing the query result may determine that the second lookup table is the 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 embodiments of the present invention, unless explicitly stated or directly seen from the context, the term "primary key" may refer to a column that can uniquely identify a row, i.e., a non-associated primary key, in which case the primary key corresponds to a column, or may refer to a plurality of columns that can uniquely identify a row, or a column that can uniquely identify a row together with other columns, i.e., an associated primary key or an associated primary key, in which case the primary key corresponds to one of a plurality of columns or a plurality of columns, which is not limited in the embodiments of the present invention.
If the first query request corresponds to a first associated query condition and the means for storing query results determines that the second query table is the fact table of the first query table, the means for storing query results may determine that the second query table is the target query table. If the first query request corresponds to a plurality of first associated query conditions, the apparatus for storing query results may determine an association relationship between two query tables in each of the first associated query conditions, and determine the target query table according to the association relationship between two query tables in each of the plurality of first associated query conditions. Still taking the second query sub-statement as shown in FIG. 3 as an example, the means for storing the query result may determine the association between the table lineitem and the table suplier and the association between the table suplier and the table n1. A typical form of the table lineitem may be as shown in table 8, where orderkey and lineumber are used as joint primary keys of the table lineitem, and a value of orderkey and a value of lineumber can jointly identify a row in the table. A typical form of a table suplier may be as shown in Table 9, where a suplier is a non-associative primary key of a table suplier, and is capable of identifying a row in a table individually. An exemplary form of a table designation of table n1 may be as shown in table 10, where the nationkey is the primary key of table n1. At this time, as can be seen from tables 8 and 9, if the support is the foreign key of table lineitem and the primary key of table suppier, table lineitem is the fact table of table suppier; as can be seen from tables 9 and 10, if the nationkey is the foreign key of Table suplier and is the primary key of Table n1, Table suplier is the fact table of Table n1. Among the three lookup tables of tables lineitem, supperer and n1, table lineitem is a fact table of table supperer, and no fact table of table lineitem exists in tables lineitem, supperer and n1, and thus the apparatus for storing the result of the query can determine table lineitem as the target lookup table.
FIG. 8 Table lineeim example
Figure GWB0000003079010000161
FIG. 9 Table supplier example
Figure GWB0000003079010000171
FIG. 10 exemplary Listation
Figure GWB0000003079010000172
Optionally, as another embodiment, the first query request corresponds to a first associated query condition;
correspondingly, S123, determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table, includes:
if the second lookup table is the fact table of the first lookup table, determining the second lookup table as the target lookup table;
and if the first lookup table is the fact table of the second lookup table, determining the first lookup table as the target lookup table.
Optionally, as another embodiment, if the first query request corresponds to a plurality of first associated query conditions, 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 includes:
establishing an association relation tree according to the association relation between the first query table and the second query table, wherein if 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 determining the root node of the incidence relation tree as the target lookup table.
When the incidence relation tree is established, the device for storing the query result can take the fact table as a parent node of the dimension table, and one node can have a plurality of child nodes. At this time, since the association tree does not have a parent node of the root node, that is, a fact table of the root node is not included in the association tree, and a child node of the root node, that is, a dimension table of the root node, exists in the association tree, the apparatus for storing a query result may determine the root node of the association tree as the target query table. Still taking the second query sub-statement shown in table 3 as an example, according to the fact table that the table lineitem is the table superlier and the fact table that the table superlier is the table n1, the apparatus for storing a query result may establish an association tree as shown in fig. 3, where the item (lineitem) table is a root node of the association tree, and therefore, the apparatus for storing a query result may determine that the table lineitem is the target query table corresponding to the second query sub-statement. Similarly, the association relation tree shown in fig. 4 may be established according to the first query sub-statement shown in table 2, where a root node of the association relation tree is an order (orders) table, and thus the apparatus for storing a query result may determine that the order table is a target query table corresponding to the first query sub-statement shown in table 2, but the embodiment of the present invention is not limited thereto.
Optionally, as another embodiment, the step S130 of determining the primary key of the first table according to the target lookup table includes:
determining whether non-joint primary keys of the target query table exist in a plurality of columns corresponding to the query result;
if the non-associative primary key of the target lookup table exists in the plurality of columns, the non-associative primary key of the target lookup table is determined to be the primary key of the first table.
Specifically, the means for storing the query result may determine whether the primary key of the target query table is a joint primary key or a non-joint primary key, and if the primary key of the target query table is the joint primary key, the means for storing the query result may determine that the non-joint primary key of the target query table does not exist in a plurality of columns corresponding to the query result. Taking the second query sub-statement shown in table 3 as an example, the target query table corresponding to the second query sub-statement is table lineitem, and the primary key of table lineitem is a joint primary key composed of orderkey and lineumber, the apparatus for storing a query result may determine that the columns corresponding to the query result do not include the non-joint primary key of table orders, but the embodiment of the present invention is not limited thereto.
Optionally, if the primary key of the target lookup table is a non-associative primary key, the apparatus for storing the query result may further determine whether the non-associative primary key of the target lookup table exists in a plurality of columns corresponding to the query result. Taking the first query sub-statement shown in table 2 as an example, the target query table corresponding to the first query sub-statement is table orders, and the primary key of the table orders is an order, the device for storing the query result may determine whether the primary key of the table orders is included in the columns o _ order, n1.n _ name, and n2.n _ name corresponding to the first query sub-statement. Since the plurality of columns include o _ orderkeys, the apparatus for storing query results may use o _ orderkeys as the primary key of the temporary table q7_ tmp _ order _ customer, but the embodiments of the present invention are not limited thereto.
Optionally, as another embodiment, the step S130 of determining the primary key of the first table according to the target lookup table further includes:
if the non-joint primary key of the target query table does not exist in the plurality of columns corresponding to the query result, determining a second query request corresponding to the first query request, wherein the second query request is used for requesting to perform correlation query on the first table and the second table;
determining a primary key of the first table according to the second query request.
If the non-union primary key of the target query table does not exist, that is, the primary key of the target query table is specifically the union primary key, or if the primary key of the target query table is the non-union primary key but the non-union primary key of the target query table is not included in the plurality of columns corresponding to the query result, the non-union primary key of the target query table does not exist in the plurality of columns corresponding to the query result. At this time, the apparatus for storing a query result may determine whether there is a second query request corresponding to the first query request, and if there is no second query request corresponding to the first query request, the apparatus for storing a query result may take a column having no practical meaning as the primary key of the first table. The means for storing query results may determine the primary key of the first table from a second query request corresponding to the first query request if the second query request exists. Specifically, the second query request is used to perform an association query on the first table and a second table, for example, the first table is a temporary table q7_ tmp _ lineitem _ suplier, and the query statement shown in table 4 is used to perform an association query on the temporary table q7_ tmp _ order _ client and q7_ tmp _ lineitem _ suplier, so that the query statement shown in table 4 may serve as the second query request corresponding to the first query request shown in table 3. At this time, the apparatus for 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 from the second query request in a number of ways. As an alternative embodiment, the 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 formed by 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 comprising the primary key of the second table;
and determining the third column of the first table included in the second target association query condition 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 means for storing the query result may determine a second target associated query condition from at least one second associated query condition corresponding to the second query request, where the second target associated query condition is composed of the third column of the first table and the fourth column of the second table, and the fourth column is a primary key of the second table. The apparatus for storing query results may determine the third column of the first table in the second target associated 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 specifically be for requesting an association query for the first table and the at least one second table. Optionally, as another embodiment, if the number of the second tables is multiple, before the apparatus for storing a query result determines the second target associated query condition, the apparatus for storing a query result may determine a second target table from the multiple second tables, where the second target table is a fact table of at least one table of the multiple second tables, and the fact table of the second target table does not exist in the multiple second tables. At this time, the apparatus for storing a query result may determine the second target query condition from at least one second associated query condition corresponding to the second query request, where the second target query condition is composed of the primary key of the second target table and a third column of the first table, and the apparatus for storing a query result may use the third column of the first table in the second target query condition as the primary key of the first table, but the embodiment of the present invention is not limited thereto.
Still taking the second query sub-statement shown in table 3 as an example, the query statement shown in table 4 is a second query request corresponding to the second query sub-statement, and the second query request is used for performing association query on the first table (provisional table q7_ tmp _ lineitem _ supplier, named table n2) and a second table (provisional table q7_ tmp _ order _ customer, named table n 1). At this time, the query statement shown in table 4 includes three second associated query conditions, "n 2.l _ order ═ n1.o _ order," "n 1. cut _ order ═ n2. cut _ order," and "n 1.Supp _ order ═ n2.Supp _ order," where a second target associated query condition among the three second associated query conditions is "n 2.l _ order ═ n1.o _ order," and the target associated query condition is composed of the primary key o _ order of table n1 and the column l _ order of table n2, and the device for storing a query result may use the l _ order as the primary key of the temporary table q7_ tmp _ lineitem _ holder. At this time, the primary key l _ order of the temporary table q7_ tmp _ lineeim _ supplyer corresponds to the primary key o _ order of the temporary table q7_ tmp _ order _ customer, and there is no duplicate data in both, and at this time, when the association query shown in table 4 is performed, the query can be directly performed without establishing an index, so that the query efficiency and speed are improved.
Therefore, according to the method for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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, the fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as the primary key of the first table in a subsequent association query on the first table can be avoided, and efficiency of the association query is improved.
It should be noted that the examples of tables 1 to 4 are for helping 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 apparent to those skilled in the art that various equivalent modifications or variations are possible in light of the examples given in tables 1 to 4, and such modifications or variations are also within the scope of the embodiments of the present invention.
It should also be understood that the sequence numbers of the above-mentioned processes do not mean the execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
It should also be understood that the terms "first", "second" and "third" in the embodiments of the present invention are only used for distinguishing different contents, and should not be construed as limiting the embodiments of the present invention in any way. The first table and the second table in the embodiment of the present invention are only for distinguishing different tables, the first column in the first lookup table, the second column in the second lookup table are only for distinguishing a lookup column belonging to the first lookup table and a lookup column belonging to the second lookup table in the associated lookup condition, and similarly, the third column in the first table and the fourth column in the second table are also only for distinguishing different columns, and the specific positions of the columns in the tables should not be limited.
The method for storing query results according to the embodiment of the present invention is described in detail above with reference to fig. 1 to 4, and the apparatus for storing query results according to the embodiment of the present invention is described below with reference to fig. 5 to 7.
FIG. 5 schematically shows an apparatus 200 for storing query results according to an embodiment of the present invention. As shown in fig. 5, the apparatus 200 includes:
a first determining unit 210, configured to determine a plurality of lookup tables corresponding to a first query request, where the first query request is used to request to perform association query on the plurality of lookup tables;
a second determining unit 220, configured to determine a target lookup table from the plurality of lookup tables determined by the first determining unit 210, where a fact table of the target lookup table does not exist in the plurality of lookup tables, and the target lookup table is a fact table of at least one lookup table other than the target lookup table in the plurality of lookup tables;
a third determining unit 230, configured to determine a primary key of a first table according to the target query table determined by the second determining unit 220, where the first table is used to store a query result corresponding to the first query request;
a storage unit 240, configured to store the query result in the first table according to the primary key of the first table determined by the third determining unit 230.
Therefore, according to the apparatus for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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 fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table used for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as a primary key of the first table in a subsequent association query on the first table can be avoided, thereby improving efficiency of the association query.
Optionally, as another embodiment, the apparatus 200 may further include:
a receiving unit, configured to receive a first query request from a client before the first determining unit 210 determines a plurality of lookup tables corresponding to the first query request;
and the query unit is used for carrying out association query on the plurality of query tables according to the first query request received by the receiving unit.
At this time, the storage unit 240 is specifically configured to store the query result obtained by the query unit in the first table.
Optionally, the storage unit 240 is specifically configured to: the query result is stored 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.
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 formed by a first column in a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table;
a second determining subunit, configured to determine an association relationship between the first lookup table and the second lookup table corresponding to the first association lookup condition determined by the first determining subunit;
and a third determining subunit, configured to determine the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table determined by the second determining subunit.
Optionally, as another embodiment, the second determining subunit is specifically configured to:
determining whether a first column of the first lookup table is a primary key of the first lookup table;
if the first row of the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table;
and if the first row of the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
Optionally, as 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 lookup table is the fact table of the first lookup table, determining that the second lookup table is the target lookup table;
if the second determining subunit determines that the first lookup table is the fact table of the second lookup table, it determines that the first lookup table is the target lookup table.
Optionally, as another embodiment, the first query request corresponds to a plurality of first associated query conditions, and at this time, the third determining subunit is specifically configured to:
establishing an association relation tree according to the association relation between the first query table and the second query table determined by the second determining subunit, wherein if the second query table is the fact table of the first query table, the second query table is the parent node of the first query table;
and determining the root node of the incidence relation tree as the target lookup table.
Optionally, as another embodiment, the third determining unit 230 includes:
a fourth determining subunit, configured to determine whether a non-joint primary key of the target lookup table exists in a plurality of columns corresponding to the query result;
a fifth determining subunit, configured to determine, if the fourth determining subunit determines that the non-associative primary key of the target lookup table exists in the plurality of columns, the non-associative primary key of the target lookup table as the primary key of the first table.
Optionally, as another embodiment, the third determining unit further includes:
a sixth determining subunit, configured to determine, if the fourth determining subunit determines that the non-joint primary key of the target query table does not exist in the multiple columns, a second query request corresponding to the first query request, where the second query request is used to request for performing association query on the first table and the second table;
a seventh determining subunit, configured to determine the primary key of the first table according to the second query request determined by the sixth determining subunit.
Optionally, as 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 formed by 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 comprising the primary key of the second table;
and determining the third column of the first table included in the second target association query condition as the primary key of the first table.
The apparatus 200 for storing a query result according to an embodiment of the present invention may correspond to an execution subject of the method 100 for storing a query result according to an embodiment of the present invention, and the above and other operations and/or functions of each module in the apparatus 200 for storing a query result are respectively for implementing corresponding flows of each method in fig. 1 to fig. 4, and are not described herein again for brevity.
Therefore, according to the apparatus for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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 fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table used for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as a primary key of the first table in a subsequent association query on the first table can be avoided, thereby improving efficiency of the association query.
FIG. 6 schematically shows another apparatus 300 for storing query results according to an embodiment of the present invention. As shown in fig. 6, the apparatus 300 includes:
a processor 310 configured to: determining a plurality of query tables corresponding to a first query request, wherein the first query request is used for requesting to perform association query on the plurality of query tables; determining a target look-up table from the plurality of look-up tables, wherein a fact table of the target look-up table does not exist in the plurality of look-up tables, and the target look-up table is a fact table of at least one look-up table of the plurality of look-up tables other than the target look-up table; determining a primary 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;
a memory 320 for storing the query result to the first table according to the primary key of the first table determined by the processor 310.
Therefore, according to the apparatus for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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 fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table used for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as a primary key of the first table in a subsequent association query on the first table can be avoided, thereby improving efficiency of the association query.
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), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 320 may include both read-only memory and random access memory and provides instructions and data to the processor 310. A portion of memory 320 may also include non-volatile random access memory. For example, the memory 320 may also store device type information.
In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 310. The steps of a method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 320, and the processor 310 reads the information in the memory 320 and completes the steps of the method in combination with the hardware. To avoid repetition, it is not described in detail here.
Optionally, as another embodiment, the apparatus 200 may further include:
a receiver, configured to receive a first query request from a client before the processor 310 determines a plurality of lookup tables corresponding to the first query request;
accordingly, the processor 310 is further configured to perform an association query on the plurality of query tables according to the first query request received by the receiver.
At this time, the memory 320 is specifically configured to store the query result obtained by the processor 310 to the first table.
Optionally, the memory 320 is specifically configured to: the query result is stored to the first table in a manner of a column cluster according to the primary key of the first table determined by the processor 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 a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table;
determining the association relationship between the first lookup table and the second lookup table corresponding to the first association query condition;
and determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table.
Optionally, as another embodiment, the processor 310 is specifically configured to:
determining whether a first column of the first lookup table is a primary key of the first lookup table;
if the first row of the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table;
and if the first row of the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
Optionally, as another embodiment, the first query request corresponds to a first associated query condition;
accordingly, the processor 310 is specifically configured to:
if the second lookup table is determined to be the fact table of the first lookup table, determining the second lookup table to be the target lookup table;
and if the first lookup table is determined to be the fact table of the second lookup table, determining the first lookup table to be the target lookup table.
Optionally, as another embodiment, the first query request corresponds to a plurality of first associated query conditions, at this time, the processor 310 is specifically configured to:
establishing an association relation tree according to the association relation between the first query table and the second query table, wherein if 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 determining the root node of the incidence relation tree as the target lookup table.
Optionally, as another embodiment, the processor 310 is further configured to:
determining whether non-joint primary keys of the target query table exist in a plurality of columns corresponding to the query result;
if the non-joint primary key of the target query table exists in the plurality of columns, the non-joint primary key of the target query table is determined as the primary key of the first table.
Optionally, as another embodiment, the processor 310 is further configured to:
if it is determined that the non-joint 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, wherein the second query request is used for requesting to perform association query on the first table and the second table;
determining a primary key of the first table according to the second query request.
Optionally, as 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 formed by 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 comprising the primary key of the second table;
and determining the third column of the first table included in the second target association query condition as the primary key of the first table.
The apparatus 300 for storing query results according to the embodiment of the present invention may correspond to the execution body of the method 100 for storing query results according to the embodiment of the present invention, and the above and other operations and/or functions of each module in the apparatus 300 for storing query results are respectively for implementing corresponding processes of each method in fig. 1 to fig. 4, and are not described herein again for brevity.
Therefore, according to the apparatus for storing query results in the embodiment of the present invention, a target query table is determined from a plurality of query tables corresponding to a first query request, 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 fact table of the target query table does not exist in the plurality of query tables, and a primary key of a first table used for storing query results is determined according to the target query table, so that a problem in the prior art that query efficiency is low when a column without actual meaning is used as a primary key of the first table in a subsequent association query on the first table can be avoided, thereby improving efficiency of the association query.
FIG. 7 schematically shows a computing device 400 according to an embodiment of the invention. As shown in fig. 7, the computing device 400 includes: a processor 402, a memory 404, and a bus 410. Wherein the processor 402 and the memory 404 are communicatively coupled to each other via a bus 410.
The processor 402 may be a general-purpose Central Processing Unit (CPU), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided by the embodiments of the present invention.
The Memory 404 may be a Read Only Memory (ROM), a static Memory device, a dynamic Memory device, or a Random Access Memory (RAM). The memory 404 may store an operating system and other application programs. When the technical solution provided by the embodiment of the present invention is implemented by software or firmware, a 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.
In particular, the memory 404 may be used to store executable instructions and may also be used to store various information, such as query results. The processor 402 may read information stored by the memory 404 through the bus system 410 or store query results to the memory 404. Further, when the computing device 400 is running, the processor 402 may execute executable instructions stored by the memory 404 to determine a plurality of lookup tables corresponding to a first query request, wherein the first query request requests an associated query to be performed on the plurality of lookup tables; determining a target look-up table from the plurality of look-up tables, wherein a fact table of the target look-up table does not exist in the plurality of look-up tables, and the target look-up table is a fact table of at least one look-up table of the plurality of look-up tables other than the target look-up table; determining a primary 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; and storing the query result to the first table according to the primary key of the first table.
Optionally, as shown in FIG. 7, the computing device may also include input/output interfaces 406 and a communication interface 408. The input/output interface 406 is used 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 transceiver means, such as, but not limited to, transceivers.
Bus 410 may include a pathway to transfer information between components of computing device 400, such as processor 402, memory 404, input/output interfaces 406, and communication interfaces 408.
The hardware structure shown in fig. 7 and the above description are suitable for executing various methods for storing query results provided by the embodiments of the present invention, for example, various method flows shown in fig. 1 to fig. 4, and are not repeated here for brevity.
It should be noted that although the computing device 400 shown in fig. 7 shows only a processor 402, a memory 404, an input/output interface 406, a communication interface 408, and a bus 410, in particular implementations, those skilled in the art will appreciate that the computing device 400 also contains other components necessary to achieve proper operation. Also, those skilled in the art will appreciate that the computing device 400 may also contain hardware components to implement other additional functionality, according to particular needs. Moreover, those skilled in the art will appreciate that computing device 400 may also contain only those elements necessary to implement embodiments of the present invention, and need not contain all of the elements shown in FIG. 7.
It should be understood that in the embodiment of the present invention, the term and/or is only one kind of association relation describing the associated object, which means that there may be three kinds of relations. For example, a and/or B, may represent: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character/generally means that the pre-association object and the post-association object are in one or the same relationship.
Those of ordinary skill in the art will appreciate that the various method steps and elements described in connection with the embodiments disclosed herein can be implemented as electronic hardware, computer software, or combinations of both, and that the steps and elements of the various embodiments have been described above generally in terms of their functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a 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 stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (19)

1. A method of storing query results, comprising:
determining a plurality of query tables corresponding to a first query request, wherein the first query request is used for requesting to perform association query on the plurality of query tables;
determining a target lookup table from the plurality of lookup tables, wherein a fact table of the target lookup table does not exist in the plurality of lookup tables, and the target lookup table is a fact table of at least one lookup table of the plurality of lookup tables other than the target lookup table;
determining a primary 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;
and storing the query result to the first table according to the primary key of the first table.
2. The method of claim 1, wherein storing the query result to the first table according to the primary key of the first table comprises:
and storing the query result to the first table in a column cluster mode according to the primary key of the first table.
3. The method of claim 1, wherein determining the target look-up table from the plurality of look-up tables comprises:
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 a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table;
determining an association relation between the first lookup table and the second lookup table corresponding to the at least one association query condition;
and determining the target query table from the first query table and the second query table according to the incidence relation between the first query table and the second query table.
4. The method according to claim 3, wherein the determining the association relationship between the first lookup table and the second lookup table corresponding to the at least one associated query condition comprises:
determining whether a first column in the first lookup table is a primary key of the first lookup table;
if the first column in the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table;
and if the first column in the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
5. The method of claim 4, wherein the first query request corresponds to a first associated query condition;
determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table, including:
if the second lookup table is the fact table of the first lookup table, determining that the second lookup table is the target lookup table;
and if the first lookup table is the fact table of the second lookup table, determining that the first lookup table is the target lookup table.
6. The method according to claim 3 or 4, wherein the first query request corresponds to a plurality of first associated query conditions;
determining the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table, including:
establishing an association relation tree according to the association relation between the first query table and the second query table, wherein if the second query table is a fact table of the first query table, the second query table is a father node of the first query table;
and determining the root node of the incidence relation tree as the target query table.
7. The method of any of claims 1 to 5, wherein determining the primary key of the first table from the target look-up table comprises:
determining whether a non-joint primary key of the target query table exists in a plurality of columns corresponding to the query result;
and if the non-joint primary key of the target query table exists in the plurality of columns, determining the non-joint primary key of the target query table as the primary key of the first table.
8. The method of claim 7, wherein determining the primary key of the first table from the target look-up table further comprises:
if the non-joint 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, wherein the second query request is used for requesting to perform correlation query on the first table and the second table;
and determining the primary key of the first table according to the second query request.
9. The method of claim 8, wherein 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 a second target associated query condition from the at least one second associated query condition, the second target associated query condition comprising a primary key of the second table;
determining a third column of the first table included in the second target associated query condition as a primary key of the first table.
10. An apparatus for storing query results, comprising:
the device comprises a first determining unit, a second determining unit and a searching unit, wherein the first determining unit is used for determining a plurality of query tables corresponding to a first query request, and the first query request is used for requesting to perform correlation query on the plurality of query tables;
a second determining unit configured to determine a target lookup table from the plurality of lookup tables determined by the first determining unit, wherein a fact table of the target lookup table does not exist in the plurality of lookup tables, and the target lookup table is a fact table of at least one lookup table of the plurality of lookup tables except the target lookup table;
a third determining unit, configured to determine a primary key of a first table according to the target query table determined by the second determining unit, where the first table is used to store a query result corresponding to the first query request;
and the storage unit is used for storing the query result to the first table according to the primary key of the first table determined by the third determination unit.
11. The apparatus according to claim 10, wherein the storage unit is specifically configured to:
and storing the query result to the first table in a column cluster mode according to the primary key of the first table determined by the third determination unit.
12. The apparatus according to claim 10, wherein the second determining unit comprises:
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 formed by a first column in a first query table and a second column in a second query table, and the plurality of query tables include the first query table and the second query table different from the first query table;
a second determining subunit, configured to determine an association relationship between the first lookup table and the second lookup table corresponding to the at least one associated query condition determined by the first determining subunit;
a third determining subunit, configured to determine the target lookup table from the first lookup table and the second lookup table according to the association relationship between the first lookup table and the second lookup table determined by the second determining subunit.
13. The apparatus according to claim 12, wherein the second determining subunit is specifically configured to:
determining whether a first column in the first lookup table is a primary key of the first lookup table;
if the first column in the first lookup table is the primary key of the first lookup table, determining that the second lookup table is the fact table of the first lookup table;
and if the first column in the first lookup table is the foreign key of the first lookup table, determining that the first lookup table is the fact table of the second lookup table.
14. The apparatus according to claim 13, wherein the first query request corresponds to a first association query condition;
the third determining subunit is specifically configured to:
if the second determining subunit determines that the second lookup table is the fact table of the first lookup table, determining that the second lookup table is the target lookup table;
if the second determining subunit determines that the first lookup table is the fact table of the second lookup table, it determines that the first lookup table is the target lookup table.
15. 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 relation tree according to the association relation between the first query table and the second query table determined by the second determining subunit, wherein if 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 determining the root node of the incidence relation tree as the target query table.
16. The apparatus according to any one of claims 10 to 14, wherein the third determining unit comprises:
a fourth determining subunit, configured to determine whether a non-joint primary key of the target lookup table exists in a plurality of columns corresponding to the query result;
a fifth determining subunit, configured to determine, if the fourth determining subunit determines that the non-joint primary key of the target lookup table exists in the plurality of columns, the non-joint primary key of the target lookup table as the primary key of the first table.
17. The apparatus of claim 16, wherein the third determining unit further comprises:
a sixth determining subunit, configured to determine, if the fourth determining subunit determines that the non-joint primary key of the target query table does not exist in the multiple columns, a second query request corresponding to the first query request, where the second query request is used to request to perform association query on the first table and the second table;
a seventh determining subunit, configured to determine, according to the second query request determined by the sixth determining subunit, a primary key of the first table.
18. 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 a second target associated query condition from the at least one second associated query condition, the second target associated query condition comprising a primary key of the second table;
determining a third column of the first table included in the second target associated query condition as a primary key of the first table.
19. A computing device, comprising: a processor, a memory, and a bus;
the memory is used for storing computer-executable instructions, the processor is connected with the memory through the bus, and when the computing device runs, the processor reads the computer-executable instructions stored in the memory to execute the method of any one of claims 1 to 9.
CN201580001205.4A 2015-01-14 2015-01-14 Method and device for storing query result and computing equipment Active CN107735781B (en)

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 (2)

Publication Number Publication Date
CN107735781A CN107735781A (en) 2018-02-23
CN107735781B true CN107735781B (en) 2020-03-10

Family

ID=56405107

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201580001205.4A Active CN107735781B (en) 2015-01-14 2015-01-14 Method and device for storing query result and computing equipment

Country Status (2)

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

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110597849B (en) * 2018-05-25 2022-03-22 北京国双科技有限公司 Data query method and device
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
CN112699149B (en) * 2020-12-31 2023-09-19 青岛海尔科技有限公司 Target data acquisition method and device, storage medium and electronic device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101197876A (en) * 2006-12-06 2008-06-11 中兴通讯股份有限公司 Method and system for multi-dimensional analysis of message service data
CN101916261A (en) * 2010-07-28 2010-12-15 北京播思软件技术有限公司 Data partitioning method for distributed parallel database system
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
CN104166740A (en) * 2014-09-10 2014-11-26 税友软件集团股份有限公司 Data inquiry method and device

Family Cites Families (4)

* 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
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
US8078570B2 (en) * 2009-05-01 2011-12-13 International Business Machines Corporation Versioning data warehouses
US8285709B2 (en) * 2009-05-12 2012-10-09 Teradata Us, Inc. High-concurrency query operator and method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101197876A (en) * 2006-12-06 2008-06-11 中兴通讯股份有限公司 Method and system for multi-dimensional analysis of message service data
CN101916261A (en) * 2010-07-28 2010-12-15 北京播思软件技术有限公司 Data partitioning method for distributed parallel database system
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
CN104166740A (en) * 2014-09-10 2014-11-26 税友软件集团股份有限公司 Data inquiry method and device

Also Published As

Publication number Publication date
CN107735781A (en) 2018-02-23
WO2016112502A1 (en) 2016-07-21

Similar Documents

Publication Publication Date Title
CN110633292B (en) Query method, device, medium, equipment and system for heterogeneous database
US9990362B2 (en) Profiling data with location information
US10585913B2 (en) Apparatus and method for distributed query processing utilizing dynamically generated in-memory term maps
US10558659B2 (en) Techniques for dictionary based join and aggregation
US9600507B2 (en) Index structure for a relational database table
US9754010B2 (en) Generation of cube metadata and query statement based on an enhanced star schema
WO2021068549A1 (en) Data processing method, platform and system
CN107735781B (en) Method and device for storing query result and computing equipment
CN108875042B (en) Hybrid online analysis processing system and data query method
CN112115152B (en) Data increment updating and inquiring method and device, electronic equipment and storage medium
WO2016134580A1 (en) Data query method and apparatus
TW202011224A (en) Data inquiry method, device, electronic device and computer-readable storage medium
US7707144B2 (en) Optimization for aggregate navigation for distinct count metrics
CN108874873B (en) Data query method, device, storage medium and processor
CN113918605A (en) Data query method, device, equipment and computer storage medium
CN108959381B (en) Data management method and device and electronic equipment
CN110147396B (en) Mapping relation generation method and device
US11347794B2 (en) Non-unique secondary indexing of semi-structured data in databases
US11423098B2 (en) Method and apparatus to generate a simplified query when searching for catalog items
JP2001216307A (en) Relational database management system and storage medium stored with same
CN112069164B (en) Data query method, device, electronic equipment and computer readable storage medium
CN115617773A (en) Data migration method, device and system
CN112632115A (en) BI-based data query method and system
CN117632947A (en) Storing and querying knowledge maps in column store
CN117931797A (en) Double-row index data table generation method, device, computing equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant