CN109656946B - Multi-table association query method, device and equipment - Google Patents

Multi-table association query method, device and equipment Download PDF

Info

Publication number
CN109656946B
CN109656946B CN201811144099.7A CN201811144099A CN109656946B CN 109656946 B CN109656946 B CN 109656946B CN 201811144099 A CN201811144099 A CN 201811144099A CN 109656946 B CN109656946 B CN 109656946B
Authority
CN
China
Prior art keywords
query
statement
cost
result set
query statement
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
CN201811144099.7A
Other languages
Chinese (zh)
Other versions
CN109656946A (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.)
Advanced New Technologies Co Ltd
Advantageous New Technologies Co Ltd
Original Assignee
Advanced New 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 Advanced New Technologies Co Ltd filed Critical Advanced New Technologies Co Ltd
Priority to CN201811144099.7A priority Critical patent/CN109656946B/en
Publication of CN109656946A publication Critical patent/CN109656946A/en
Application granted granted Critical
Publication of CN109656946B publication Critical patent/CN109656946B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the specification discloses a multi-table association query method, a multi-table association query device and multi-table association query equipment. The scheme comprises the following steps: acquiring a first query statement; acquiring a second query statement; the query conditions in the first query statement and the second query statement have the same fields; estimating a first query cost of the first query statement; estimating a second query cost for the second query statement; determining a minimum query cost; inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set; rewriting additional query statements according to the first query result set; inquiring according to the rewritten inquiry statement to obtain a second inquiry result set; and obtaining an associated query result set according to the first query result set and the second query result set.

Description

Multi-table association query method, device and equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, and a device for multi-table association query.
Background
In the prior art, the data of the user is stored in a database in a multi-table manner. In order to query certain behaviors of a user, a multi-table association query needs to be performed. A multi-table associative query, generally refers to querying records from multiple data tables that have some common attributes.
For example, assume three data tables, table A, table B, and Table C. The user number and the user name are stored in the table a, the user number and the user age are stored in the table B, and the user number and the user gender are stored in the table C. Each user has a unique number. Then, if a male with the name of "zhang san" and the age of 20 is to be queried, a multi-table association query needs to be performed according to the three tables to obtain a query result.
However, in the conventional multi-table association query method, query results of each data table related to a multi-table association query script are generally obtained in a memory of a query initiating device, and then the query results of each data table are filtered. The method carries out multi-table query and has low efficiency.
Disclosure of Invention
In view of this, embodiments of the present application provide a method, an apparatus, and a device for multi-table association query, which are used to improve query efficiency.
In order to solve the above technical problem, the embodiments of the present specification are implemented as follows:
the multi-table association query method provided by the embodiment of the specification comprises the following steps:
obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
estimating a first query cost of the first query statement;
estimating a second query cost for the second query statement;
comparing the first query cost with the second query cost to determine a minimum query cost;
inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
rewriting additional query statements according to the first query result set;
inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
and obtaining an associated query result set according to the first query result set and the second query result set.
An embodiment of the present specification provides a multi-table association query apparatus, including:
the first query statement acquisition module is used for acquiring a first query statement aiming at a first table; the first query statement is obtained by analyzing a multi-table association query script;
a second query statement acquisition module, configured to acquire a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
the first query cost estimation module is used for estimating a first query cost of the first query statement;
the second query cost estimation module is used for estimating a second query cost of the second query statement;
the query cost comparison module is used for comparing the first query cost with the second query cost and determining the minimum query cost;
the first query module is used for querying according to the query statement corresponding to the minimum query cost to obtain a first query result set;
a query statement rewriting module for rewriting another query statement according to the first query result set;
the second query module is used for querying according to the rewritten query statement to obtain a second query result set;
and the association result generation module is used for obtaining an association query result set according to the first query result set and the second query result set.
An apparatus provided by an embodiment of the present specification includes:
at least one processor; and (c) a second step of,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to:
obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
estimating a first query cost of the first query statement;
estimating a second query cost for the second query statement;
comparing the first query cost with the second query cost to determine a minimum query cost;
inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
rewriting additional query statements according to the first query result set;
inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
and obtaining an associated query result set according to the first query result set and the second query result set.
The embodiment of the specification adopts at least one technical scheme which can achieve the following beneficial effects:
by estimating the query cost of each table, the query statement with lower query cost is executed firstly, and then the other query statement is rewritten according to the obtained query result set, so that the query range of the other query statement can be narrowed, the query cost of the other query statement can be reduced, and the query efficiency of multi-table association query can be improved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a diagram illustrating an application scenario of a multi-table association query method in an embodiment of the present disclosure;
FIG. 2 is a flowchart illustrating a multi-table association query method provided in an embodiment of the present disclosure;
FIG. 3 is a schematic structural diagram of a multi-table association lookup apparatus corresponding to FIG. 2 according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of a multi-table association query device corresponding to fig. 2 provided in an embodiment of this specification.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only a few embodiments of the present application, and not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of an application scenario of the multi-table association query method in the embodiment of the present specification. As shown in fig. 1, the workstation 10 is communicably connected to the databases 11, 12, and 13. The databases 11, 12, and 13 store a large number of data tables, respectively. The databases 11, 12 and 13 may be located in different locations, respectively. The databases 11, 12 and 13 may be different types of databases. When the workstation 10 acquires the multi-table association query script and the tables involved in the script are located in the database 11, the database 12 and the database 13, respectively, it is required to acquire relevant data information from the database 11, the database 12 and the database 13, respectively.
Fig. 2 is a flowchart illustrating a multi-table association query method according to an embodiment of the present disclosure. From the viewpoint of the program, the main body of execution of the flow may be a program or an application client installed in an application server or a workstation computer.
As shown in fig. 2, the process may include the following steps:
s201: obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
the multi-table associated query script may be a script using SQL statements.
The first table in the embodiment of the present specification may be a data table stored in a database.
Open source software can be adopted to analyze the multi-table association query script to obtain query statements for each table.
S202: obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
for example, the following is a simple multi-table association query script:
Figure BDA0001816421310000051
in the above paragraph of script, tables a and b are referred to. The script may be parsed using open source software to obtain a query statement for table a and a query statement for table b.
The query statement for table a may be
Figure BDA0001816421310000052
Figure BDA0001816421310000061
The query statement for table a may be
Figure BDA0001816421310000062
It can be seen that the query statement for table a has the same field id as the query condition in the query statement for table b.
S203: estimating a first query cost of the first query statement;
the query cost may refer to the time consumed by executing the query or the amount of occupied hardware resources. In the embodiment of the present specification, the query cost may be estimated from the perspective of the data amount of the query result, or from the perspective of the data amount of the metadata in the data table, or may be estimated in a manner of comprehensively considering the data amount of the query result, the occupancy rate of the memory, and the occupancy rate of the CPU.
A dynamic programming algorithm and a genetic algorithm can be adopted to estimate the query cost by combining the database metadata.
S204: estimating a second query cost for the second query statement;
s205: comparing the first query cost with the second query cost to determine a minimum query cost;
the result of the query cost may be a specific numerical value. Comparing the size of the specific numerical value can determine the minimum query cost.
S206: inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
for the query statement with the minimum query cost, the query can be performed first.
S207: rewriting additional query statements according to the first query result set;
additional query statements may be augmented with qualifiers using the first set of query results as newly augmented qualifiers.
When the query cost of the first query statement is minimal, the further query statement is a second query statement; the further query statement is the first query statement when the query cost of the second query statement is minimal.
S208: inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
since the constraint of the query statement after rewriting is increased, the data size of the second query result set is smaller than the query result of the query statement before rewriting.
S209: and obtaining an associated query result set according to the first query result set and the second query result set.
Specifically, the first query result set and the second query result set may be connected through a connection algorithm to obtain a final associated query result set.
In the example of query statements given above, assuming that the query cost for the query statement for table a is 100 (indicating that 100 pieces of query results are expected) and the query cost for the query statement for table b is 1000 (indicating that 1000 pieces of query results are expected), the query statement for table a may be executed first. Assuming that the result set obtained after execution is D (a) = { id } = {1,2,3,. 100}, the query statement for table B can be rewritten as select b.age, b.sex from B world b.aid in (1, 2,3,. 100) and b.age >20and b.sex = 'male' accordingly. After rewriting, it means that the query statement for table b only needs to query from data with id between 1 and 100, the query scope is reduced, and the query result for table b is within 100. The query cost of the rewritten query statement is smaller than the query cost before rewriting. More specifically, before rewriting, when executing the query statement for the table b, the device of the workstation needs to read about 1000 pieces of data from the database into its own memory, and then filter the data related to the table a from the about 1000 pieces of data, so as to obtain the final 100 pieces of data. After rewriting, the device of the workstation only needs to read the data within 100 items from the database into its own memory, and then connect the data within 100 items with the query result set of the table a.
In summary, in the method in fig. 2, by estimating the query cost of each table, the query statement with a smaller query cost is executed first, and then the other query statement is rewritten according to the obtained query result set, so that the query range of the other query statement can be narrowed, the query cost of the other query statement can be reduced, and the query efficiency of the multi-table association query can be improved.
Based on the method of fig. 2, the present specification also provides some specific embodiments of the method, which are described below.
In the embodiment of the present specification, step S207: rewriting additional query statements according to the first query result set may specifically include:
qualifying the same field in the further query statement with a value of the first query result set.
In practical applications, when the data amount of a certain data table is large, the estimation of the query cost of the table also consumes a lot of resources. When the amount of data exceeds a certain value, the cost of the query to the table is estimated, which may cause a crash of the database. In order to avoid such a situation, in the embodiment of the present specification, step S203: before estimating the first query cost of the first query statement, the method may further include the following steps:
judging whether the data volume of the first table is larger than a preset threshold value or not to obtain a first judgment result;
the estimating a first query cost of the first query statement specifically includes:
and when the first judgment result shows that the data volume of the first table is not larger than the preset threshold, estimating a first query cost of the first query statement.
When the first determination result indicates that the data amount of the first table is greater than the preset threshold, the step of estimating the first query cost of the first query statement may no longer be performed.
In the above steps, the specific value of the preset threshold may be set according to the performance of the database.
And when the first judgment result shows that the data volume of the first table is not larger than the preset threshold, estimating the first query cost of the first query statement without causing the crash of the database.
When the first judgment result indicates that the data size of the first table is greater than the preset threshold, the following steps may be directly performed without estimating the first query cost of the first query statement:
inquiring according to the first inquiry statement to obtain a third inquiry result set;
inquiring according to the second inquiry statement to obtain a fourth inquiry result set;
and obtaining an associated query result set according to the third query result set and the fourth query result set.
In the steps, the query statement is not rewritten any more, and the original first query statement and the original second query statement are directly adopted for query, so that the crash of the database is avoided.
In the above example, a multi-table associative query is directed to two tables. In practical application, multi-table association query can be performed on three tables or more tables.
If multi-table association query is performed on three tables, the following steps can be adopted:
obtaining a third query statement for a third table; the query conditions in the third query statement have the same field;
calculating a third query cost of the third query statement;
after the step S205 determines the minimum query cost, and before the step S206 performs query according to the query statement corresponding to the minimum query cost, the method may further include:
comparing the third query cost to the minimum query cost;
if the third query cost is less than the minimum query cost, performing query according to the third query statement to obtain a fifth query result set;
rewriting the query statement corresponding to the minimum query cost according to the fifth query result set;
step S206, querying according to the query statement corresponding to the minimum query cost, which may specifically include:
and inquiring according to the inquiry statement corresponding to the rewritten minimum inquiry cost.
In the above step, when three tables are involved, the query costs of the three tables can be estimated respectively, and the table with the minimum query cost is selected from the three estimation results and is queried first. And after the query result is obtained, rewriting the query statement of the table with the intermediate query cost according to the query result. And after the query result of the second table is obtained, rewriting the query statement of the third table according to the query result of the second table, and then querying, thereby realizing statement optimization of multi-table association query of the three tables.
Furthermore, according to the query mode of the three tables in the above example, it can be known that, when there are more tables to be queried in association, the query costs of the tables can be estimated, the tables with the minimum query costs are queried according to the query costs obtained through estimation, the query statements with the minimum query costs are rewritten according to the query results, and the query and the rewriting are sequentially performed until the query results of the tables with the rewritten query statements are obtained.
In practical applications, the execution process for the query statement is performed circularly. Sometimes, after the data in the data table has been completely queried, the query process is still in circulation, which may cause the system to still perform circulation query, resulting in wasted query time.
In order to avoid the above situation, in this embodiment of the present specification, after performing query according to the query statement corresponding to the minimum query cost, the method may further include the step of:
and marking the state of the table aimed at by the query statement corresponding to the minimum query cost as queried.
Similarly, in this embodiment of the present specification, after performing a query according to the rewritten query statement, the method may further include:
and marking the state of the table aimed at by the rewritten query statement as queried.
The state of the table is queried, which means that the table is queried completely, and after the subsequent process identifies the state mark, the circular query on the table can no longer be performed.
In practical application, each query result set may include a plurality of pieces of query data, and each query result set is associated to obtain a final associated query result set. The specific association method may be performed by external connection. The external connection comprises a left connection and a right connection. The specific external connection mode is determined by the initial multi-table association query script. In the original multi-table associative query script, left join can be used to represent left join and right join can be used to represent right join.
It should be noted that, in the embodiments of the present specification, the first query statement, the second query statement, and the like are obtained by analyzing an initial multi-table related query script. That is, before the first query statement for the first table is obtained, the following steps may be further included:
acquiring a multi-table association query script;
and analyzing the script to obtain the first query statement and the second query statement.
The analysis of the multi-table association query script can be realized by adopting open source software such as Jsqlparser or druid.
Based on the same idea, the embodiment of the present specification further provides a device corresponding to the above method. Fig. 3 is a schematic structural diagram of a multi-table association query apparatus corresponding to fig. 2 according to an embodiment of the present disclosure. As shown in fig. 3, the apparatus may include:
a first query statement obtaining module 301, configured to obtain a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
a second query statement obtaining module 302, configured to obtain a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
a first query cost estimation module 303, configured to estimate a first query cost of the first query statement;
a second query cost evaluation module 304, configured to evaluate a second query cost of the second query statement;
a query cost comparing module 305, configured to compare the first query cost with the second query cost, and determine a minimum query cost;
a first query module 306, configured to query the query statement corresponding to the minimum query cost to obtain a first query result set;
a query statement rewriting module 307, configured to rewrite another query statement according to the first query result set;
a second query module 308, configured to perform a query according to the rewritten query statement to obtain a second query result set;
and an association result generating module 309, configured to obtain an association query result set according to the first query result set and the second query result set.
Optionally, the query statement rewriting module 307 may specifically include:
a query statement rewrite unit configured to qualify the same field in the further query statement by a value of the first query result set.
Optionally, the apparatus may further include:
the first judging module is used for judging whether the data volume of the first table is larger than a preset threshold value or not before estimating the first query cost of the first query statement to obtain a first judging result;
the first query cost estimation module 303 may be specifically configured to:
and when the first judgment result shows that the data volume of the first table is not larger than the preset threshold, estimating a first query cost of the first query statement.
Optionally, the apparatus may further include:
the third query module is used for querying according to the first query statement to obtain a third query result set when the first judgment result indicates that the data volume of the first table is larger than the preset threshold;
the fourth query module is used for querying according to the second query statement to obtain a fourth query result set;
the association result generating module 309 is further configured to obtain an association query result set according to the third query result set and the fourth query result set.
Optionally, the apparatus may further include:
a third query statement acquisition module, configured to acquire a third query statement for a third table; the query conditions in the third query statement have the same field;
a third query cost estimation module for estimating a third query cost of the third query statement;
the query cost comparing module 305 is further configured to, after determining a minimum query cost, compare the third query cost with the minimum query cost before performing query according to the query statement corresponding to the minimum query cost;
the fourth query module is configured to query according to the third query statement to obtain a fifth query result set if the third query cost is smaller than the minimum query cost;
the query statement rewriting module 307 is further configured to rewrite the query statement corresponding to the minimum query cost according to the fifth query result set;
the first query module 306 is further configured to:
and inquiring according to the inquiry statement corresponding to the rewritten minimum inquiry cost.
Optionally, the apparatus may further include:
and the first marking module is used for marking the state of the table aimed at by the query statement corresponding to the minimum query cost as queried after querying according to the query statement corresponding to the minimum query cost.
Optionally, the apparatus may further include:
and the second marking module is used for marking the state of the table aimed at by the rewritten query statement as queried after querying according to the rewritten query statement.
Optionally, the correlation result generating module 309 is specifically configured to:
and externally connecting the first query result set and the second query result set to obtain a connected query result set.
Optionally, the apparatus may further include:
the query script acquisition module is used for acquiring a multi-table association query script before acquiring a first query statement aiming at a first table;
and the script analysis module is used for analyzing the script to obtain the first query statement and the second query statement.
Based on the same idea, the embodiment of the present specification further provides a device corresponding to the above method.
Fig. 4 is a schematic structural diagram of a multi-table association query device corresponding to fig. 2 provided in an embodiment of this specification. As shown in fig. 4, the apparatus 400 may include:
at least one processor 410; and the number of the first and second groups,
a memory 430 communicatively coupled to the at least one processor; wherein, the first and the second end of the pipe are connected with each other,
the memory 430 stores instructions 420 executable by the at least one processor 410 to cause the at least one processor 410 to:
obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
estimating a first query cost of the first query statement;
estimating a second query cost for the second query statement;
comparing the first query cost with the second query cost to determine a minimum query cost;
inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
rewriting additional query statements according to the first query result set;
inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
and obtaining an associated query result set according to the first query result set and the second query result set.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as ABEL (Advanced Boolean Expression Language), AHDL (alternate Hardware Description Language), traffic, CUPL (core universal Programming Language), HDCal, jhddl (Java Hardware Description Language), lava, lola, HDL, PALASM, rhyd (Hardware Description Language), and vhigh-Language (Hardware Description Language), which is currently used in most popular applications. It will also be apparent to those skilled in the art that hardware circuitry for implementing the logical method flows can be readily obtained by a mere need to program the method flows with some of the hardware description languages described above and into an integrated circuit.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium that stores computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and embedded microcontrollers, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be regarded as a hardware component and the means for performing the various functions included therein may also be regarded as structures within the hardware component. Or even means for performing the functions may be conceived to be both a software module implementing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, respectively. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of other like elements in a process, method, article, or apparatus comprising the element.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (17)

1. A multi-table association query method comprises the following steps:
obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
estimating a first query cost of the first query statement; the query cost refers to the time consumed by executing the query or the occupied hardware resource;
estimating a second query cost for the second query statement;
comparing the first query cost with the second query cost to determine a minimum query cost;
inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
rewriting additional query statements according to the first query result set specifically includes: qualifying the same field in the further query statement with a value of the first set of query results;
inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
and obtaining an associated query result set according to the first query result set and the second query result set.
2. The method of claim 1, prior to estimating the first query cost of the first query statement, further comprising:
judging whether the data volume of the first table is larger than a preset threshold value or not to obtain a first judgment result;
the estimating the first query cost of the first query statement specifically includes:
and when the first judgment result shows that the data volume of the first table is not larger than the preset threshold, estimating a first query cost of the first query statement.
3. The method of claim 2, further comprising:
when the first judgment result shows that the data size of the first table is larger than the preset threshold value, inquiring according to the first inquiry statement to obtain a third inquiry result set;
inquiring according to the second inquiry statement to obtain a fourth inquiry result set;
and obtaining an associated query result set according to the third query result set and the fourth query result set.
4. The method of claim 1, further comprising:
obtaining a third query statement for a third table; the query conditions in the third query statement have the same field;
estimating a third query cost of the third query statement;
after the minimum query cost is determined and before the query is performed according to the query statement corresponding to the minimum query cost, the method further includes:
comparing the third query cost to the minimum query cost;
if the third query cost is less than the minimum query cost, performing query according to the third query statement to obtain a fifth query result set;
rewriting the query statement corresponding to the minimum query cost according to the fifth query result set;
the querying according to the query statement corresponding to the minimum query cost specifically includes:
and inquiring according to the inquiry statement corresponding to the rewritten minimum inquiry cost.
5. The method of claim 1, after the query is performed according to the query statement corresponding to the minimum query cost, further comprising:
and marking the state of the table aimed at by the query statement corresponding to the minimum query cost as queried.
6. The method of claim 1, after the querying according to the rewritten query statement, further comprising:
and marking the state of the table aimed at by the rewritten query statement as queried.
7. The method according to claim 1, wherein obtaining an associated query result set according to the first query result set and the second query result set specifically includes:
and externally connecting the first query result set and the second query result set to obtain a connected query result set.
8. The method of claim 1, prior to obtaining the first query statement for the first table, further comprising:
acquiring a multi-table association query script;
and analyzing the script to obtain the first query statement and the second query statement.
9. A multi-table associative lookup apparatus, comprising:
the first query statement acquisition module is used for acquiring a first query statement aiming at a first table; the first query statement is obtained by analyzing a multi-table association query script;
a second query statement acquisition module, configured to acquire a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
the first query cost estimation module is used for estimating a first query cost of the first query statement; the query cost refers to the time consumed by executing the query or the occupied hardware resource;
a second query cost estimation module, configured to estimate a second query cost of the second query statement;
the query cost comparison module is used for comparing the first query cost with the second query cost and determining the minimum query cost;
the first query module is used for querying according to the query statement corresponding to the minimum query cost to obtain a first query result set;
a query statement rewriting module for rewriting another query statement according to the first query result set; the query statement rewriting module specifically includes: a query statement rewrite unit configured to define the same field in the other query statement by a value of the first query result set;
the second query module is used for querying according to the rewritten query statement to obtain a second query result set;
and the correlation result generating module is used for obtaining a correlation query result set according to the first query result set and the second query result set.
10. The apparatus of claim 9, further comprising:
the first judging module is used for judging whether the data volume of the first table is larger than a preset threshold value or not before estimating the first query cost of the first query statement to obtain a first judging result;
the first query cost estimation module is specifically configured to:
and when the first judgment result shows that the data volume of the first table is not larger than the preset threshold, estimating a first query cost of the first query statement.
11. The apparatus of claim 10, further comprising:
the third query module is used for querying according to the first query statement to obtain a third query result set when the first judgment result indicates that the data volume of the first table is larger than the preset threshold;
the fourth query module is used for querying according to the second query statement to obtain a fourth query result set;
and the association result generation module is further configured to obtain an association query result set according to the third query result set and the fourth query result set.
12. The apparatus of claim 9, further comprising:
a third query statement acquisition module, configured to acquire a third query statement for a third table; the query conditions in the third query statement have the same field;
a third query cost estimation module for estimating a third query cost of the third query statement;
the query cost comparison module is further configured to compare the third query cost with the minimum query cost after determining the minimum query cost and before querying the query statement corresponding to the minimum query cost;
the fourth query module is configured to query according to the third query statement to obtain a fifth query result set if the third query cost is smaller than the minimum query cost;
the query statement rewriting module is further configured to rewrite the query statement corresponding to the minimum query cost according to the fifth query result set;
the first query module is further configured to:
and inquiring according to the inquiry statement corresponding to the rewritten minimum inquiry cost.
13. The apparatus of claim 9, further comprising:
and the first marking module is used for marking the state of the table aimed at by the query statement corresponding to the minimum query cost as queried after querying according to the query statement corresponding to the minimum query cost.
14. The apparatus of claim 9, further comprising:
and the second marking module is used for marking the state of the table aimed at by the rewritten query statement as queried after querying according to the rewritten query statement.
15. The apparatus according to claim 9, wherein the association result generation module is specifically configured to:
and externally connecting the first query result set and the second query result set to obtain a connected query result set.
16. The apparatus of claim 9, further comprising:
the query script acquisition module is used for acquiring a multi-table association query script before acquiring a first query statement aiming at a first table;
and the script analysis module is used for analyzing the script to obtain the first query statement and the second query statement.
17. A multi-table associative lookup apparatus comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to cause the at least one processor to:
obtaining a first query statement for a first table; the first query statement is obtained by analyzing a multi-table association query script;
obtaining a second query statement for a second table; the second query statement is obtained by analyzing the multi-table association query script; the query conditions in the first query statement and the second query statement have the same fields;
estimating a first query cost of the first query statement; the query cost refers to the time consumed by executing the query or the occupied hardware resource;
estimating a second query cost for the second query statement;
comparing the first query cost with the second query cost to determine a minimum query cost;
inquiring according to the inquiry statement corresponding to the minimum inquiry cost to obtain a first inquiry result set;
rewriting additional query statements according to the first query result set specifically includes: defining the same field in the further query statement with the value of the first query result set;
inquiring according to the rewritten inquiry statement to obtain a second inquiry result set;
and obtaining an associated query result set according to the first query result set and the second query result set.
CN201811144099.7A 2018-09-29 2018-09-29 Multi-table association query method, device and equipment Active CN109656946B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811144099.7A CN109656946B (en) 2018-09-29 2018-09-29 Multi-table association query method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811144099.7A CN109656946B (en) 2018-09-29 2018-09-29 Multi-table association query method, device and equipment

Publications (2)

Publication Number Publication Date
CN109656946A CN109656946A (en) 2019-04-19
CN109656946B true CN109656946B (en) 2022-12-16

Family

ID=66110687

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811144099.7A Active CN109656946B (en) 2018-09-29 2018-09-29 Multi-table association query method, device and equipment

Country Status (1)

Country Link
CN (1) CN109656946B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113297248B (en) * 2020-07-27 2022-04-26 阿里巴巴集团控股有限公司 Data processing method, resource allocation method, device, equipment and readable storage medium
CN112307050B (en) * 2020-09-16 2022-11-15 苏宁云计算有限公司 Identification method and device for repeated correlation calculation and computer system
CN113434529B (en) * 2021-06-22 2023-06-16 青岛海尔科技有限公司 Service data query method and device, storage medium, processor and electronic equipment

Family Cites Families (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1307585C (en) * 2003-12-31 2007-03-28 中兴通讯股份有限公司 Data processing method for realizing data base multitable inguiry
US8140556B2 (en) * 2009-01-20 2012-03-20 Oracle International Corporation Techniques for automated generation of queries for querying ontologies
CN101561817A (en) * 2009-06-02 2009-10-21 天津大学 Conversion algorithm from XQuery to SQL query language and method for querying relational data
CN101739453B (en) * 2009-12-17 2013-07-10 中国电力科学研究院 Method and device for carrying out condition query on database table
US8990186B2 (en) * 2011-12-28 2015-03-24 Teradata Us, Inc. Techniques for updating join indexes
CN103365885B (en) * 2012-03-30 2016-12-14 国际商业机器公司 Method and system for database inquiry optimization
US9355143B2 (en) * 2012-07-29 2016-05-31 Sergiy GETMANETS Systems and methods for providing a simplified application programming interface for converting from two-dimensional query languages into multi-dimensional query languages to query multi-dimensional data sources and MDX servers
CN103092998B (en) * 2013-02-21 2017-02-08 用友网络科技股份有限公司 Data query system and data query method
CN105574052A (en) * 2014-11-06 2016-05-11 中兴通讯股份有限公司 Database query method and apparatus
CN105630881B (en) * 2015-12-18 2019-04-09 陕西师范大学 A kind of date storage method and querying method of RDF
CN106250519A (en) * 2016-08-04 2016-12-21 曙光信息产业(北京)有限公司 Data query method and apparatus for parallel database
CN108073641B (en) * 2016-11-18 2020-06-16 华为技术有限公司 Method and device for querying data table
CN107315790B (en) * 2017-06-14 2021-07-06 腾讯科技(深圳)有限公司 Optimization method and device for non-relevant sub-queries
CN108509637A (en) * 2018-04-10 2018-09-07 口碑(上海)信息技术有限公司 Tables of data relation query method and device

Also Published As

Publication number Publication date
CN109656946A (en) 2019-04-19

Similar Documents

Publication Publication Date Title
CN107562775B (en) Data processing method and device based on block chain
JP7021228B2 (en) Blockchain-based data storage and query methods and devices
CN109656946B (en) Multi-table association query method, device and equipment
CN107622080B (en) Data processing method and equipment
CN110399359B (en) Data backtracking method, device and equipment
CN110263050B (en) Data processing method, device, equipment and storage medium
US20240126465A1 (en) Data storage methods, apparatuses, devices, and storage media
CN115828162A (en) Classification model training method and device, storage medium and electronic equipment
WO2024046015A1 (en) Data query method and apparatus, storage medium, and electronic device
CN116303625B (en) Data query method and device, storage medium and electronic equipment
CN116402165B (en) Operator detection method and device, storage medium and electronic equipment
CN116822606A (en) Training method, device, equipment and storage medium of anomaly detection model
CN107368281B (en) Data processing method and device
CN116384505A (en) Data processing method and device, storage medium and electronic equipment
CN116010419A (en) Method and device for creating unique index and optimizing logic deletion
CN115878654A (en) Data query method, device, equipment and storage medium
CN107562533B (en) Data loading processing method and device
CN115934161A (en) Code change influence analysis method, device and equipment
CN108415914B (en) Method, device and equipment for inquiring information in visual object
CN112907198B (en) Service state circulation maintenance method and device and electronic equipment
CN111339117B (en) Data processing method, device and equipment
CN108153799B (en) Database access control method and device and database system
CN109325127B (en) Risk identification method and device
TWI748247B (en) Method, system and electronic equipment for generating statistical information
CN110008237B (en) Similar query recognition method and device

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
TA01 Transfer of patent application right

Effective date of registration: 20200927

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Advanced innovation technology Co.,Ltd.

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Applicant before: Alibaba Group Holding Ltd.

Effective date of registration: 20200927

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Innovative advanced technology Co.,Ltd.

Address before: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant before: Advanced innovation technology Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant