[go: up one dir, main page]

CN113836166A - Database query method and device - Google Patents

Database query method and device Download PDF

Info

Publication number
CN113836166A
CN113836166A CN202010592569.7A CN202010592569A CN113836166A CN 113836166 A CN113836166 A CN 113836166A CN 202010592569 A CN202010592569 A CN 202010592569A CN 113836166 A CN113836166 A CN 113836166A
Authority
CN
China
Prior art keywords
values
query
field
main
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.)
Granted
Application number
CN202010592569.7A
Other languages
Chinese (zh)
Other versions
CN113836166B (en
Inventor
张美�
屈四宝
慕明磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Cloud Computing Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202010592569.7A priority Critical patent/CN113836166B/en
Publication of CN113836166A publication Critical patent/CN113836166A/en
Application granted granted Critical
Publication of CN113836166B publication Critical patent/CN113836166B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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/2455Query execution
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

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

Abstract

The application relates to the technical field of databases, and discloses a database query method and device, which are used for providing a database query mode. The method comprises the following steps: first, a first query statement for querying the number of main values is obtained. The first query statement is then converted into a second query statement for querying a number of non-primary values, the primary values and the non-primary values being different field values for the same query field. Next, the number of non-primary values is queried according to the second query statement. And finally, determining the number of the main values according to the number of the field values of the query field and the number of the non-main values.

Description

Database query method and device
Technical Field
The embodiment of the application relates to the technical field of databases, in particular to a database query method and device.
Background
In recent years, with the continuous development of information technology, databases have been widely used as a medium for storing mass data. In actual scene application, most operations of a user relate to data query. When the data in the database reaches millions and tens of millions, one query operation usually needs to wait for tens of seconds or more, thereby bringing bad experience to users.
How to query data in a database is a technical problem to be solved.
Disclosure of Invention
The embodiment of the application provides a database query method and a database query device, which are used for providing a database query mode.
In a first aspect, a method for querying a database is provided. First, a first query statement for querying the number of main values is obtained. The first query statement is then converted into a second query statement for querying a number of non-primary values, the primary values and the non-primary values being different field values for the same query field. Next, the number of non-primary values is queried according to the second query statement. And finally, determining the number of the main values according to the number of the field values of the query field and the number of the non-main values, namely subtracting the number of the non-main values from the number of the field values to obtain the number of the main values.
In this embodiment, when the number of main values is to be queried, the number is converted into the number of query non-main values, and the number of main values is obtained by using the number of field values of the query field and the number of non-main values. Therefore, a new database query mode is provided.
In one possible implementation, the ratio between the number of main values and the number of field values of the query field to which the main values belong is greater than 50% in the database. In this embodiment, it is limited that the number of non-primary values of one query field is less than the number of primary values, and thus, when the number of query primary values is converted into the number of query non-primary values, the query time can be reduced, and the efficiency of data query is improved.
In one possible implementation, the first query statement may be used to query a main value B1The number of (2); then the obtaining may be when converting the first query statement into a second query statement for querying a number of non-primary values
Figure BDA0002556232350000011
I.e. a second query statement is obtained.
Further, when determining the number of dominant values according to the number of field values of the query field and the number of non-dominant values, the number of dominant values may be determined according to:
Figure BDA0002556232350000012
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000013
I.e., the number of field values of the query field recorded in the database.
In one possible implementation, the first query statement may be used to query two main values B1And B2The number of (2); then the obtaining may be when converting the first query statement into a second query statement for querying a number of non-primary values
Figure BDA0002556232350000014
And
Figure BDA0002556232350000015
i.e. a second query statement is obtained.
Further, when determining the number of dominant values according to the number of field values of the query field and the number of non-dominant values, the number of dominant values may be determined according to:
Figure BDA0002556232350000016
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000021
And
Figure BDA0002556232350000022
the number of the cells.
In one possible implementation, the first query statement is used to query three main values B1、B2And B3The number of (2); then the first query statement is converted for lookupWhen querying the second query statement of the number of non-primary values, it may be to obtain
Figure BDA0002556232350000023
Figure BDA0002556232350000024
And
Figure BDA0002556232350000025
i.e. a second query statement is obtained.
Further, when determining the number of the primary values according to the number of the field values of the query field and the number of the non-primary values, the number of the primary values may be determined according to:
Figure BDA0002556232350000026
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000027
And
Figure BDA0002556232350000028
the number of the cells.
In one possible implementation, before converting the first query statement into a second query statement for querying the number of non-primary values, it may be determined whether the query fields in the first query statement all have an index; and/or determining whether the query fields in the first query statement all belong to an exact query. If both have indices and/or both belong to a fine query, then a subsequent step of converting the first query statement into a number of second query statements for querying non-primary values is performed.
In one possible implementation, the first query statement may further include: the first condition, then the first query statement may be used to query the number of primary values under the first condition. The second query statement may further include: the first condition, then the second query statement is used to query the number of non-primary values under the first condition. Then, the number of non-primary values under the first condition is queried according to the second query statement. Finally, the number of main values under the first condition can be determined according to the number of field values of the query field under the first condition and the number of non-main values under the first condition, that is, the number of field values under the first condition is subtracted by the number of non-main values under the first condition to obtain the number of main values under the first condition. The first condition here may be a non-primary value of a certain field.
In one possible implementation, if the first query statement queries a main value B under a first condition C1The number of (2); then when converting the first query statement to a second query statement, it may be to obtain
Figure BDA0002556232350000029
Further, when determining the number of dominant values under the first condition according to the number of field values of the query field under the first condition and the number of non-dominant values under the first condition, the method may further include:
Figure BDA00025562323500000210
determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is C (i.e. the number of the main values under the first condition is C
Figure BDA00025562323500000211
The number of the cells.
In one possible implementation, two main values B under a first condition C are queried if the first query statement1And B2The number of (2); then when converting the first query statement to a second query statement, it may be to obtain
Figure BDA00025562323500000212
And
Figure BDA00025562323500000213
further, when determining the number of dominant values under the first condition according to the number of field values of the query field under the first condition and the number of non-dominant values under the first condition, the method may further include:
Figure BDA00025562323500000214
determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is C (i.e. the number of the main values under the first condition is C
Figure BDA00025562323500000215
) The number of the cells.
In one possible implementation, if a field value corresponding to the query field includes a plurality of sub-field values, when at least one of the plurality of sub-field values is a main value or an entirety of the plurality of sub-field values is a main value, the field value corresponding to the query field is determined to be the main value.
In a second aspect, there is provided an apparatus for querying a database, the apparatus having the functionality of any one of the above-mentioned first aspect and possible implementations of the first aspect. These functions may be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more functional modules corresponding to the above functions.
In a third aspect, a computer program product is provided, the computer program product comprising: computer program code for causing a computer to perform the method as performed in the first aspect and any one of the possible implementations of the first aspect when said computer program code is run on a computer.
In a fourth aspect, the present application provides an apparatus for querying a database, the apparatus comprising a processor and a memory, the processor and the memory being electrically coupled to each other; the memory to store computer program instructions; the processor is configured to execute part or all of the computer program instructions in the memory, and when the part or all of the computer program instructions are executed, the processor is configured to implement the functions of the method according to any one of the above-mentioned first aspect and the first possible implementation of the first aspect.
Drawings
FIG. 1 is a schematic diagram of a data query process provided in an embodiment of the present application;
fig. 2 is a structural diagram of an inquiry apparatus of a database provided in an embodiment of the present application;
fig. 3 is a structural diagram of an inquiry apparatus of a database provided in an embodiment of the present application.
Detailed Description
The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
In order to facilitate understanding of the embodiments of the present application, some terms of the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
1) "things" in a collection, called elements. The whole made up of one or more determined elements is called a set. If x is an element of the set A, then it is written as x ∈ A. The elements in a collection have three characteristics: certainty (the elements in the set must be certain); reciprocity (elements in a set are different from each other), such as: the set a is {1, a }, then a cannot equal 1); disorder (elements in a set do not succeed), such as: the sets 3, 4, 5 and 3, 5, 4 are counted as one set.
2) And adding a horizontal line on the set letter to represent a complementary set of the set letter, namely all elements which do not belong to the set letter. For example, collections
Figure BDA0002556232350000031
Is set A1The complement of (c).
3) And the theory of volume repulsion: the counting method is characterized in that the overlapping condition is not considered, the number of all objects contained in a certain content is calculated, and then the number repeatedly calculated during counting is excluded, so that the calculated result is not missed or repeated.
Example 1: if the things to be counted are of A, B types, the sum of the numbers of the elements belonging to the A type and the B type-the numbers of the elements belonging to both the A type and the B type-i.e. A ═ B ═ A + B-A ≈ B.
Example 2: if the counted things have A, B, C types, then the sum of the numbers of the elements of the A type, the B type and the C type is equal to the number of the elements of the A type + the number of the elements of the B type + the number of the elements of the C type-the number of the elements of both the A type and the B type-the number of the elements of both the B type and the C type + the number of the elements of both the A type and the B type and the C type, i.e. A U B U C is equal to A + B C-A U B-B U C-U A + A U B U C.
4) An index is a structure that sorts (values of) one or more columns in a database table, and specific information in the database table can be quickly accessed by using the index. For example, the name (name) column suggests an index that helps to get information faster than searching all rows in a table if one wants to look up a particular employee by his or her last name.
"and/or" in the present application, describing an association relationship of associated objects, means that there may be three relationships, for example, a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
The plural in the present application means two or more.
In the description of the present application, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying relative importance, nor order.
In addition, in the embodiments of the present application, the word "exemplary" is used to mean serving as an example, instance, or illustration. Any embodiment or implementation described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments or implementations. Rather, the term using examples is intended to present concepts in a concrete fashion.
For convenience of understanding of the embodiment of the present application, an application scenario of the present application is introduced next, and the service scenario described in the embodiment of the present application is for more clearly explaining the technical solution of the embodiment of the present application, and does not constitute a limitation to the technical solution provided in the embodiment of the present application.
As shown in Table 1, a data table in a database is provided, for example, taking MySQL relational database as an example, the name of the data table is table, the data table includes m fields, respectively ci(i∈[1,m]) Each row under a field records the field value corresponding to the field, and the row number recorded in table 1 is the total number of all field values corresponding to the field.
Figure BDA0002556232350000041
TABLE 1
The field c1 may be, for example, "name", the field c2 may be, for example, "age", the field c3 may be, for example, "gender", and the field c4 may be, for example, "province", … …. For the field "age", its corresponding field value recorded in the data table may be, for example, "18", "19", "20", etc. For the field "name", the corresponding field value recorded in the data table may be "zhang san", "lie si", or the like, for example. For the field "gender", its corresponding field value recorded in the data table may be "female", "male", etc., for example. For the field "province", the corresponding field value recorded in the data table may be, for example, "north Hezhou province", "Tianjin", "Beijing", "south Henan province", and the like. In this application, a field value may also be referred to as a field value.
For example, 100 lines are recorded, and of these 100 lines, there are 70 lines "male" and 30 lines "female" for "gender".
For another example, in the 100 rows, there are 30 behaviors "18", 30 behaviors "19", and 40 behaviors "20" for age.
For another example, in the 100 rows, there are 20 behaviors "beijing" and 80 behaviors "hebei" for provinces.
In the m fields, there may be k fields to establish an index, where k is less than or equal to m and greater than mOr an integer equal to 0. The k index-establishing fields are cK respectively1,cK2,…,cKkFor example, i (cK) ═ { cK ═ cK can be mentioned1,cK2,...,cKk}. For example, the field c1 "province", the field c2 "age", the field c3 "gender" all index, and the field c4 "name" does not index.
In the k index-establishing fields, there are s fields whose values (i.e., field values) are enumerable (i.e., a limited number, e.g., h), where s is an integer less than or equal to k and greater than or equal to 0. The s fields are respectively cS1,cS2,…,cSSFor example, i (cS) ═ cS can be mentioned1,cS2,...,cSS}. For example, values of the field c1 "province", the field c2 "age", and the field c3 "gender" are enumerable.
The values of these s fields belong to a set of values V (cS)l) I.e. cSl(l∈[1,s]) All values of (A) belong to V (cS)l)。
For example, V (cS)2)={cS2_value1,cS2_value2,...,cS2_valueh};
V(cSl)={cSl_value1,cSl_value2,...,cSl_valuehH is an integer of 0 or more.
When a field value of a field has more than half of the total number of rows recorded in the data table, the number of rows recorded in the data table is the same as the number of rows recorded in the data table. It is also understood that in the database, the ratio between the number of the main values and the number of field values of the query field to which the main values belong is greater than 50%.
For example, the number of rows recorded in the data table for the field "gender" is 100 rows, in the 100 rows, 70 rows are recorded in the field value "male", and 30 rows are recorded in the field value "female", so that the field value "male" exceeds 50%, and the field value "gender" can be regarded as the main value.
For another example, in the 100 rows, the field value "18" has 30 rows, the field value "19" has 30 rows, and the field value "20" has 40 rows for the age, and this field "age" has no main value.
For another example, in the 100 rows, for province, there are 20 rows of the field value "beijing", 80 rows of the field value "hebei", and the field value "hebei" is the main value of the field "province".
Of course, when determining which field value is the main value, 50% may be used as a reference standard, or any value of 50% -100% may be used as a reference standard, for example, 70%, 75%, 80%, 82%, etc. may be used as a reference standard. Taking 80% as an example, in the field cSlIn (1), there is a certain value cSl_valueT(T∈[1,h]) Satisfies the two-eight principle, i.e. field cSlMiddle, field value cSl_valueTRecording the number of lines in the data tablelThe ratio of the total number of rows recorded in the data sheet is greater than or equal to 80%, i.e.
Figure BDA0002556232350000051
The field value cS is addedl_valueTRecorded as field cSlThe main value of (2).
In the present application, the field word of each field to be queried in the database statistics data query statement may or may not be a main value.
The following first describes a case where the field value of each field to be queried in a query statement is a main value: illustratively, the database statistics query statement is:
select count(*)from table where cS1 in A(cS1)
and cS2 in A(cS2)
...and cSs in A(cSs)。
wherein, the table is the name of a certain data table in the database. The query conditions in the data query statement are: cS1 in A(cS1)and cS2in A(cS2)...and cSs in A(cSs). Wherein, cS1 inA(cS1),cS2in A(cS2),……,cSs in A(cSs) May be considered as one of the sub-query conditions in the query. in indicates the precise query of the value of the field, and the field cSlHas a field value of A (cS)l),(l∈[1,s]) The field value may include, for example, a main value cSl_valueTThe field value may include a non-dominant value in addition to a dominant value, such as Note A (cS)l)=(...,cSl_valueT,...)。
For example, cS3The field "province", A (cS)3) Field value indicating the province to be queried, e.g. query "Hebei", then cS3_valueT"hebei" may be represented, and the field values corresponding to the provinces recorded in the data table include "beijing" and "hebei", where "hebei" is the main value of the province.
As another example, cS2Indicates the field "sex", A (cS)2) A field value indicating the sex to be queried, e.g. query "male", then cS2_valueT"male" may be represented, and the field values corresponding to genders recorded in the data table include "female" and "male", where "male" is the main value of age.
The query condition refers to the field cS to be queriedl(l∈[1,s]) Middle of the set of qualifying conditions A (cS)l) The total number of data of (c) can also be understood as satisfying the condition set A (cS)l) The number of rows of (c).
For example, for the query condition: cS1 in A(cS1)and cS2 in A(cS2)...and cSs in A(cSs) According to cS1 in A(cS1) Query set A1 according to cS2 in A(cS2) Query set A2, … …, according to cSs in A(cSs) The set As is looked up.
For the sets a1, a2, … …, As, the following transformations can be made by the principle of repulsion:
Figure BDA0002556232350000071
wherein,
Figure BDA0002556232350000072
representation set AiComplement of, n represents intersection, (-1)(s)Represents the power s of-1 and sigma represents the summation.
For example, when s is 1,
Figure BDA0002556232350000073
as another example, when s is 2,
Figure BDA0002556232350000074
as another example, when s is 3,
Figure BDA0002556232350000075
as described above, the main value of the field is that the number of rows of the main value recorded in the data table exceeds half of the total number of rows of the field recorded in the data table, and if the query is performed according to the main value of the field, the content to be queried is more, and the efficiency of data query is lower. Based on this, referring to table 2, the query conditions in the query statement are transformed by the same principle by reasoning according to the above-described process of transforming the query results a1, a2, … …, As by the repulsion principle. That is, when querying the main value, the number of main values to be queried is determined by querying the number of non-main values (i.e. the complement of the main values) in combination with the number of field values, so as to improve the query efficiency.
For example, the number of rows recorded in the data table for the field "gender" is 100 rows, and in the 100 rows, the field value "male" has 70 rows recorded and the field value "female" has 30 rows recorded. The field value "male" is a main value of gender. To query the number of males, the number of females may be queried, and then the number of females queried 30, i.e., the number of males to be queried 70, may be subtracted from the number of field values of "gender" 100. When inquiring for 'woman', only 30 lines are required to be inquired, and the inquiry efficiency can be improved compared with the inquiry of 70 lines corresponding to 'man'.
The database statistics data query conditions and the repulsion principle conditions are corresponding to a table 2.
Figure BDA0002556232350000076
Figure BDA0002556232350000081
Table 2 based on the repulsion principle transformation in table 2, the query condition may be converted as follows:
Figure BDA0002556232350000082
wherein,
Figure BDA0002556232350000083
V(cSs) Is field cSsA full set of field values. In addition, it should be noted that the query condition before the equal sign contains a field, and for convenience of description, the query condition after the equal sign filters out the field, for example, a (cS)s) Is actually field cSsThe value of (1).
In a database query, due to the field cSsCondition set A (cS) ofs) Containing the main value cSl_valueTThe main value may be, for example, a field value conforming to the twenty-eight principle. Therefore, it is not only easy to use
Figure BDA0002556232350000084
Database statistical query performance of combined conditions is superior to A (cS)s) Combining conditional queries, i.e.
Figure BDA0002556232350000085
Combined conditional query time
Figure BDA0002556232350000086
Less than A (cS)s) Combined conditional query T (A (cS)s))。
For example, by
Figure BDA0002556232350000087
Combined conditional query time
Figure BDA0002556232350000088
Has a maximum value of
Figure BDA0002556232350000089
Then when
Figure BDA00025562323500000810
Combining conditional queries to perform tasks in parallel (ignoring other system time overhead), increasing efficiency η1Is composed of
Figure BDA00025562323500000811
For example, table 3 below records the test results of performance tests performed on data tables with different numbers of recording lines, unit/s, when s is 2.
Figure BDA00025562323500000812
Figure BDA0002556232350000091
TABLE 3
As can be seen from Table 3, A (cS)s) Combined conditional query time T (A (cS)s) Is A)1∩A2The corresponding time.
Figure BDA0002556232350000092
Combined conditional query time
Figure BDA0002556232350000093
The method comprises the following steps: 1-1 corresponds to a time period,
Figure BDA0002556232350000094
the corresponding time is the time at which the user is expected to be,
Figure BDA0002556232350000095
the corresponding time is the time at which the user is expected to be,
Figure BDA0002556232350000096
the corresponding time. Due to the fact that
Figure BDA0002556232350000097
If the combined conditions are parallel queries, only the maximum value is concerned
Figure BDA0002556232350000098
And (4) finishing. For example, when 100 ten thousand are recorded in the data amount, if according to A (cS)s) Conditional query sets A1∩A2Time T (A (cS)s) 10.501 s). If transformed
Figure BDA0002556232350000099
When the query is carried out by combining the query conditions, 2.025s is needed at most, and the query efficiency is improved by 81%. The more data volume is recorded, the greater the promotion efficiency.
With reference to the above description, referring to the example of fig. 1, a query process of a database is described, which specifically includes the following steps:
step 101: a first query statement is obtained for querying a quantity of the primary values.
Typically, in a database, the ratio between the number of main values and the number of field values of the query field to which the main values belong is greater than 50%.
The format of the query statement is introduced above, and the query is performed on one data table, where the first query statement may also be performed on one data table in the database, and optionally, for convenience of description, the following database may represent a certain data table in the database.
The first query statement may be used to query for a main value or a number of main values. As described aboveA (cS) has been adopted2)A(cS2) To describe the main value, B is used in place of A (cS) in the following for ease of understanding2) B1 can be regarded as A (cS) as described above1) B2 can be regarded as A (cS) as described above2) … …, and so on.
Step 102: converting the first query statement into a second query statement for querying a number of non-primary values, the primary values and the non-primary values being different field values for a same query field.
The following steps 102a and 102b may also be performed before converting the first query statement into a second query statement for querying the number of non-primary values.
Step 102 a: determining whether the query fields in the first query statement all have an index. If the index exists, the execution can be continued, and if the index does not exist, the data query can be performed according to the first query statement in step 101.
Step 102 b: determining whether the query fields in the first query statement all belong to an exact query. If the query statements belong to the fine query, the execution can be continued downwards, and if the query statements do not belong to the fine query (i.e. the fuzzy query), the data query can be performed according to the first query statement in step 101.
The steps 102a and 102b are optional steps, and the sequence is not limited.
Through the step 102a, the fields with indexes can be queried, and the query efficiency is improved.
Through the step 102b, fine query can be performed on the field, and the query precision is improved.
Step 103: and querying the number of the non-main values according to the second query statement.
Step 104: and determining the number of the main values according to the number of the field values of the query field and the number of the non-main values. For example, the number of the non-dominant values is subtracted from the number of field values of the query field to determine the number of dominant values.
Number of field values of the query field here (i.e., the mnemonic of the database)Number of rows of a record) may be already saved in the database without being queried through a query statement, in which case the time required to obtain the number of field values may be considered to be 0. For example, in the example of table 3, if the time corresponding to 1 is infinitely close to 0, then when 100 ten thousand data volumes are recorded, if a (cS) is counteds) Conditional query sets A1∩A2Time T (A (cS)s) 10.501 s). If transformed
Figure BDA0002556232350000101
When the query is carried out by combining the query conditions, 0.588s is needed at most, and the query efficiency is improved by 99%.
Of course, the number of field values of the query field may also be found by the query statement, for example, the second query statement may include all field values of the query field, and then the second query statement may also query the number of field values of the query field; or the number of field values of the query field queried by other query statements.
In one example, the first query statement may be used to query a main value B1The number of (2); then the obtaining may be when converting the first query statement into a second query statement for querying a number of non-primary values
Figure BDA0002556232350000102
I.e. a second query statement is obtained.
Further, when determining the number of dominant values according to the number of field values of the query field and the number of non-dominant values, the number of dominant values may be determined according to:
Figure BDA0002556232350000103
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000104
I.e., the number of field values of the query field recorded in the database.
For example, there are 100 rows in the database;
for gender, the field value "male" has 70 rows and the field value "female" has 30 rows, and the field value "male" is the main value of the field "gender".
For age, the field value "18" has 30 rows, the field value "19" has 30 rows, the field value "20" has 40 rows, and the field "age" has no main value.
For provinces, 20 rows are provided for the field value "Beijing", and 80 rows are provided for the field value "Hebei", so that the field value "Hebei" is the main value of the field "provinces".
For example, a first query statement is to query for "male" (B)1) Since "man" is the main value, the second query statement can query "woman"
Figure BDA0002556232350000105
Then the number of "women" is subtracted from the number of field values of gender of 100 to obtain the number of "men" of 70.
In one example, the first query statement may be used to query two main values B1And B2The number of (2); then the obtaining may be when converting the first query statement into a second query statement for querying a number of non-primary values
Figure BDA0002556232350000111
And
Figure BDA0002556232350000112
i.e. a second query statement is obtained.
Further, when determining the number of dominant values according to the number of field values of the query field and the number of non-dominant values, the number of dominant values may be determined according to:
Figure BDA0002556232350000113
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000114
And
Figure BDA0002556232350000115
the number of the cells.
In connection with the above example, as another example, the first query statement is to query the number of "men in north of river", and since "men" is the main value and "north of river" is the main value, the second query statement may query the number of "women", the number of "beijing", and the number of "women in beijing". Then, the number of field values for gender was taken as 100, minus "woman"
Figure BDA0002556232350000116
30, minus "Beijing"
Figure BDA0002556232350000117
20, minus "Beijing women"
Figure BDA0002556232350000118
The number of the male in Hebei can be obtained.
In one example, the first query statement is for querying three main values B1、B2And B3The number of (2); then the obtaining may be when converting the first query statement into a second query statement for querying a number of non-primary values
Figure BDA0002556232350000119
Figure BDA00025562323500001110
And
Figure BDA00025562323500001111
i.e. a second query statement is obtained.
Further, when determining the number of the primary values according to the number of the field values of the query field and the number of the non-primary values, the number of the primary values may be determined according to:
Figure BDA00025562323500001112
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA00025562323500001113
And
Figure BDA00025562323500001114
the number of the cells.
If the first query statement is to query for a number of 4, 5, or even more primary values, analogy can be made according to the above principles, and the illustration is not repeated here.
In addition, it should be noted that, if a field value corresponding to the query field includes a plurality of sub-field values, when at least one of the plurality of sub-field values is a main value or an entirety of the plurality of sub-field values is a main value, the field value corresponding to the query field is determined to be the main value.
For example, for the query field "age", the field values to be queried include sub-field values "17" and "18". "17" and "18" can be considered as a whole, and these two subfield values are considered as the main values of the field age.
Optionally, when the first query statement is obtained in the present application, it may be analyzed in advance whether the first query statement includes a main value, which field value is the main value, and which field value is not the main value. For example, it may be determined which field values in the first query statement are the main values and which are not the main values according to a predetermined statistical report. It may be determined which field value in the first query statement is the main value and which is not the main value, based on the saved field value as the main value. The saved field value as the main value may be saved after being queried according to a previous query statement. I.e., the field value was previously queried.
In another embodiment of the present application, the first query statement may further include: the first condition, then the first query statement may be used to query the number of primary values under the first condition. The second query statement may further include: the first condition, then the second query statement is used to query the number of non-primary values under the first condition. Then, the number of non-primary values under the first condition is queried according to the second query statement. Finally, the number of main values under the first condition can be determined according to the number of field values of the query field under the first condition and the number of non-main values under the first condition, that is, the number of field values under the first condition is subtracted by the number of non-main values under the first condition to obtain the number of main values under the first condition. The first condition here may be a non-primary value of a certain field.
In one example, if the first query statement queries a main value B under a first condition C1The number of (2); then when converting the first query statement to a second query statement, it may be to obtain
Figure BDA0002556232350000121
Further, when determining the number of dominant values under the first condition according to the number of field values of the query field under the first condition and the number of non-dominant values under the first condition, the method may further include:
Figure BDA0002556232350000122
determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is the number of C. That is to say according to
Figure BDA0002556232350000123
Determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is
Figure BDA0002556232350000124
The number of the cells.
For example, a first query statement is to query for the number of "men" aged 17, where aged 17 is the first condition C. Due to "male" (B)1) Being a dominant value, the second query statement may query for "women" aged 17 "
Figure BDA0002556232350000125
The number of the cells. Then the number of 17-year-old owners (C) was used, minus the 17-year-old "women"
Figure BDA0002556232350000126
The number of "men" of 17 years old is obtained.
In one example, if the first query statement queries two main values B under a first condition C1And B2The number of (2); then when converting the first query statement to a second query statement, it may be to obtain
Figure BDA0002556232350000127
And
Figure BDA0002556232350000128
further, when determining the number of dominant values under the first condition according to the number of field values of the query field under the first condition and the number of non-dominant values under the first condition, the method may further include:
Figure BDA0002556232350000129
determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is the number of C. That is according to:
Figure BDA00025562323500001210
determining the number of main values under a first condition, wherein the number of field values of the query field under the first condition is
Figure BDA00025562323500001211
The number of the cells.
For another example, the first query statement is to query the number of "men in north of river" of age 17, where age 17 is the first condition. Due to "male" (B)1) Is a main value, "HebeiB2) Being a dominant value, the second query statement may query for "women" aged 17 "
Figure BDA00025562323500001212
Number of (1) ("Beijing" at 17 years old) "
Figure BDA00025562323500001213
And 17 years old "Beijing women"
Figure BDA00025562323500001214
The number of the cells. Then the number of 17-year-old owners (C) was used, minus the 17-year-old "women"
Figure BDA00025562323500001215
The amount of (2) minus 17 years old of "Beijing"
Figure BDA00025562323500001216
The number of the Chinese medicinal herbs, minus 17 years old 'Beijing women'
Figure BDA00025562323500001217
The number of "Hebei men" of 17 years old can be obtained.
Reference is now made to the foregoing examples, as well as to the foregoing description
Figure BDA00025562323500001218
A combination condition specifying a query statement including a first condition:
the first query statement is as follows: the field values of one part of fields comprise main values, and the field values of the other part of fields are all non-main values:
select count(*)from table where cS1 in A(cS1)
and cS2 in A(cS2)...and cSs inA(cSs)
and cond(I(cK)-I(cS))。
the foregoing has described: cS1 inA(cS1),cS2 in A(cS2),……,cSs in A(cSs) May be considered as one of the sub-query conditions in the query. Wherein in represents the precise query of the value of the field, and the field cSlHas a field value of A (cS)l),(l∈[1,s]) The field value may include, for example, a main value cSl_valueTThe query field value may include a non-main value in addition to a main value, such as a note A (cS)l)=(...,cSl_valueT,...)。
It should be further introduced that cond (i (cK) -i (cs)) may be understood as a field to be queried in the query statement as i (cK) { cK) } cK1,cK2,...,cKk]Wherein the field containing the main value is i (cS) ═ cS1,cS2,...,cSS]And cond (i (ck) -i (cs)) may represent a set of field values to be queried corresponding to the remaining fields except for the field containing the main value among the fields to be queried.
For example, "a junior middle school male aged 17 to north of river" is to be queried in the query sentence. The field value "male" is the main value of the field "gender", the field value "north of river" is the main value of the field "province", the field value "17" is not the main value of the field "age", and the field value "junior" is not the main value of the field "academic calendar". Then i (ck) ═ age, gender, province, academic, i (cs) = { gender, province ], cond (i (ck) -i (cs)) includes field value "17" of field "age" and field value "birth" of field "academic.
Based on the repulsion principle already described above, the following transformation can be performed on the query condition in the query statement:
Figure BDA0002556232350000131
in this transformation, since none of the field values included in cond (i (ck) -i (cs)) is a main value, the field values can be kept unchanged without being queried in a complementary manner.
Due to the field cSsField value set A (cS)s) Containing the main value cSl_valueTTherefore, it is
Figure BDA0002556232350000132
Database statistics for Cond (I (cK) -I (cS)) combination conditions query statements perform better than A (cS)s) And cond (I (cK) -I (cS)) combined query condition performance. Namely, it is
Figure BDA0002556232350000141
And cond (I (cK) -I (cS)) combined conditional query time:
Figure BDA0002556232350000142
cond (I (cK) -I (cS))) less than A (cSs) And cond (I (cK) -I (cS)) combined conditional query T (cond (A (cS))s)),cond(I(cK)-I(cS)))。
For example, by
Figure BDA0002556232350000143
And cond (I (cK) -I (cS)) combination of the query time of the maximum value
Figure BDA0002556232350000144
Then when
Figure BDA0002556232350000145
And cond (I (cK) -I (cS)) combined condition query to improve the efficiency eta by executing parallel tasks (ignoring other system time overhead)2Comprises the following steps:
Figure BDA0002556232350000146
the following describes the process of data query and the improvement of efficiency by using an example of an actual structure.
The data table name is test, and has 3 fields, which are id, enumpam 1 and enumpam 2. These three fields id, enum param1 and enum param2 are indexed.
For example, the data table test records:
Figure BDA0002556232350000147
that is, the field value of the field "enumpan 1" in the data table test includes "online" and "offline", and the field value of the field "enumpan 2" includes "success" and "failed" and "running".
The field value recorded for the integer row of the field "enum param1, 10 is" offline ", for example, the field values recorded for the 10 th, 20 th, 30 th rows … …, etc. are" offline ", and the field value recorded for the integer row other than 10 is" online ", for example, the field values recorded for the 1 st to 9 th rows, 11 th to 19 th rows, 21 st to 29 th rows, … …, etc. are" online ".
The data constructed in this example is distributed as follows (id is an increasing integer, id may represent the several rows). mod denotes the remainder, and id mod10 is 0, i.e., the remainder is divided by 10 to obtain 0, i.e., the integer row with 10 rows.
Figure BDA0002556232350000148
For the field "enumpam 2", the field value recorded for the integer row of 10 and the integer row other than 19 is "failed", for example, the field values recorded for the rows 10, 20, 1 st to 9 th, 11 th to 18 th, etc. are "failed". The integer row of 19 records a field value of "running", for example, 190 is the integer row of 19 and is also the integer row of 10, and can record a field value of "running". The value of the record field of the integer row other than 10 is "success".
The data constructed in this example is distributed as follows (id is an increasing integer, id may represent the several rows). mod denotes the remainder, and id mod10 is 0, i.e., an integer row with a row number of 10.
Figure BDA0002556232350000151
The query conditions may be, for example:
enum param1in ("online") and enum param2in ("success", "failed"). The 2 (i.e., m ═ 2) sub-query conditions included in the query condition are "enum param1in (" online ")" and "enum param2in (" success "," failed ")" respectively. The sub-query condition enumpan 1in ("online") includes a query field "enuparam 1" with a field value of "online", and the sub-query condition "enumpan 2in (" success "," failed ")" includes a query field "enumpan 2" with a field value of "success" and "failed".
From this, it can be derived that,
Figure BDA0002556232350000152
then the values exist: enumpam 1_ valueTAs "online", and enumpam 2_ valueTIf the query field "enumpam 1" and the query field "enumpam 2" in the query condition satisfy the twenty-eight rule, the field value "online" to be queried is the main value.
For example, according to the principle of repulsion introduced above:
Figure BDA0002556232350000161
and
Figure BDA0002556232350000162
and the number of the first and second groups,
Figure BDA0002556232350000163
it can be derived that:
select count(*)from test where enumParam1 in("online")
and enumpam 2in ("success", "failed"), the corresponding database statistics query statement is as follows:
A1∩A2→sum(enumParam1 in("online")and enumParam2in("success","failed"))
→select count(*)from test where enumParam1 in("online")
and enumParam2 in("success","failed")
Figure BDA0002556232350000171
Figure BDA0002556232350000172
Figure BDA0002556232350000173
Figure BDA0002556232350000174
in addition, it should be noted that, if a field value corresponding to the query field includes a plurality of sub-field values, when at least one of the plurality of sub-field values is a main value or an entirety of the plurality of sub-field values is a main value, the field value corresponding to the query field is determined to be the main value.
For example, for the query field "enumpam 2," the subfield values include "success" and "failed. "success" and "failed" can be considered as a whole, and these two subfield values are considered as the main values of one field.
The efficiency of the improvement can be seen in table 3, and is not repeated. In conclusion, for the database statistical query statement meeting the main value condition of the present application, the query optimization method based on the repulsion principle can effectively improve the database query performance, and particularly, for the data statistical query with large data volume, the system performance can be obviously improved.
In the foregoing, the database query method according to the embodiment of the present application is described, and hereinafter, the database query device according to the embodiment of the present application will be described. The method and the device are based on the same technical conception, and because the principles of solving the problems of the method and the device are similar, the implementation of the device and the method can be mutually referred, and repeated parts are not repeated.
Based on the same technical concept as the query method of the database, as shown in fig. 2, a query device 200 of the database is provided, and the device 200 can execute the steps executed in the method of fig. 1. The apparatus 200 may be an electronic device, and may also be a chip applied to an electronic device. The apparatus 200 may comprise:
an obtaining module 201, configured to obtain a first query statement used for querying the number of main values;
a conversion module 202, configured to convert the first query statement into a second query statement for querying a number of non-main values, where the main value and the non-main value are different field values for a same query field;
a query module 203, configured to query the number of the non-primary values according to the second query statement;
a determining module 204, configured to determine the number of the primary values according to the number of the field values of the query field and the number of the non-primary values.
In one example, the first query statement is used to query a main value B1The number of (2); the conversion module 202, when configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure BDA0002556232350000181
In an example, the determining module 204, when configured to determine the number of primary values according to the number of field values of the query field and the number of non-primary values, is specifically configured to:
according to the following steps:
Figure BDA0002556232350000182
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000183
The number of the cells.
In one example, the first query statement is used to query two main values B1And B2The number of (2); the conversion module 202, when configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure BDA0002556232350000184
And
Figure BDA0002556232350000185
in an example, the determining module 204, when configured to determine the number of primary values according to the number of field values of the query field and the number of non-primary values, is specifically configured to:
according to the following steps:
Figure BDA0002556232350000186
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000187
And
Figure BDA0002556232350000188
the number of the cells.
In one example, the first query statement is for querying three main values B1、B2And B3The number of (2); the conversion module 202, when configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure BDA0002556232350000189
And
Figure BDA00025562323500001810
in an example, the determining module 204, when configured to determine the number of primary values according to the number of field values of the query field and the number of non-primary values, is specifically configured to:
according to the following steps:
Figure BDA00025562323500001811
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA00025562323500001812
And
Figure BDA00025562323500001813
the number of the cells.
In one example, the conversion module 202 is further configured to determine that the query fields in the first query statement each have an index; and/or determining that the query fields in the first query statement all belong to an exact query.
Fig. 3 is a schematic block diagram of a query device 300 according to an embodiment of the present application. It should be understood that the apparatus 300 is capable of performing the various steps performed in the method of fig. 1 described above. The apparatus 300 comprises: the processor 310, optionally, also includes a communication interface 320 and a memory 330. The communication interface may be configured to receive program instructions and transmit the program instructions to the processor, or the transceiver may be configured to perform communication interaction between the apparatus and other communication devices, such as interaction control signaling and/or service data. The communication interface may be a code and/or data read-write transceiver, or the communication interface may be a signal transmission transceiver between the communication processor and the transceiver. The communication interface may be replaced with a transceiver, an interface circuit, or the like. The processor 310 and the memory 330 are electrically coupled.
Illustratively, the memory 330 is for storing a computer program; the processor 310 may be configured to call the computer program or instructions stored in the memory to execute the above-mentioned database query method.
In one example, the processor 310 is configured to obtain a first query statement for querying a number of main values; converting the first query statement into a second query statement for querying a number of non-primary values, the primary values and the non-primary values being different field values for a same query field; querying the number of the non-primary values according to the second query statement; and determining the number of the main values according to the number of the field values of the query field and the number of the non-main values.
In one example, the first query statement is used to query a main value B1The number of (2); when the processor 310 converts the first query statement into a second query statement for querying the number of non-primary values, specifically: obtaining
Figure BDA00025562323500001814
In an example, when determining the number of primary values according to the number of field values of the query field and the number of non-primary values, the processor 310 is specifically configured to: according to the following steps:
Figure BDA0002556232350000191
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000192
The number of the cells.
In one example, the first query statement is used to query two main values B1And B2The number of (2); when the processor 310 converts the first query statement into a second query statement for querying the number of non-primary values, specifically: obtaining
Figure BDA0002556232350000193
Figure BDA0002556232350000194
And
Figure BDA0002556232350000195
in an example, when determining the number of primary values according to the number of field values of the query field and the number of non-primary values, the processor 310 is specifically configured to: according to the following steps:
Figure BDA0002556232350000196
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA0002556232350000197
And
Figure BDA0002556232350000198
the number of the cells.
In one example, the first query statement is for querying three main values B1、B2And B3The number of (2); when the processor 310 converts the first query statement into a second query statement for querying the number of non-primary values, specifically: obtaining
Figure BDA0002556232350000199
And
Figure BDA00025562323500001910
in an example, when determining the number of primary values according to the number of field values of the query field and the number of non-primary values, the processor 310 is specifically configured to:
according to the following steps:
Figure BDA00025562323500001911
determining the number of the main values, wherein the number of the field values of the query field is
Figure BDA00025562323500001912
And
Figure BDA00025562323500001913
the number of the cells.
In one example, the processor 310 is further configured to determine that the query fields in the first query statement each have an index before converting the first query statement into a second query statement for querying the number of non-primary values; and/or determining that the query fields in the first query statement all belong to an exact query.
The processor may be a Central Processing Unit (CPU), a Network Processor (NP), or a combination of a CPU and an NP. The processor may further include a hardware chip or other general purpose processor. The hardware chip may be an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. The aforementioned PLDs may be Complex Programmable Logic Devices (CPLDs), field-programmable gate arrays (FPGAs), General Array Logic (GAL) and other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., or any combination thereof. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will also be appreciated that the memory referred to in the embodiments of the application may be either volatile memory or nonvolatile memory, or may include both volatile and nonvolatile memory. The non-volatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash Memory. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of example, but not limitation, many forms of RAM are available, such as Static random access memory (Static RAM, SRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic random access memory (Synchronous DRAM, SDRAM), Double Data Rate Synchronous Dynamic random access memory (DDR SDRAM), Enhanced Synchronous SDRAM (ESDRAM), Synchronous link SDRAM (SLDRAM), and Direct Rambus RAM (DR RAM). It should be noted that the memory described herein is intended to comprise, without being limited to, these and any other suitable types of memory.
The transceiver, the interface circuit, or the transceiver according to the embodiments of the present application may include a separate transmitter and/or a separate receiver, or may be an integrated transmitter and receiver. The transceiver means, interface circuit or transceivers may operate under the direction of a corresponding processor. Alternatively, the sender may correspond to a transmitter in the physical device, and the receiver may correspond to a receiver in the physical device.
The embodiment of the application also provides a computer storage medium, which stores a computer program, and when the computer program is executed by a computer, the computer can be used for executing the query method of the database.
Embodiments of the present application further provide a computer program product containing instructions, which when run on a computer, enable the computer to execute the database query method provided above.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application 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 application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. 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.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the embodiments of the present application without departing from the spirit and scope of the embodiments of the present application. Thus, if such modifications and variations of the embodiments of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include such modifications and variations.

Claims (20)

1. A method for querying a database, the method comprising:
acquiring a first query statement for querying the number of main values;
converting the first query statement into a second query statement for querying a number of non-primary values, the primary values and the non-primary values being different field values for a same query field;
querying the number of the non-primary values according to the second query statement;
and determining the number of the main values according to the number of the field values of the query field and the number of the non-main values.
2. The method of claim 1, wherein a ratio between the number of primary values and the number of field values of a query field to which the primary values belong is greater than 50% in a database.
3. A method as claimed in claim 1 or 2, wherein the first query statement is used to query for a main value B1The number of (2); the converting the first query statement into a second query statement for querying a number of non-primary values, comprising:
obtaining
Figure FDA0002556232340000011
4. The method of claim 3, wherein said determining the number of dominant values based on the number of field values of the query field and the number of non-dominant values comprises:
according to the following steps:
Figure FDA0002556232340000012
determining the number of the main values, wherein the number of the field values of the query field is
Figure FDA0002556232340000013
The number of the cells.
5. The method of claim 1 or 2, wherein the first query statement is for querying two main values B1And B2The number of (2); the converting the first query statement into a second query statement for querying a number of non-primary values, comprising:
obtaining
Figure FDA0002556232340000014
And
Figure FDA0002556232340000015
6. the method of claim 5, wherein said determining the number of dominant values based on the number of field values of the query field and the number of non-dominant values comprises:
according to the following steps:
Figure FDA0002556232340000016
determining the number of the main values, wherein the number of the field values of the query field is
Figure FDA0002556232340000017
And
Figure FDA0002556232340000018
the number of the cells.
7. The method of claim 1 or 2, wherein the first query statement is for querying three main values B1、B2And B3The number of (2); the converting the first query statement into a second query statement for querying a number of non-primary values, comprising:
obtaining
Figure FDA0002556232340000019
And
Figure FDA00025562323400000110
8. the method of claim 7, wherein said determining the number of dominant values based on the number of field values of the query field and the number of non-dominant values comprises:
according to the following steps:
Figure FDA00025562323400000111
determining the number of the main values, wherein the number of the field values of the query field is
Figure FDA00025562323400000112
And
Figure FDA00025562323400000113
the number of the cells.
9. The method of any of claims 1-8, prior to converting the first query statement to a second query statement for querying a number of non-primary values, further comprising:
determining that the query fields in the first query statement all have an index; and/or
Determining that the query fields in the first query statement all belong to an exact query.
10. An apparatus for querying a database, the apparatus comprising:
the acquisition module is used for acquiring first query statements for querying the number of the main values;
a conversion module, configured to convert the first query statement into a second query statement for querying a number of non-main values, where the main value and the non-main values are different field values for a same query field;
the query module is used for querying the number of the non-main values according to the second query statement;
and the determining module is used for determining the number of the main values according to the number of the field values of the query field and the number of the non-main values.
11. The apparatus of claim 10, wherein a ratio in a database between a number of the primary values and a number of field values of a query field to which the primary values belong is greater than 50%.
12. The apparatus of claim 10 or 11, wherein the first query statement is for querying a main value B1The number of (2); the conversion module, when being configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure FDA0002556232340000021
13. The apparatus as claimed in claim 12, wherein the determining module, when configured to determine the number of dominant values according to the number of field values of the query field and the number of non-dominant values, is specifically configured to:
according to the following steps:
Figure FDA0002556232340000022
determining the number of the main values, wherein the number of the field values of the query field is
Figure FDA0002556232340000023
The number of the cells.
14. The apparatus of claim 10 or 11, wherein the first query statement is to query two main values B1And B2The number of (2); the conversion module, when being configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure FDA0002556232340000024
And
Figure FDA0002556232340000025
15. the apparatus as claimed in claim 14, wherein said determining module, when configured to determine the number of dominant values based on the number of field values of the query field and the number of non-dominant values, is specifically configured to:
according to the following steps:
Figure FDA0002556232340000026
determining the number of the main values, wherein the number of the field values of the query field is
Figure FDA0002556232340000027
And
Figure FDA0002556232340000028
the number of the cells.
16. The apparatus of claim 10 or 11, wherein the first query statement is to query for three main values B1、B2And B3The number of (2); the conversion module, when being configured to convert the first query statement into a second query statement for querying the number of non-primary values, is specifically configured to: obtaining
Figure FDA0002556232340000029
And
Figure FDA00025562323400000210
17. the apparatus as claimed in claim 16, wherein said determining module, when configured to determine the number of dominant values based on the number of field values of the query field and the number of non-dominant values, is specifically configured to:
according to the following steps:
Figure FDA00025562323400000211
determining a number of the primary values, wherein a field value of the query fieldIs in an amount of
Figure FDA00025562323400000212
And
Figure FDA00025562323400000213
the number of the cells.
18. The apparatus of any of claims 10-17, wherein the translation module is further configured to determine that query fields in the first query statement all have an index; and/or determining that the query fields in the first query statement all belong to an exact query.
19. An apparatus for querying a database, the apparatus comprising: a processor and a memory;
the memory to store computer program instructions;
the processor to execute some or all of the computer program instructions in the memory, when executed, to implement the method of any of claims 1-9.
20. A computer-readable storage medium, in which a computer program is stored which, when executed by a computer, causes the computer to carry out the method according to any one of claims 1 to 9.
CN202010592569.7A 2020-06-24 2020-06-24 Database query method and device Active CN113836166B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010592569.7A CN113836166B (en) 2020-06-24 2020-06-24 Database query method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010592569.7A CN113836166B (en) 2020-06-24 2020-06-24 Database query method and device

Publications (2)

Publication Number Publication Date
CN113836166A true CN113836166A (en) 2021-12-24
CN113836166B CN113836166B (en) 2025-08-22

Family

ID=78965005

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010592569.7A Active CN113836166B (en) 2020-06-24 2020-06-24 Database query method and device

Country Status (1)

Country Link
CN (1) CN113836166B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN120670456A (en) * 2025-06-24 2025-09-19 广州市海捷计算机科技有限公司 Low-code-based data index query statement generation method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102622399A (en) * 2011-01-11 2012-08-01 索尼公司 Search apparatus, search method and program
US20160048584A1 (en) * 2014-08-13 2016-02-18 Marco Valentin On-the-fly determination of search areas and queries for database searches
CN107038207A (en) * 2017-02-20 2017-08-11 阿里巴巴集团控股有限公司 A kind of data query method, data processing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102622399A (en) * 2011-01-11 2012-08-01 索尼公司 Search apparatus, search method and program
US20160048584A1 (en) * 2014-08-13 2016-02-18 Marco Valentin On-the-fly determination of search areas and queries for database searches
CN107038207A (en) * 2017-02-20 2017-08-11 阿里巴巴集团控股有限公司 A kind of data query method, data processing method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
QI CHUNXIA: "On index-based query in SQL Server database", 《PROCEEDINGS OF THE 35TH CHINESE CONTROL CONFERENCE》, 29 August 2016 (2016-08-29), pages 9519 - 9523 *
曾艳梅: "一种基于元数据静动态数据联合查询方法的研究与实现", 《计算机应用与软件》, vol. 32, no. 1, 15 January 2015 (2015-01-15), pages 59 - 63 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN120670456A (en) * 2025-06-24 2025-09-19 广州市海捷计算机科技有限公司 Low-code-based data index query statement generation method and device

Also Published As

Publication number Publication date
CN113836166B (en) 2025-08-22

Similar Documents

Publication Publication Date Title
US8352488B2 (en) Methods, systems and computer program products for providing a distributed associative memory base
US10430448B2 (en) Computer-implemented method of and system for searching an inverted index having a plurality of posting lists
US8862588B1 (en) Generating an empirically-determined schema for a schemaless database
CN103593425B (en) Preference-based intelligent retrieval method and system
CN110659282B (en) Data route construction method, device, computer equipment and storage medium
CN106326361B (en) Data query method and device based on HBase database
CN118981475B (en) SQL sentence generation method and device based on large model
CN111506621B (en) Data statistical method and device
CN107748766B (en) Big data fast query method based on Presto and elastic search
CN107103032B (en) A massive data paging query method that avoids global sorting in a distributed environment
US11216474B2 (en) Statistical processing of natural language queries of data sets
CN109086456B (en) Data indexing method and device
CN118396123B (en) Text generation method, device, computer program product, electronic device and medium
CN107329987A (en) A kind of search system based on mongo databases
US9323798B2 (en) Storing a key value to a deleted row based on key range density
EP4586108A1 (en) A method of querying graph data for graph databases and associated equipment
CN114020790A (en) Method and device for querying data
CN112035449A (en) Data processing method and device, computer equipment and storage medium
CN113282579B (en) Heterogeneous data storage and retrieval method, device, equipment and storage medium
CN108241856A (en) Information generation method and equipment
Chung et al. A simple message-optimal algorithm for random sampling from a distributed stream
CN113836166A (en) Database query method and device
CN117609473A (en) Question-answering method, system and device for water conservancy knowledge base
CN107193916B (en) A kind of personalized diversified query recommendation method and system
CN114385555A (en) Data query method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20220214

Address after: 550025 Huawei cloud data center, jiaoxinggong Road, Qianzhong Avenue, Gui'an New District, Guiyang City, Guizhou Province

Applicant after: Huawei Cloud Computing Technologies Co.,Ltd.

Address before: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Applicant before: HUAWEI TECHNOLOGIES Co.,Ltd.

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant