CN113535756B - Data query method, device, equipment and storage medium - Google Patents

Data query method, device, equipment and storage medium Download PDF

Info

Publication number
CN113535756B
CN113535756B CN202110873375.9A CN202110873375A CN113535756B CN 113535756 B CN113535756 B CN 113535756B CN 202110873375 A CN202110873375 A CN 202110873375A CN 113535756 B CN113535756 B CN 113535756B
Authority
CN
China
Prior art keywords
data table
data
query
query statement
tables
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
CN202110873375.9A
Other languages
Chinese (zh)
Other versions
CN113535756A (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.)
Shanghai Dameng Database Co Ltd
Original Assignee
Shanghai Dameng Database 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 Shanghai Dameng Database Co Ltd filed Critical Shanghai Dameng Database Co Ltd
Priority to CN202110873375.9A priority Critical patent/CN113535756B/en
Publication of CN113535756A publication Critical patent/CN113535756A/en
Application granted granted Critical
Publication of CN113535756B publication Critical patent/CN113535756B/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
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a data query method, a device, equipment and a storage medium, wherein the method comprises the steps that if a query statement input by a user is a multi-table connection query statement and meets a set condition; dividing a plurality of data tables into a first data table set and a second data table set according to the query items; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term; removing the data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set; splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences; and carrying out data query based on the new query statement. By utilizing the method, the complementary conditions are spliced with the query statement of the removed data table, and the redundant table in the query statement is eliminated by optimizing and rewriting the query statement, so that the generation of an intermediate result set can be reduced, and the query efficiency is improved.

Description

Data query method, device, equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of databases, in particular to a data query method, a device, equipment and a storage medium.
Background
When two or more data tables are involved in a query statement (e.g., structured query language (Structured Query Language, SQL)), a join query is required for those data tables. Multi-table join queries may produce a relatively large set of intermediate results, thereby affecting query efficiency.
Disclosure of Invention
The embodiment of the invention provides a data query method, a device, equipment and a storage medium, which can reduce the generation of an intermediate result set by rewriting query sentences, thereby improving the query efficiency.
In a first aspect, an embodiment of the present invention provides a data query method, where the method includes:
if the query statement input by the user is a multi-table connection query statement and meets the set condition; wherein the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
dividing the plurality of data tables into a first data table set and a second data table set according to the query term; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
removing data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set;
splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences;
and carrying out data query based on the new query statement.
In a second aspect, an embodiment of the present invention further provides a data query apparatus, where the apparatus includes:
the query statement judging module is used for judging whether the query statement input by the user is a multi-table connection query statement or not and meets the set condition; wherein the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
the data table dividing module is used for dividing the plurality of data tables into a first data table set and a second data table set according to the query items when the query statement input by the user is a multi-table connection query statement and meets the set condition; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
the data table information removing module is used for removing the data table information in the second data table set from the query statement and generating a supplement condition according to the second data table set;
the query statement splicing module is used for splicing the supplementing conditions with the query statement of the removal data table to form a new query statement;
and the data query module is used for carrying out data query based on the new query statement.
In a third aspect, an embodiment of the present invention further provides a computer apparatus, including: a memory and one or more processors;
the memory is used for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the data query method as described in the first aspect above.
In a fourth aspect, embodiments of the present invention also provide a storage medium containing computer executable instructions which, when executed by a computer processor, are used to perform a data querying method as described in the first aspect above.
The embodiment of the invention discloses a data query method, a device, equipment and a storage medium, wherein the method comprises the steps that if a query statement input by a user is a multi-table connection query statement and meets a set condition; wherein the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information; dividing the plurality of data tables into a first data table set and a second data table set according to the query term; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term; removing data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set; splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences; and carrying out data query based on the new query statement. By utilizing the method, the data table set irrelevant to the query term is removed from the original query statement, the supplementary condition is generated, the supplementary condition is spliced with the query statement of which the data table is removed, and the redundant table in the query statement is eliminated by optimizing and rewriting the query statement, so that the generation of an intermediate result set can be reduced, and the query efficiency is improved.
Drawings
FIG. 1 is a flowchart of a data query method according to a first embodiment of the present invention;
fig. 2 is a flowchart of a data query method according to a second embodiment of the present invention;
fig. 3 is a flowchart of a data query method according to a third embodiment of the present invention;
fig. 4 is a block diagram of a data query device according to a fourth embodiment of the present invention;
fig. 5 is a block diagram of a computer device according to a fifth embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Example 1
Fig. 1 is a flowchart of a data query method according to a first embodiment of the present invention, where the method may be performed by a data query device, and the device may be implemented by software and/or hardware.
It should be noted that, in the data query method of this embodiment, firstly, grammar and semantic analysis are performed on a query sentence input by a user, and equivalent semantic conversion and optimization are performed on the query sentence meeting a preset form, so as to reduce the query or search range of data, and query is performed in a corresponding data table according to the converted sentence. The method specifically comprises the following steps:
s110, if the query sentence input by the user is a multi-table connection query sentence and meets the set condition.
Wherein, the setting conditions include: carrying a set keyword and not containing a set function; and the query statement contains a plurality of data table information.
The keywords may be words used to characterize the sentence function, such as keyword SELECT is used to characterize selecting data from a data table, DISTINCT is used to characterize eliminating duplicate records in a result set, and WHERE is used to characterize implementing selective grabbing of data. In this embodiment, the keywords are set as keywords representing the deduplication query, for example: "DISTINCT". I.e. one condition that the query statement satisfies is to carry a "disable" key. The set function is an aggregate function in the query statement.
Specifically, a query sentence input by a user is analyzed, and whether the query sentence contains a plurality of data table information and carries a set keyword and does not contain a set function is determined, and if the query sentence contains a plurality of data table information and carries a set keyword and does not contain a set function, the query sentence is an object of optimization in this embodiment. The query statement is used for matching data in the data table with the set key.
By way of example, a query statement may be expressed as:
SELECT DISTINCT T1.C1 FROM T1, T2, T3, T4, T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1 = T4.C1 AND T5.C1<200; it can be seen that the data tables involved in the query statement include T1, T2, T3, T4, and T5, and the query term includes the keyword distict, and the query statement is a multi-table join query statement that does not include a set function.
Optionally, the query statement carries conditional information.
The condition information may include: the relation between tables is what content is in a certain column of the table and what condition is satisfied by the content. In this embodiment, the condition information may be extracted by the keyword "WHERE", that is, the content following the keyword "WHERE" is the condition information.
Specifically, the query statement carries a query part and condition information, and the condition information can be specifically a condition to be satisfied by query data. Taking the query statement exemplified in the above embodiment as an example: the "SELECT DISTINCT T1.c1 FROM T1, T2, T3, T4, T5" part is the query part, AND the "WHERE T2.c2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1 =t4.c1 AND T5.c1<200" part is the condition information part.
S120, dividing the data tables into a first data table set and a second data table set according to the query items.
Wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term. The query term may be a "column term" or a "row term" in a table that the query statement wants to query. Taking the query term exemplified by the above embodiment as an example, the query term of the query term is "T1.C1", i.e., the data listed in the table T1 as "C1" is to be queried.
Specifically, when the query statement input by the user is a multi-table connection query statement and meets the set condition, collecting the data tables involved in the query statement, dividing the data tables involved in all the queried items into a first data table set, and dividing the rest of the data tables into a second data table set.
Illustratively, a query statement is expressed as:
SELECT DISTINCT T1.C1 FROM T1,T2,T3,T4,T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1=T4.C1 AND T5.C1<200;
the first set of data tables may be denoted as Ts and the second set of data tables may be denoted as Tr. It can be seen that the data table related to the query statement is: t1, T2, T3, T4, T5. Wherein the data table T1 is divided into the first data table set Ts because the data table T1 is directly related to the query term T1. C1; the data tables T2, T3, T4, T5 are not directly related to the query term, and the data tables T2, T3, T4, T5 are divided into the second data table set Tr. And then the data table in the Tr, which has a connection relation with the data table in the Ts, is moved to the Ts. The data table in Tr and the data table in Ts have connection relation, namely the data table indirectly related to the query term.
S130, removing the data table information in the second data table set from the query statement, and generating a supplementary condition according to the second data table set.
The supplemental condition may be composed of the removed data table information and condition information corresponding to the removed data table information.
Specifically, the data tables in the second data table set are not related to the query term, so the data tables in the second data table set are removed from the query statement, and a supplemental condition is generated based on the removed data tables.
For example, the supplemental condition may be expressed as EXISTS (SELECT TOP 11 FROM tab1,tab2, …, tabx WHERE exp), WHERE tab1, tab2, …, tabx is all data tables in the second set of data tables and exp is all conditions in the query statement that are related to data tables tab1, tab2, …, tabx.
And S140, splicing the supplementing conditions with the query statement of the removed data table to form a new query statement.
The way to splice the supplemental condition with the query statement that removes the data table may be: and placing the supplementary condition in a WHERE clause of the query statement of the removal data table, and splicing the supplementary condition with the original query condition by adopting a set field.
Wherein the set field may be "AND". The number of the supplementary conditions can be one or more, for example, a plurality of supplementary conditions can be spliced by setting fields. Illustratively, the WHERE clause of the new query statement may be in the form of: WHERE original query condition AND complementary condition.
S150, carrying out data query based on the new query statement.
Specifically, the data query is performed by using the new optimized query statement.
The embodiment of the invention discloses a data query method, which comprises the steps that if a query statement input by a user is a multi-table connection query statement and meets a set condition; wherein, the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information; dividing a plurality of data tables into a first data table set and a second data table set according to the query items; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term; removing the data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set; splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences; and carrying out data query based on the new query statement. By utilizing the method, the data table set irrelevant to the query term is removed from the original query statement, the supplementary condition is generated, the supplementary condition is spliced with the query statement of which the data table is removed, and the redundant table in the query statement is eliminated by optimizing and rewriting the query statement, so that the generation of an intermediate result set can be reduced, and the query efficiency is improved.
Example two
Fig. 2 is a flowchart of a data query method according to a second embodiment of the present invention, where the data query method is further optimized based on the foregoing embodiment. The method specifically comprises the following steps:
s210, if the query sentence input by the user is a multi-table connection query sentence and meets the set condition.
S220, dividing the data table directly related to the query term into a first data table set, and dividing the rest data tables into a second data table set.
Specifically, when the query statement input by the user is a multi-table connection query statement and meets the set condition, collecting the data tables involved in the query statement, dividing the data tables directly involved in the query items of all the queried statements into a first data table set, and dividing the rest of the data tables into a second data table set.
Illustratively, if a query statement is expressed as:
SELECT DISTINCT T1.C1 FROM T1,T2,T3,T4,T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1=T4.C1 AND T5.C1<200;
it can be seen that the data table related to the query statement is: t1, T2, T3, T4, T5, wherein the data table T1 is directly related to the query term of the query statement, and the data tables T2, T3, T4, T5 are not directly related to the query term of the query statement. If the first data table set may be expressed as Ts and the second data table set may be expressed as Tr, the data table T1 is divided into the first data table set Ts and the data tables T2, T3, T4, T5 are divided into the second data table set Tr.
S230, traversing the data table in the second data table set, and judging whether a connection condition exists between the traversed data table and the data table in the first data table set according to the condition information; if so, step 240 is performed.
It will be clear that the data tables in the first set of data tables are directly or indirectly related to the query term. The method comprises the steps of determining whether the data table in the second data table set is indirectly related to the query term of the query statement by judging whether the data table in the second data table set and the data table in the first data table set have connection conditions or not.
Specifically, traversing the data table in the second data table set, and judging whether the traversed data table and the data table in the first data table set have connection conditions according to the condition part of the query statement. The connection condition may be a typical join operation, such as a comparison operator, or may be an internal connection, and the connection condition is not particularly limited herein.
Illustratively, the description follows with the above example, in which the conditional parts of the example query statement are: WHERE T2.c2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1 =t4.c1 AND T5.c1<200, it can be seen that only the connection condition t2.c2< t1.c2 exists between data table T2 AND data table T1.
S240, moving the traversed data table to the first data table set to form a new first data table set and a new second data table set.
Specifically, if a connection condition exists between the data table in the second data table set and the data table in the first data table set, it indicates that the data table in the second data table set is indirectly related to the query term of the query statement, and the data table with the connection condition needs to be moved to the first data table set to form a new first data table set and a new second data table set.
Illustratively, describing the above example, in the above example query statement, only the connection condition t2.c2< T1.c2 exists between the data table T2 and the data table T1, and no connection condition exists between the data tables T3, T4, T5 and the data table T1, the data table T2 is moved from the second data table set to the first data table set. Finally, the first data table set Ts includes data tables T1 and T2, and the second data table set Tr includes data tables T3, T4 and T5.
S250, for the new second data table set, returning to execute the operation of traversing the data tables in the second data table set, and judging whether the traversed data tables and the data tables in the first data table set have the connection condition according to the condition information until the data tables directly or indirectly related to the query item are divided into the first data table set.
Specifically, for the newly added data table in the first data table set, the data table in the second data table set is traversed again, whether a connection condition exists between the traversed data table and the newly added data table in the first data table set is judged according to the condition information, if the connection condition exists, the data table is moved from the second data table set to the first data table set until the data table directly or indirectly related to the query item is divided into the first data table set, and the data tables in the second data table set are all irrelevant to the query item.
And S260, removing the data table information in the second data table set from the query statement, and generating a supplementary condition according to the second data table set.
S270, splicing the supplementing conditions with the query statement of the removed data table to form a new query statement.
S280, carrying out data query based on the new query statement.
The embodiment of the invention discloses a data query method, which is characterized in that the steps of dividing a first data table set and a second data table set are thinned on the basis of the embodiment, the data table set irrelevant to query items is removed from an original query statement, a supplementary condition is generated, the supplementary condition is spliced with the query statement of which the data table is removed, and the redundant table in the query statement is eliminated by optimizing and rewriting the query statement, so that the generation of an intermediate result set can be reduced, and the query efficiency is improved.
Example III
Fig. 3 is a flowchart of a data query method according to a third embodiment of the present invention, where the data query method is further optimized based on the foregoing embodiment. The method specifically comprises the following steps:
s310, if the query sentence input by the user is a multi-table connection query sentence and meets the set condition.
Wherein, the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
s320, dividing the data tables into a first data table set and a second data table set according to the query items.
Wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term.
S330, grouping the data table information in the second data table set according to the condition information to obtain at least one data table group.
Wherein, there are connection conditions among the data tables in the data table group.
Specifically, according to the condition information of the query statement, the data tables with the connection conditions in the second data table set are divided into a group to form a data table group. The connection condition may be a typical join operation, such as a comparison operator, or may be an internal connection, and the connection condition is not particularly limited herein. It will be appreciated that when there is no connection condition for one data table in the second data table set to the other data table, then the data tables individually form a data table group.
Illustratively, the second data set Tr is divided into a number of minimum sets (i.e., data table groups) Tr1, tr2, …, trm having no connection condition with each other, where m is the number of data table groups finally formed, as described in connection with the above example. In the above example query statement, the connection condition t3.c1=t4.c1 exists between the data tables T3 and T4 in the second data table set Tr, and no connection condition exists between the data tables T3 and T5, and T4 and T5, so that the tables T3 and T4 are divided into the set Tr1 and the data table T5 is divided into the set Tr 2.
S340, sequentially removing the data tables from the query statement according to the at least one data table group, and generating at least one supplementary condition according to the at least one data table group.
It should be noted that, in this step, since the data table in each data table group has no connection condition with the data tables in other data table groups, and does not participate in projection of the final result set, the effect generated is only to make the result of the connection of the other data tables outside the data table group duplicate p times according to the number p of the intermediate result set filtered by the set itself. Because the query itself is a distict query, repeated records will eventually be filtered out, so that the data tables in the data table group actually belong to redundant tables, and all the data tables in the data table group can be removed from the query statement. However, when the result set generated by the data table group is empty, the result set of the query is always empty, and at this time, if all the data table information in the data table group is directly removed from the query statement, the result set of the query may not be empty any more, and thus the final query result will also change, so that the data table is removed from the query statement, and a supplementary condition needs to be generated according to the data table group, and the supplementary condition can ensure that the final query result will not change after all the data tables in the data table group are removed no matter whether the result set generated by the data table group is empty or not.
In particular, the data tables involved in the set of data tables are independent of the query term of the query statement, so that the data tables are removed from the query statement and a supplemental condition is generated based on the set of data tables.
Optionally, traversing at least one data table group, removing the data table information in the traversed data table group from the query statement, and generating the supplemental condition according to the traversed data table group.
Illustratively, described in connection with the above example, the above example query statement may be expressed as: SELECT DISTINCT T1.C1 FROM T1, T2, T3, T4, T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1 = T4.C1 AND T5.C1<200;
the data table set Tr1 includes the data tables T3 and T4, so that the data table information about T3 and T4 is removed FROM the query sentence to obtain SELECT DISTINCT T1.C1 FROM T1, T2, T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T5.C1<200, and then the supplemental condition EXISTS is generated according to the traversed data tables T3 and T4 (SELECT TOP 11 FROM T3,T4 WHERE T4.C2>0 AND T3.C1 =t4.c1).
S350, splicing the supplementing conditions and the query statement of the removal data table through the setting field.
Wherein the set field may be "AND".
Illustratively, following the above example, the supplemental conditions may be AND-linked to the original conditions of the query statement, resulting in SELECT DISTINCT T1.C1 FROM T1, T2, T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T5.C1<200 AND EXISTS (SELECT TOP 11 FROM T3,T4 WHERE T4.C2>0 AND T3.C1 =t4.c1).
And S360, if the supplementary conditions comprise two or more than two, splicing the supplementary conditions by adopting set fields to form a new query statement.
Wherein the set field may be "AND".
Specifically, when the supplemental condition includes two or more than two, corresponding set fields are adopted to splice according to the relationship of the supplemental condition, so as to form a new query statement.
Illustratively, following the above example, tr2 contains Table T5, so that data Table T5 is removed FROM the query statement to yield SELECT DISTINCT T1.C1 FROM T1, T2 WHERE T2.C2>100 AND T2.C2<T1.C2 AND EXISTS (SELECT TOP 11 FROM T3,T4 WHERE T4.C2>0 AND T3.C1 =T4.C1), AND then the condition EXISTS (SELECT TOP 11 FROM T5 WHERE T5.C1<200) is supplemented in the WHERE clause of the query statement, AND the supplemented condition is AND-connected with the original condition to yield SELECT DISTINCT T1.C1 FROM T1, T2 WHERE T2.C2>100 AND T2.C2<T1.C2 AND EXISTS (SELECT TOP 11 FROM T3,T4 WHERE T4.C2>0 AND T3.C1 =T4.C1) AND EXISTS (SELECT TOP 11 FROM T5 WHERE T5.C1<200).
And S370, carrying out data query based on the new query statement.
Illustratively, the original query statement may be expressed as:
SELECT DISTINCT T1.C1 FROM T1,T2,T3,T4,T5 WHERE T2.C2>100 AND T2.C2<T1.C2 AND T4.C2>0 AND T3.C1=T4.C1 AND T5.C1<200;
after the optimization of the method, the new query statement can be expressed as:
SELECT DISTINCT T1.C1 FROM T1,T2 WHERE T2.C2>100 AND T2.C2<T1.C2 AND EXISTS(SELECT TOP 1 1 FROM T3,T4 WHERE T4.C2>0 AND T3.C1=T4.C1)AND EXISTS(SELECT TOP 1 1 FROM T5 WHERE T5.C1<200);
the embodiment of the invention discloses a data query method, which is optimized on the basis of the embodiment, and refines the steps of generating the supplementary condition and forming the new query statement.
Example IV
Fig. 4 is a block diagram of a data query device according to a fourth embodiment of the present invention, as shown in fig. 4, where the device includes: a query statement determination module 41, a data table division module 42, a data table information removal module 43, a query statement stitching module 44 and a data query module 45.
A query term determination module 41, configured to determine whether a query term input by a user is a multi-table join query term and satisfies a set condition; wherein, the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
the data table dividing module 42 is configured to divide the plurality of data tables into a first data table set and a second data table set according to the query term when the query statement input by the user is a multi-table connection query statement and the set condition is satisfied; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
the data table information removing module 43 is configured to remove data table information in the second data table set from the query statement, and generate a supplemental condition according to the second data table set;
the query statement splicing module 44 is configured to splice the supplemental condition with the query statement from which the data table is removed to form a new query statement;
the data query module 45 is configured to perform a data query based on the new query statement.
Optionally, the query statement carries conditional information.
Optionally, the data table dividing module 42 may specifically be configured to:
dividing the data table directly related to the query term into a first data table set, and dividing the rest data tables into a second data table set;
traversing the data table in the second data table set, and judging whether the traversed data table and the data table in the first data table set have connection conditions according to the condition information;
if the connection condition exists, moving the traversed data table to the first data table set to form a new first data table set and a new second data table set;
and for the new second data table set, returning to execute the operation of traversing the data tables in the second data table set, and judging whether the traversed data tables and the data tables in the first data table set have connection conditions according to the condition information until the data tables directly or indirectly related to the query item are divided into the first data table set.
Alternatively, the data table information removing module 43 may include:
the data table group acquisition unit is used for grouping the data table information in the second data table set according to the condition information to obtain at least one data table group; wherein, there are connection conditions among the data tables in the data table group;
and the supplementing condition generating unit is used for sequentially removing the data tables from the query statement according to the at least one data table group and generating at least one supplementing condition according to the at least one data table group.
Optionally, the supplemental condition generating unit may specifically be configured to:
traversing at least one data table group, removing the data table information in the traversed data table group from the query statement, and generating a supplementary condition according to the traversed data table group.
Alternatively, the query statement stitching module 44 may specifically be configured to:
splicing the supplementing conditions and the query statement of the removal data table through the setting field;
if the supplementary conditions comprise two or more than two, the supplementary conditions are spliced by adopting set fields to form a new query statement.
Optionally, the supplemental condition is composed of the removed data table information and condition information corresponding to the removed data table information.
The device can execute the method provided by all the embodiments of the invention, and has the corresponding functional modules and beneficial effects of executing the method. Technical details not described in detail in this embodiment can be found in the methods provided in all the foregoing embodiments of the invention.
Example five
Fig. 5 is a block diagram of a computer device according to a fifth embodiment of the present invention, and as shown in fig. 5, the computer device includes a processor 51, a memory 52, an input device 53 and an output device 54; the number of processors 51 in the computer device may be one or more, one processor 51 being taken as an example in fig. 5; the processor 51, the memory 52, the input means 53 and the output means 54 in the computer device may be connected by a bus or by other means, in fig. 5 by way of example.
The memory 52 is used as a computer readable storage medium for storing software programs, computer executable programs, and modules, such as program instructions/modules corresponding to the data query method in the embodiment of the present invention (for example, the query sentence judging module 41, the data table dividing module 42, the data table information removing module 43, the query sentence splicing module 44, and the data query module 45 in the data query device). The processor 51 executes various functional applications of the computer device and data processing, i.e., implements the data query method described above, by running software programs, instructions, and modules stored in the memory 52.
The memory 52 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, at least one application program required for functions; the storage data area may store data created according to the use of the terminal, etc. In addition, memory 52 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some examples, memory 52 may further comprise memory remotely located from processor 51, which may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input means 53 may be used to receive entered numeric or character information and to generate key signal inputs related to user settings and function control of the computer device. The output device 54 may include a display device such as a display screen.
Example six
A sixth embodiment of the present invention also provides a storage medium containing computer-executable instructions, which when executed by a computer processor, are configured to perform a data query method, the method comprising:
if the query statement input by the user is a multi-table connection query statement and meets the set condition; wherein, the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
dividing a plurality of data tables into a first data table set and a second data table set according to the query items; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
removing the data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set;
splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences;
and carrying out data query based on the new query statement.
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present invention is not limited to the above method operations, but may also perform the related operations in the data query method provided in any embodiment of the present invention.
From the above description of embodiments, it will be clear to a person skilled in the art that the present invention may be implemented by means of software and necessary general purpose hardware, but of course also by means of hardware, although in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, etc., including several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to execute the method of the embodiments of the present invention.
It should be noted that, in the embodiment of the data query device, each unit and module included are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present invention.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (8)

1. A method of querying data, comprising:
if the query statement input by the user is a multi-table connection query statement and meets the set condition; wherein the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
dividing the plurality of data tables into a first data table set and a second data table set according to the query term; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
removing data table information in the second data table set from the query statement, and generating a supplemental condition according to the second data table set;
splicing the supplementing conditions with the query sentences of the removed data table to form new query sentences;
performing data query based on the new query statement;
the query statement carries conditional information;
the method for dividing the plurality of data tables into a first data table set and a second data table set according to the query term comprises the following steps:
dividing the data table directly related to the query term into a first data table set, and dividing the rest data tables into a second data table set;
traversing the data tables in the second data table set, and judging whether connection conditions exist between the traversed data tables and the data tables in the first data table set according to the condition information;
if the connection condition exists, moving the traversed data table to the first data table set to form a new first data table set and a new second data table set;
and for the new second data table set, returning to execute the operation of traversing the data tables in the second data table set, and judging whether the traversed data tables and the data tables in the first data table set have connection conditions according to the condition information until the data tables directly or indirectly related to the query item are divided into the first data table set.
2. The method of claim 1, wherein removing the data table information in the second set of data tables from the query statement and generating supplemental conditions from the second set of data tables comprises:
grouping the data table information in the second data table set according to the condition information to obtain at least one data table group; wherein, there are connection conditions among the data tables in the said data table group;
and sequentially removing data tables from the query statement according to the at least one data table group, and generating at least one supplementary condition according to the at least one data table group.
3. The method of claim 2, wherein sequentially removing data tables from the query statement based on the at least one data table set and generating at least one supplemental condition based on the at least one data table set comprises:
traversing the at least one data table group, removing the data table information in the traversed data table group from the query statement, and generating a supplementary condition according to the traversed data table group.
4. The method of claim 2, wherein concatenating the supplemental condition with the query statement of the removed data table forms a new query statement, comprising:
splicing the supplementing conditions and the query statement of the removal data table through a set field;
if the supplementary conditions comprise two or more than two, splicing the set fields among the supplementary conditions to form a new query statement.
5. The method according to any one of claims 1 or 2 to 4, wherein the supplemental condition is constituted by the removed data table information and condition information corresponding to the removed data table information.
6. A data query device, comprising:
the query statement judging module is used for judging whether the query statement input by the user is a multi-table connection query statement or not and meets the set condition; wherein the setting conditions include: carrying a set keyword and not containing a set function; the query statement comprises a plurality of data table information;
the data table dividing module is used for dividing the plurality of data tables into a first data table set and a second data table set according to the query items when the query statement input by the user is a multi-table connection query statement and meets the set condition; wherein the data tables in the first set of data tables are directly or indirectly related to the query term; the data tables in the second set of data tables are not related to the query term;
the data table information removing module is used for removing the data table information in the second data table set from the query statement and generating a supplement condition according to the second data table set;
the query statement splicing module is used for splicing the supplementing conditions with the query statement of the removal data table to form a new query statement;
the data query module is used for carrying out data query based on the new query statement;
the query statement carries conditional information;
the data table dividing module is specifically configured to:
dividing the data table directly related to the query term into a first data table set, and dividing the rest data tables into a second data table set;
traversing the data tables in the second data table set, and judging whether connection conditions exist between the traversed data tables and the data tables in the first data table set according to the condition information;
if the connection condition exists, moving the traversed data table to the first data table set to form a new first data table set and a new second data table set;
and for the new second data table set, returning to execute the operation of traversing the data tables in the second data table set, and judging whether the traversed data tables and the data tables in the first data table set have connection conditions according to the condition information until the data tables directly or indirectly related to the query item are divided into the first data table set.
7. A computer device, comprising: a memory and one or more processors;
the memory is used for storing one or more programs;
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the data query method of any of claims 1-5.
8. A storage medium containing computer executable instructions which, when executed by a computer processor, are for performing the data query method of any of claims 1-5.
CN202110873375.9A 2021-07-30 2021-07-30 Data query method, device, equipment and storage medium Active CN113535756B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110873375.9A CN113535756B (en) 2021-07-30 2021-07-30 Data query method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110873375.9A CN113535756B (en) 2021-07-30 2021-07-30 Data query method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113535756A CN113535756A (en) 2021-10-22
CN113535756B true CN113535756B (en) 2023-05-30

Family

ID=78089945

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110873375.9A Active CN113535756B (en) 2021-07-30 2021-07-30 Data query method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113535756B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107315790A (en) * 2017-06-14 2017-11-03 腾讯科技(深圳)有限公司 A kind of optimization method and device of irrelevant subquery
CN107784030A (en) * 2016-08-31 2018-03-09 华为技术有限公司 A kind of method and device for handling Connection inquiring
CN109508339A (en) * 2018-11-12 2019-03-22 上海达梦数据库有限公司 A kind of data query method, apparatus, terminal device and storage medium
CN109947804A (en) * 2019-03-20 2019-06-28 上海达梦数据库有限公司 Optimization method, device, server and the storage medium of data acquisition system inquiry
CN109947791A (en) * 2019-03-27 2019-06-28 上海达梦数据库有限公司 A kind of database statement optimization method, device, equipment and storage medium
CN110222071A (en) * 2019-06-06 2019-09-10 上海达梦数据库有限公司 A kind of data query method, apparatus, server and storage medium
CN110471935A (en) * 2019-08-15 2019-11-19 上海达梦数据库有限公司 A kind of execution method, apparatus, equipment and the storage medium of data manipulation
CN110555035A (en) * 2018-05-31 2019-12-10 阿里巴巴集团控股有限公司 Method and device for optimizing query statement
CN112732752A (en) * 2021-01-29 2021-04-30 上海达梦数据库有限公司 Query statement optimization method, device, equipment and storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107784030A (en) * 2016-08-31 2018-03-09 华为技术有限公司 A kind of method and device for handling Connection inquiring
CN107315790A (en) * 2017-06-14 2017-11-03 腾讯科技(深圳)有限公司 A kind of optimization method and device of irrelevant subquery
CN110555035A (en) * 2018-05-31 2019-12-10 阿里巴巴集团控股有限公司 Method and device for optimizing query statement
CN109508339A (en) * 2018-11-12 2019-03-22 上海达梦数据库有限公司 A kind of data query method, apparatus, terminal device and storage medium
CN109947804A (en) * 2019-03-20 2019-06-28 上海达梦数据库有限公司 Optimization method, device, server and the storage medium of data acquisition system inquiry
CN109947791A (en) * 2019-03-27 2019-06-28 上海达梦数据库有限公司 A kind of database statement optimization method, device, equipment and storage medium
CN110222071A (en) * 2019-06-06 2019-09-10 上海达梦数据库有限公司 A kind of data query method, apparatus, server and storage medium
CN110471935A (en) * 2019-08-15 2019-11-19 上海达梦数据库有限公司 A kind of execution method, apparatus, equipment and the storage medium of data manipulation
CN112732752A (en) * 2021-01-29 2021-04-30 上海达梦数据库有限公司 Query statement optimization method, device, equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于关系型数据库中SQL语句优化规则的研究;龚成鹏;《中国优秀硕士学位论文全文数据库 信息科技辑》;全文 *

Also Published As

Publication number Publication date
CN113535756A (en) 2021-10-22

Similar Documents

Publication Publication Date Title
JP4644420B2 (en) Method and machine-readable storage device for retrieving and presenting data over a network
CN108804554B (en) Database query method, database query device, server and storage medium
CN110515973B (en) Data query optimization method, device, equipment and storage medium
CN104636478A (en) Information query method and device
JP5616444B2 (en) Method and system for document indexing and data querying
CN110968593B (en) Database SQL statement optimization method, device, equipment and storage medium
CN110362593B (en) Data query method, device, equipment and storage medium
WO2007085187A1 (en) Method of data retrieval, method of generating index files and search engine
CN107783985B (en) Distributed database query method, device and management system
CN102541631B (en) Execution plans with different driver sources in multiple threads
WO2021259217A1 (en) Data association query method and apparatus, and device and storage medium
CN109299101B (en) Data retrieval method, device, server and storage medium
CN112732752A (en) Query statement optimization method, device, equipment and storage medium
CN110019380B (en) Data query method, device, server and storage medium
CN111309753A (en) Method, device and equipment for optimizing structured query statement and storage medium
CN112199390B (en) Data query method, device, equipment and storage medium in database
CN113946600A (en) Data query method, data query device, computer equipment and medium
CN110990423B (en) SQL statement execution method, device, equipment and storage medium
CN113535756B (en) Data query method, device, equipment and storage medium
CN109753520B (en) Semi-connection query method, device, server and storage medium
CN116049232A (en) Sub-query extraction method, sub-query extraction device, electronic equipment and storage medium
WO2021103859A1 (en) Information search method, apparatus and device, and storage medium
CN114238387A (en) Data query method and device, electronic equipment and storage medium
CN112765286A (en) Query method and device based on relational database
CN111552856A (en) Microblog public opinion propagation path analysis method

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