WO2015184782A1 - Data query method and device - Google Patents

Data query method and device Download PDF

Info

Publication number
WO2015184782A1
WO2015184782A1 PCT/CN2014/095684 CN2014095684W WO2015184782A1 WO 2015184782 A1 WO2015184782 A1 WO 2015184782A1 CN 2014095684 W CN2014095684 W CN 2014095684W WO 2015184782 A1 WO2015184782 A1 WO 2015184782A1
Authority
WO
WIPO (PCT)
Prior art keywords
query
data
key
query field
field
Prior art date
Application number
PCT/CN2014/095684
Other languages
French (fr)
Chinese (zh)
Inventor
陈波
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2015184782A1 publication Critical patent/WO2015184782A1/en

Links

Images

Classifications

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

Definitions

  • the present invention relates to the field of data query technology, and in particular, to a data query method and apparatus.
  • the similar statistics also include the busy hour indicator (the hour/minute of the minimum/maximum index value in a day or a time range) Information), and these key fields are usually counted along with many other common fields to facilitate comparison analysis.
  • a common method is to sequentially query all the corresponding values of this field, and obtain the final statistical result according to the value corresponding to the key field. Since querying all fields requires access to multiple data tables, the associated query method consumes a lot of database resources and leads to statistical inefficiencies.
  • the main technical problem to be solved by the present invention is to provide a data query method and device, and solve the problem that the related data query method has large resource consumption and low query efficiency.
  • a data query method including:
  • the query condition includes a key query field, a common query field associated with the key query field, and a key query field data filtering condition;
  • the step of determining the database table corresponding to the key query field includes:
  • the corresponding data in the respective database tables is processed according to a preset algorithm to obtain a database table corresponding to the keyword query field.
  • the method before the step of querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
  • the method before the step of querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
  • the association relationship includes at least one of a time association and a location association.
  • a data query device includes a condition acquisition module, a data table determination module, a key data query module, and an associated data query module, wherein
  • the condition obtaining module is configured to: obtain a query condition, where the query condition includes a key query field, a common query field associated with the key query field, and a key query field data screening condition;
  • the data table determining module is configured to: determine a database table corresponding to the common query field and the key query field, and set data corresponding to the database table corresponding to the common query field and the key query field The relationship between the data stored in the database table;
  • the key data query module is configured to: query, according to the keyword query field, a key that meets the filtering condition of the key query field from a database table corresponding to the key query field data;
  • the associated data query module is configured to: query data associated with the key data from a database table corresponding to the common query field according to the association relationship.
  • the data table determining module includes a computing processing submodule, and is configured to:
  • the corresponding data in the respective database tables are processed according to a preset algorithm to obtain a new database table, and the new database table is The database table corresponding to the keyword query field.
  • the device further includes a ratio judgment module, where
  • the ratio determining module is configured to: determine whether a ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than the preset ratio; if not, notify the The key data query module queries, from the database table corresponding to the key query field, key data that satisfies the data filtering condition of the key query field.
  • the device further includes a data amount determining module, where
  • the data amount judging module is configured to: determine whether the amount of data stored in the database in which the database table corresponding to the key query field is located is greater than a preset threshold, and if not, notify the key data query module from the key query field The corresponding database table queries the key data that meets the filtering conditions of the key query field data.
  • the association relationship includes at least one of a time association and a location association.
  • a computer program comprising program instructions that, when executed by a computer, cause the computer to perform any of the above data query methods.
  • a carrier carrying the computer program A carrier carrying the computer program.
  • the data query method and device first acquires a query condition when performing data query, and the query condition includes a key query field and an ordinary query associated with the key query field.
  • Field, and key query field data filtering conditions determine the database table corresponding to the common query field and the key query field; the relationship between the common query field and the data stored in each database table corresponding to the key query field; Key data corresponding to the data filtering condition of the key query field is queried in the database table corresponding to the key query field, and the associated data corresponding to the key data is queried from the database table corresponding to the common query field according to the above association relationship (that is, each common query) The data corresponding to the field).
  • the embodiment of the present invention can firstly query the key data corresponding to the key segment, and then directly query the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, and can significantly reduce resource consumption, and Improve query efficiency.
  • FIG. 1 is a schematic flowchart of a data query method according to Embodiment 1 of the present invention.
  • FIG. 2 is a schematic structural diagram of a data query apparatus according to Embodiment 2 of the present invention.
  • FIG. 3 is a schematic structural diagram of another data query apparatus according to Embodiment 2 of the present invention.
  • FIG. 4 is a schematic structural diagram of another data query apparatus according to Embodiment 2 of the present invention.
  • Embodiment 1 is a diagrammatic representation of Embodiment 1:
  • the data query method provided in this embodiment includes:
  • Step 101 Acquire a query condition; the query condition may be currently input by the user, or may be preset in advance.
  • the query conditions in this embodiment include a key query field, a common query field associated with the key query field, and a key query.
  • the key query field data filtering condition may be, for example, a maximum of N data, a minimum of M data, or each data within a user-set range value, and the like.
  • Step 102 Determine a database table corresponding to the common query field and the key query field respectively; set an association relationship between the data stored in the database table corresponding to the common query field and the data stored in the database table corresponding to the key query field, That is, the two are associated database tables;
  • the association relationship includes at least one of a latitude association field such as a time association and a location association;
  • Time association refers to the existence of a relationship in time, such as the same time or other relationships in time.
  • the positional relationship refers to the existence of a relationship in the position, such as corresponding position or other relationship in position.
  • Step 103 Query, according to the keyword query field, the key data that meets the filtering condition of the key query field data from the database table corresponding to the key query field;
  • Step 104 Query data associated with the key data, that is, data corresponding to each common query field, from the database table corresponding to the common query field according to the foregoing association relationship and the common query field.
  • the key data corresponding to the key field is first queried, and the associated data corresponding to other common fields is directly queried by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, can significantly reduce resource consumption, and improve the query. effectiveness.
  • the application example is described by taking the time association as an example.
  • the key query field included in the query condition is the c2 field, and the c1, c3, and c6 of the T1 table are the common field key query fields. Find the minimum value of the c2 field;
  • the database table corresponding to the key query field c2 is the following T1 table, and the database table corresponding to the common query field 2014-12-2300:15 is the following T2 table;
  • begintime is an associated field, that is, the two tables are associated by time, that is, The start time in the table is 2014-12-23.
  • the keyword query field input by the user in the embodiment mainly reflects the corresponding query index.
  • the query indicator in this embodiment includes an indicator that can be embodied by using a query field, and includes an indicator that is reflected by multiple query fields;
  • the key query field in this embodiment includes multiple query fields.
  • the database table corresponding to the key query field is determined to include:
  • the corresponding data of the plurality of query fields in the respective database tables are processed according to a preset algorithm to obtain a new database table, and the new database table is a database table corresponding to the keyword query field.
  • the keyword query field in this embodiment includes the query fields A and B; when the corresponding database table is determined, the corresponding corresponding in the query field A and the query field B are respectively extracted.
  • the data in the data table is added to obtain a new database table, which is the database table of the keyword query field (ie, query field A + query field B). That is, in this embodiment, for the case where the index is obtained by multiple query field operations, the data table obtained by calculating the plurality of query fields may be first obtained and the key satisfying the screening condition (for example, the maximum 10 values) may be queried therefrom. Data, and then query the values of other common fields according to the key data association, can achieve a good efficiency optimization effect.
  • the screening condition for example, the maximum 10 values
  • the keyword query field in this embodiment includes the query field C; when the corresponding database table is determined, the data table corresponding to the query field C is the keyword query field. Database Table.
  • the method before querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
  • the preset ratio in this embodiment may be less than or equal to one-half, for example, the specific value may be one-half, and the number of query fields included in the keyword query field and the number of query fields included in the common query field are assumed.
  • the ratio is one-seventh, less than one-half of the preset ratio.
  • the method before the key data satisfying the data filtering condition of the key query field is queried from the database table corresponding to the key query field, the method further includes determining the key data corresponding to the key query field by combining the data size of the database, and then Use the association relationship to query the data corresponding to other common query fields of the association. Because the database with a small amount of data can be directly queried in the corresponding data table for each query field; the judging process includes:
  • the method of the embodiment of the present invention is used only when the amount of data stored in the database in which the database table is located is greater than a preset threshold, and the query efficiency is also used when the amount of data stored in the database where the database table is located is less than or equal to a preset threshold. The improvement is not very obvious. However, the method of the embodiment of the invention can also be used.
  • the data amount of the database may be counted according to the number of data tables in the database; for the column storage database, the data amount of the database may be counted according to the number of fields, or according to the number of fields and The amount of data is used to count the amount of data in the database.
  • the preset threshold in this embodiment may be specifically selected according to a specific database and an application scenario or the like.
  • the key data is queried in its corresponding data table.
  • 10 million pieces of data in the database table need to be accessed to obtain the maximum 10 pieces of data; and then according to the time and/or time of the 10 pieces of data.
  • Associated dimension fields such as location to match the data of the remaining 7 query fields Corresponding data in the library table.
  • 70 data can be used to obtain the final result; and the related query method requires at least 80 million pieces of data to be accessed. It can be seen that the solution provided in this embodiment greatly reduces the reading and writing consumption of the database and effectively improves the statistical efficiency.
  • Embodiment 2 is a diagrammatic representation of Embodiment 1:
  • the data query device 1 includes a condition acquisition module 11, a data table determination module 12, a key data query module 13, and an associated data query module 14;
  • the condition obtaining module 11 is configured to: obtain a query condition, which may be currently input by the user, or may be preset in advance.
  • the query condition in this embodiment includes a key query field and a common query field associated with the key query field. And key query field data filtering conditions;
  • the key query field data filtering condition may be, for example, selecting the largest N data, the smallest M data, or each data within the user set range value.
  • the data table determining module 12 is configured to: determine a database table corresponding to the common query field and the key query field respectively; and set an association relationship between the data stored in each database table corresponding to the common query field and the key query field;
  • the association relationship includes at least one of a latitude association field such as a time association and a location association; that is, each database table corresponding to each query field is an associated database table;
  • the key data query module 13 is configured to: query key data that meets the filtering conditions of the key query field data from the database table corresponding to the key query field;
  • the associated data query module 14 is configured to: query the data associated with the key data (that is, the data corresponding to each common query field) from the database table corresponding to the common query field according to the foregoing association relationship and the common query field.
  • the data querying apparatus 1 in this embodiment firstly queries the key data corresponding to the key field, and then directly queries the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, and can significantly reduce the data access amount. Resource consumption and improve query efficiency.
  • the keyword query field input by the user in the embodiment mainly reflects the corresponding query index.
  • the query indicator in this embodiment includes an indicator that can be embodied by using a query field, and includes an indicator that is reflected by multiple query fields;
  • the key query field in this embodiment includes multiple query fields. Therefore, the data table determining module 12 in this embodiment may include a calculation processing sub-module, configured to: according to a preset algorithm, corresponding data of the plurality of query fields in the respective database tables when the key query field includes multiple query fields After processing, a new database table is obtained, and the new database table is a database table corresponding to the keyword query field.
  • the keyword query field in this embodiment includes the query fields A and B; when the corresponding database table is determined, the corresponding corresponding in the query field A and the query field B are respectively extracted.
  • the data in the data table is added to obtain a new database table, which is the database table of the keyword query field (ie, query field A + query field B). That is, in this embodiment, for the case where the index is obtained by multiple query field operations, the data table obtained by calculating the plurality of query fields may be first obtained and the key satisfying the screening condition (for example, the maximum 10 values) may be queried therefrom. Data, and then query the values of other common fields according to the key data association, can achieve a good efficiency optimization effect.
  • the screening condition for example, the maximum 10 values
  • the keyword query field in this embodiment includes the query field C; when the corresponding database table is determined, the data table corresponding to the query field C is the keyword query field. Database Table.
  • the data querying apparatus in this embodiment further includes a ratio determining module 15 configured to query, in the database table corresponding to the key query field, the key data query module to meet the key data of the key query field data screening condition. Before, it is determined whether the ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than a preset ratio; if yes, the key data query module is notified to query the database table corresponding to the key query field. Key data that meets the key query field data filtering criteria; otherwise, it can be queried directly in each corresponding data table for each query field.
  • the preset ratio in this embodiment may be less than or equal to one-half, for example, the specific value may be one-half, and the number of query fields included in the keyword query field and the number of query fields included in the common query field are assumed.
  • the ratio is one-seventh, less than one-half of the preset ratio.
  • the method before the key data satisfying the data filtering condition of the key query field is queried from the database table corresponding to the key query field, the method further includes determining the key data corresponding to the key query field by combining the data size of the database, and then Use the association relationship to query the data corresponding to other common query fields of the association. Because the database with a small amount of data can be directly queried in the corresponding data table for each query field.
  • the data query apparatus 1 in this embodiment further includes a data quantity determining module 16 configured to query, in the database table corresponding to the key query field, the key data query module to meet the filtering conditions of the key query field data.
  • the data amount of the database may be counted according to the number of data tables in the database; for the column storage database, the data amount of the database may be counted according to the number of fields, or according to the number of fields and The amount of data is used to count the amount of data in the database.
  • the preset threshold in this embodiment may be specifically selected according to a specific database and an application scenario or the like.
  • a service statistic requires querying 10 associated query fields, which are from 8 associated database tables, one of which is a key query field, and the remaining 9 are common query fields, and the filtering condition is the smallest according to the key query field. 100 values (ie Top min10) are presented. And assume that each data table needs to query the amount of data is 1 million, the query process is as follows:
  • the key data is queried in its corresponding data table.
  • Position and other associated dimension fields to match the corresponding data in the database table corresponding to the remaining 9 query fields.
  • For each common query field according to the association relationship between the data, only the corresponding 100 in the corresponding database table is accessed.
  • the data is OK, so you only need to access 1 million and 900 data to get the final result.
  • the related query method needs to access at least 10 million data, which shows that the solution provided in this embodiment is greatly reduced.
  • the database read and write consumption, and effectively improve the statistical efficiency.
  • the embodiment of the invention also discloses a computer program, comprising program instructions, which when executed by a computer, enable the computer to execute any of the above data query methods.
  • the embodiment of the invention also discloses a carrier carrying the computer program.
  • the embodiment of the present invention can firstly query the key data corresponding to the key segment, and then directly query the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, can significantly reduce resource consumption, and improve Query efficiency. Therefore, the present invention has strong industrial applicability.

Abstract

A data query method and device. During a data query, first obtaining query conditions, the query conditions comprising a key query field, a common query field related to the key query field, and data filtering conditions for the key query field; determining the database tables corresponding respectively to the common query field and the key query field; correspondence exist between the data stored in the database tables corresponding to the common query field and key query field; finding from the database table corresponding to the key query field the key data that satisfy the data filtering conditions of the key query field, and then finding the related data corresponding to the key data from the database table corresponding to the common query field according to said correspondence. Key data corresponding to the key field is first found, and related data corresponding to other common fields are then directly found using the correspondence, thereby substantially reducing resources consumption and enhancing query efficiency.

Description

数据查询方法及装置Data query method and device 技术领域Technical field
本发明涉及数据查询技术领域,具体涉及一种数据查询方法及装置。The present invention relates to the field of data query technology, and in particular, to a data query method and apparatus.
背景技术Background technique
目前,对于某些关键字段对应的数据,往往有求最大/最小、逻辑过滤等统计要求,相近的统计还包括忙时指标(统计一天或一个时间范围内指标值最小/最大的小时时间段信息),而且这些关键字段通常是和很多其他普通字段一起统计的,以方便用户进行对比分析。常用的方法是依次查询出这个字段的对应的所有数值,并根据关键字段对应的数值来获取最终统计结果。由于查询所有字段需要访问多个数据表,因此按照相关的查询方法会消耗很多数据库资源并导致统计效率低下。At present, for the data corresponding to certain key fields, there are often statistical requirements such as maximal/minimum and logical filtering. The similar statistics also include the busy hour indicator (the hour/minute of the minimum/maximum index value in a day or a time range) Information), and these key fields are usually counted along with many other common fields to facilitate comparison analysis. A common method is to sequentially query all the corresponding values of this field, and obtain the final statistical result according to the value corresponding to the key field. Since querying all fields requires access to multiple data tables, the associated query method consumes a lot of database resources and leads to statistical inefficiencies.
发明内容Summary of the invention
本发明要解决的主要技术问题是,提供一种数据查询方法及装置,解决相关数据查询方法资源消耗大、查询效率低的问题。The main technical problem to be solved by the present invention is to provide a data query method and device, and solve the problem that the related data query method has large resource consumption and low query efficiency.
为解决上述技术问题,采用如下技术方案:In order to solve the above technical problems, the following technical solutions are adopted:
一种数据查询方法,包括:A data query method, including:
获取查询条件,其中,所述查询条件包括关键查询字段、与所述关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;Obtaining a query condition, wherein the query condition includes a key query field, a common query field associated with the key query field, and a key query field data filtering condition;
确定所述普通查询字段和所述关键查询字段所分别对应的数据库表;Determining a database table corresponding to the common query field and the key query field respectively;
设置所述普通查询字段数据库表中存储的数据和所述关键查询字段所对应的数据库表中存储的数据之间的关联关系;Setting an association relationship between the data stored in the general query field database table and the data stored in the database table corresponding to the key query field;
根据所述关键字查询字段从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据;Determining, according to the keyword query field, key data that meets the filtering condition of the key query field data from a database table corresponding to the key query field;
根据所述关联关系从所述普通查询字段对应的数据库表中查询出与所述 关键数据关联的数据。Querying from the database table corresponding to the common query field according to the association relationship Data associated with key data.
可选地,当所述关键查询字段包括多个查询字段时,确定所述关键查询字段所对应的数据库表的步骤包括:Optionally, when the key query field includes multiple query fields, the step of determining the database table corresponding to the key query field includes:
将所述多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到所述关键字查询字段所对应的数据库表。The corresponding data in the respective database tables is processed according to a preset algorithm to obtain a database table corresponding to the keyword query field.
可选地,所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤之前,该方法还包括:Optionally, before the step of querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
判断所述关键字查询字段包括的查询字段个数与所述普通查询字段包括的查询字段个数之比是否小于预设比值;如果小于,才执行所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤。Determining whether the ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than a preset ratio; if less than, executing the database table corresponding to the key query field The step of querying the key data that satisfies the data filtering condition of the key query field is queried.
可选地,所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤之前,该方法还包括:Optionally, before the step of querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
判断所述关键查询字段对应的数据库表所在的数据库中存储的数据量是否大于预设阈值,如果大于,才执行所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤。Determining whether the amount of data stored in the database in which the database table corresponding to the key query field is located is greater than a preset threshold. If the value is greater than, the query is performed from the database table corresponding to the key query field to satisfy the key query field. The step of data filtering the key data.
可选地,所述关联关系包括时间关联和位置关联中的至少一种。Optionally, the association relationship includes at least one of a time association and a location association.
一种数据查询装置,包括条件获取模块、数据表确定模块、关键数据查询模块和关联数据查询模块,其中,A data query device includes a condition acquisition module, a data table determination module, a key data query module, and an associated data query module, wherein
所述条件获取模块设置成:获取查询条件,其中,所述查询条件包括关键查询字段、与所述关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;The condition obtaining module is configured to: obtain a query condition, where the query condition includes a key query field, a common query field associated with the key query field, and a key query field data screening condition;
所述数据表确定模块设置成:确定所述普通查询字段和关键查询字段所分别对应的数据库表,并设置所述普通查询字段所对应的数据库表中存储的数据和所述关键查询字段所对应的数据库表中存储的数据之间的关联关系;The data table determining module is configured to: determine a database table corresponding to the common query field and the key query field, and set data corresponding to the database table corresponding to the common query field and the key query field The relationship between the data stored in the database table;
所述关键数据查询模块设置成:根据所述关键字查询字段从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键 数据;The key data query module is configured to: query, according to the keyword query field, a key that meets the filtering condition of the key query field from a database table corresponding to the key query field data;
所述关联数据查询模块设置成:根据所述关联关系从所述普通查询字段对应的数据库表中查询出与所述关键数据关联的数据。The associated data query module is configured to: query data associated with the key data from a database table corresponding to the common query field according to the association relationship.
可选地,所述数据表确定模块包括计算处理子模块,设置成:Optionally, the data table determining module includes a computing processing submodule, and is configured to:
当所述关键查询字段包括多个查询字段时,将所述多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到新的数据库表,该新的数据库表为所述关键字查询字段所对应的数据库表。When the key query field includes multiple query fields, the corresponding data in the respective database tables are processed according to a preset algorithm to obtain a new database table, and the new database table is The database table corresponding to the keyword query field.
可选地,该装置还包括比值判断模块,其中,Optionally, the device further includes a ratio judgment module, where
所述比值判断模块设置成:判断所述关键字查询字段包括的查询字段个数与所述普通查询字段包括的查询字段个数之比是否小于所述预设比值;如果小于,才通知所述关键数据查询模块从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据。The ratio determining module is configured to: determine whether a ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than the preset ratio; if not, notify the The key data query module queries, from the database table corresponding to the key query field, key data that satisfies the data filtering condition of the key query field.
可选地,该装置还包括数据量判断模块,其中,Optionally, the device further includes a data amount determining module, where
所述数据量判断模块设置成:判断所述关键查询字段对应的数据库表所在的数据库中存储的数据量是否大于预设阈值,如果大于,才通知所述关键数据查询模块从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据。The data amount judging module is configured to: determine whether the amount of data stored in the database in which the database table corresponding to the key query field is located is greater than a preset threshold, and if not, notify the key data query module from the key query field The corresponding database table queries the key data that meets the filtering conditions of the key query field data.
可选地,所述关联关系包括时间关联和位置关联中的至少一种。Optionally, the association relationship includes at least one of a time association and a location association.
一种计算机程序,包括程序指令,当该程序指令被计算机执行时,使得该计算机可执行上述任意的数据查询方法。A computer program comprising program instructions that, when executed by a computer, cause the computer to perform any of the above data query methods.
一种载有所述计算机程序的载体。A carrier carrying the computer program.
本发明实施例的有益效果是:The beneficial effects of the embodiments of the present invention are:
本发明实施例提供的数据查询方法及装置,在进行数据查询时,先获取查询条件,该查询条件包括关键查询字段、与关键查询字段关联的普通查询 字段、以及关键查询字段数据筛选条件;确定普通查询字段和关键查询字段所分别对应的数据库表;普通查询字段和关键查询字段所对应的各数据库表中存储的数据之间存在关联关系;先从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据,再根据上述关联关系从普通查询字段对应的数据库表中查询出与关键数据对应的关联数据(也即各普通查询字段对应的数据)。可见本发明实施例通过先查询出关键字段对应的关键数据,再利用关联关系直接查询到其他普通字段对应的关联数据,可以呈数量级的降低数据库的数据访问量,能明显降低资源消耗,并提升查询效率。The data query method and device provided by the embodiment of the present invention first acquires a query condition when performing data query, and the query condition includes a key query field and an ordinary query associated with the key query field. Field, and key query field data filtering conditions; determine the database table corresponding to the common query field and the key query field; the relationship between the common query field and the data stored in each database table corresponding to the key query field; Key data corresponding to the data filtering condition of the key query field is queried in the database table corresponding to the key query field, and the associated data corresponding to the key data is queried from the database table corresponding to the common query field according to the above association relationship (that is, each common query) The data corresponding to the field). It can be seen that the embodiment of the present invention can firstly query the key data corresponding to the key segment, and then directly query the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, and can significantly reduce resource consumption, and Improve query efficiency.
附图概述BRIEF abstract
图1为本发明实施例一提供的数据查询方法流程示意图;1 is a schematic flowchart of a data query method according to Embodiment 1 of the present invention;
图2为本发明实施例二提供的数据查询装置结构示意图;2 is a schematic structural diagram of a data query apparatus according to Embodiment 2 of the present invention;
图3为本发明实施例二提供的另一数据查询装置结构示意图;3 is a schematic structural diagram of another data query apparatus according to Embodiment 2 of the present invention;
图4为本发明实施例二提供的另一数据查询装置结构示意图。FIG. 4 is a schematic structural diagram of another data query apparatus according to Embodiment 2 of the present invention.
本发明的较佳实施方式Preferred embodiment of the invention
下面通过具体实施方式结合附图对本发明作进一步详细说明。The present invention will be further described in detail below with reference to the accompanying drawings.
实施例一:Embodiment 1:
请参见图1所示,本实施例提供的数据查询方法包括:Referring to FIG. 1 , the data query method provided in this embodiment includes:
步骤101:获取查询条件;该查询条件可以是用户当前输入的,也可以提前预置好的,本实施例中的查询条件包括关键查询字段、与关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;Step 101: Acquire a query condition; the query condition may be currently input by the user, or may be preset in advance. The query conditions in this embodiment include a key query field, a common query field associated with the key query field, and a key query. Field data filtering conditions;
可选地,关键查询字段数据筛选条件可以为,例如最大的N个数据、最小的M个数据或者用户设定范围值内的各数据等等。Optionally, the key query field data filtering condition may be, for example, a maximum of N data, a minimum of M data, or each data within a user-set range value, and the like.
步骤102:确定普通查询字段和关键查询字段所分别对应的数据库表;设置普通查询字段所对应的数据库表中存储的数据和关键查询字段所对应的数据库表中存储的数据之间的关联关系,也即二者为关联数据库表; Step 102: Determine a database table corresponding to the common query field and the key query field respectively; set an association relationship between the data stored in the database table corresponding to the common query field and the data stored in the database table corresponding to the key query field, That is, the two are associated database tables;
可选地,该关联关系包括时间关联、位置关联等纬度关联字段中的至少一种;Optionally, the association relationship includes at least one of a latitude association field such as a time association and a location association;
时间关联是指在时间上存在联系,例如时间相同或者时间上存在其他关系,位置关系是指在位置上存在联系,例如位置相应或者在位置上存在其他关系。Time association refers to the existence of a relationship in time, such as the same time or other relationships in time. The positional relationship refers to the existence of a relationship in the position, such as corresponding position or other relationship in position.
步骤103:根据关键字查询字段从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据;Step 103: Query, according to the keyword query field, the key data that meets the filtering condition of the key query field data from the database table corresponding to the key query field;
步骤104:根据上述关联关系以及上述普通查询字段从普通查询字段对应的数据库表中查询出与关键数据关联的数据,也即各普通查询字段对应的数据。Step 104: Query data associated with the key data, that is, data corresponding to each common query field, from the database table corresponding to the common query field according to the foregoing association relationship and the common query field.
本实施例通过先查询出关键字段对应的关键数据,再利用关联关系直接查询到其他普通字段对应的关联数据,可以呈数量级的降低数据库的数据访问量,能明显降低资源消耗,并提升查询效率。In this embodiment, the key data corresponding to the key field is first queried, and the associated data corresponding to other common fields is directly queried by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, can significantly reduce resource consumption, and improve the query. effectiveness.
下面将通过一个具体的应用实例来说明图1的数据查询方法。The data query method of FIG. 1 will be explained below through a specific application example.
该应用实例以时间关联为例进行说明,其中,查询条件所包括的关键查询字段为c2字段,T1表的c1、c3以及T2表的c4、c5、c6为普通字段关键查询字段数据筛选条件为求c2字段的最小值;The application example is described by taking the time association as an example. The key query field included in the query condition is the c2 field, and the c1, c3, and c6 of the T1 table are the common field key query fields. Find the minimum value of the c2 field;
关键查询字段c2所对应的数据库表为如下的T1表,普通查询字段2014-12-2300:15对应的数据库表为如下的T2表;The database table corresponding to the key query field c2 is the following T1 table, and the database table corresponding to the common query field 2014-12-2300:15 is the following T2 table;
设置普通查询字段所对应的数据库表中存储的数据和关键查询字段所对应的数据库表中存储的数据之间的关联关系是:begintime为关联字段,即这两张表通过时间关联,即这两张表中的开始时间都是2014-12-23。The association relationship between the data stored in the database table corresponding to the common query field and the data stored in the database table corresponding to the key query field is: begintime is an associated field, that is, the two tables are associated by time, that is, The start time in the table is 2014-12-23.
Figure PCTCN2014095684-appb-000001
Figure PCTCN2014095684-appb-000001
在查询时,先查询T1的c2字段,求c2的最小值得到99这个值,而这个值对应的时间字段为“2014-12-2300:15”,根据这个时间关联字段得到c1、c3以及T2表的c4、c5、c6。 In the query, first query the c2 field of T1, and find the minimum value of c2 to get the value of 99, and the time field corresponding to this value is "2014-12-2300:15", according to this time, the associated fields get c1, c3 and T2. Table c4, c5, c6.
本实施例中用户输入的关键字查询字段主要体现相应的查询指标,本实施例中的查询指标包括通过一个查询字段即可体现的指标,也包括通过多个查询字段体现的指标;当通过多个查询字段体现时,本实施例中的关键查询字段包括多个查询字段,此时确定关键查询字段所对应的数据库表包括:The keyword query field input by the user in the embodiment mainly reflects the corresponding query index. The query indicator in this embodiment includes an indicator that can be embodied by using a query field, and includes an indicator that is reflected by multiple query fields; When the query fields are displayed, the key query field in this embodiment includes multiple query fields. At this time, the database table corresponding to the key query field is determined to include:
将多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到新的数据库表,该新的数据库表为关键字查询字段所对应的数据库表。The corresponding data of the plurality of query fields in the respective database tables are processed according to a preset algorithm to obtain a new database table, and the new database table is a database table corresponding to the keyword query field.
例如,假设指标需要结合查询字段A+查询字段B体现,则本实施例中的关键字查询字段包括查询字段A和B;对应的确定数据库表时,分别提取出查询字段A和查询字段B中对应的数据表中的数据并进行相加得到新的数据库表,该新的数据库表即为关键字查询字段(即查询字段A+查询字段B)的数据库表。也即,本实施例中,对于通过多个查询字段运算得到指标的情况,可以先求多个查询字段计算后得到的数据表并从中查询出满足筛选条件(例如最大的10个值)的关键数据,再根据关键数据关联查询其他普通字段的值,可以起到很好的效率优化效果。For example, if the indicator needs to be combined with the query field A+the query field B, the keyword query field in this embodiment includes the query fields A and B; when the corresponding database table is determined, the corresponding corresponding in the query field A and the query field B are respectively extracted. The data in the data table is added to obtain a new database table, which is the database table of the keyword query field (ie, query field A + query field B). That is, in this embodiment, for the case where the index is obtained by multiple query field operations, the data table obtained by calculating the plurality of query fields may be first obtained and the key satisfying the screening condition (for example, the maximum 10 values) may be queried therefrom. Data, and then query the values of other common fields according to the key data association, can achieve a good efficiency optimization effect.
又例如,假设指标通过一个查询字段C即可体现,则本实施例中的关键字查询字段包括查询字段C;对应的确定数据库表时,查询字段C对应的数据表即为关键字查询字段的数据库表。For example, if the indicator is reflected by a query field C, the keyword query field in this embodiment includes the query field C; when the corresponding database table is determined, the data table corresponding to the query field C is the keyword query field. Database Table.
本实施例中,在从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据之前,还包括:In this embodiment, before querying the key data that meets the data filtering condition of the key query field from the database table corresponding to the key query field, the method further includes:
判断关键字查询字段包括的查询字段个数与普通查询字段包括的查询字段个数之比是否小于所述预设比值;如是,再从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据。也即本实施例只有在关键查询字段涉及的数据表个数与普通查询字段涉及的数据表个数的比值小于预设比值时,才先查询关键查询字段对应的关键数据,再利用关联关系查询到关联的其他普通查询字段对应的数据;否则,可直接针对各查询字段在各自对应的数据表中进行查询。这是因为关键字查询字段包括的查询字段个数与普通查询字段包括的查询字段个数之比大于等于所述预设比值时,对于查询效率的提高,效果不是很明显。但是也可以使用本发明实施例的方法。 Determining whether the ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than the preset ratio; if yes, querying the data of the key query field from the database table corresponding to the key query field Key data for screening criteria. That is, in this embodiment, only when the ratio of the number of data tables involved in the key query field to the number of data tables involved in the common query field is less than the preset ratio, the key data corresponding to the key query field is first queried, and then the association relationship is used. Data corresponding to other common query fields of the association; otherwise, the query may be directly queried in the corresponding data table for each query field. This is because when the ratio of the number of query fields included in the keyword query field to the number of query fields included in the normal query field is greater than or equal to the preset ratio, the effect is not obvious for the improvement of the query efficiency. However, the method of the embodiment of the invention can also be used.
本实施例中的预设比值可以取为小于等于二分之一,例如具体可取值为二分之一,假设关键字查询字段包括的查询字段个数与普通查询字段包括的查询字段个数之比为七分之一,小于预设比值二分之一,先查询关键查询字段对应的关键数据,再利用关联关系查询到关联的其他普通查询字段对应的数据。The preset ratio in this embodiment may be less than or equal to one-half, for example, the specific value may be one-half, and the number of query fields included in the keyword query field and the number of query fields included in the common query field are assumed. The ratio is one-seventh, less than one-half of the preset ratio. The key data corresponding to the key query field is first queried, and then the association data is used to query the data corresponding to other common query fields.
本实施例中,在从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据之前,还包括结合数据库的数据量大小判断是否先查询关键查询字段对应的关键数据,再利用关联关系查询到关联的其他普通查询字段对应的数据。因为对于数据量较小的数据库可直接针对各查询字段在各自对应的数据表中进行查询;该判断过程包括:In this embodiment, before the key data satisfying the data filtering condition of the key query field is queried from the database table corresponding to the key query field, the method further includes determining the key data corresponding to the key query field by combining the data size of the database, and then Use the association relationship to query the data corresponding to other common query fields of the association. Because the database with a small amount of data can be directly queried in the corresponding data table for each query field; the judging process includes:
判断数据库表所在的数据库中存储的数据量是否大于预设阈值,如是,再从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据;否则,直接针对各查询字段在各自对应的数据表中进行查询。只有在数据库表所在的数据库中存储的数据量大于预设阈值时,才使用本发明实施例的方法,也是因为在数据库表所在的数据库中存储的数据量小于等于预设阈值时,对于查询效率的提高,效果不是很明显。但是也可以使用本发明实施例的方法。Determining whether the amount of data stored in the database in which the database table is located is greater than a preset threshold. If yes, querying the database table corresponding to the key query field to query key data that meets the filtering conditions of the key query field; otherwise, directly targeting each query field. Query in the corresponding data table. The method of the embodiment of the present invention is used only when the amount of data stored in the database in which the database table is located is greater than a preset threshold, and the query efficiency is also used when the amount of data stored in the database where the database table is located is less than or equal to a preset threshold. The improvement is not very obvious. However, the method of the embodiment of the invention can also be used.
本实施例中,对于普通的关系数据库,可以根据该数据库中的数据表个数统计该数据库的数据量;对于列存储数据库,则可根据字段数统计该数据库的数据量,或根据字段数以及数据量规模统计该数据库的数据量。本实施例中的预设阈值可以根据具体的数据库以及应用场景等等具体选定设置。In this embodiment, for a common relational database, the data amount of the database may be counted according to the number of data tables in the database; for the column storage database, the data amount of the database may be counted according to the number of fields, or according to the number of fields and The amount of data is used to count the amount of data in the database. The preset threshold in this embodiment may be specifically selected according to a specific database and an application scenario or the like.
为了更好的理解本发明,下面再以一个具体示例进行说明。In order to better understand the present invention, a specific example will be described below.
假设某业务统计要求查询8个关联的查询字段,分别来自8个关联的数据库表,其中1个为关键查询字段,剩余的7个为普通查询字段,筛选条件为按照该关键查询字段的最大的10个值(也即Top max10)进行呈现。并假设每个数据表需要查询的数据量为1千万条,其查询过程如下:Suppose a service statistic requires querying 8 associated query fields, which are from 8 associated database tables, one of which is a key query field, and the remaining 7 are common query fields, and the filtering condition is the largest according to the key query field. Ten values (ie Top max10) are presented. And assume that each data table needs to query the amount of data is 10 million, the query process is as follows:
先根据关键查询字段在其对应的数据表中查询出关键数据,此时需要访问该数据库表中的1千万条数据才能得到最大的10条数据;再根据这10条数据的时间和/或位置等关联维度字段来匹配查询其余7个查询字段对应数据 库表中的对应数据,此时针对每个普通查询字段,根据数据之间的关联关系只需在对应的数据库表中访问对应的那10条数据即可,因此一共仅需访问1千万零70条数据即可得到最终结果;而采用相关的查询方法则至少需要访问8千万条数据,可见本实施例提供的方案极大的降低了数据库的读写消耗、并有效提升了统计效率。First, according to the key query field, the key data is queried in its corresponding data table. At this time, 10 million pieces of data in the database table need to be accessed to obtain the maximum 10 pieces of data; and then according to the time and/or time of the 10 pieces of data. Associated dimension fields such as location to match the data of the remaining 7 query fields Corresponding data in the library table. At this time, for each common query field, according to the association relationship between the data, only the corresponding 10 pieces of data need to be accessed in the corresponding database table, so only a total of 10 million zeros are needed. 70 data can be used to obtain the final result; and the related query method requires at least 80 million pieces of data to be accessed. It can be seen that the solution provided in this embodiment greatly reduces the reading and writing consumption of the database and effectively improves the statistical efficiency.
实施例二:Embodiment 2:
本实施例提供了数据查询装置,请参见图2所示,数据查询装置1包括条件获取模块11、数据表确定模块12、关键数据查询模块13和关联数据查询模块14;其中:This embodiment provides a data query device. Referring to FIG. 2, the data query device 1 includes a condition acquisition module 11, a data table determination module 12, a key data query module 13, and an associated data query module 14;
条件获取模块11设置成:获取查询条件,该查询条件可以是用户当前输入的,也可以提前预置好的,本实施例中的查询条件包括关键查询字段、与关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;The condition obtaining module 11 is configured to: obtain a query condition, which may be currently input by the user, or may be preset in advance. The query condition in this embodiment includes a key query field and a common query field associated with the key query field. And key query field data filtering conditions;
可选地,关键查询字段数据筛选条件可以为,例如选出最大的N个数据、最小的M个数据或者用户设定范围值内的各数据等等。Optionally, the key query field data filtering condition may be, for example, selecting the largest N data, the smallest M data, or each data within the user set range value.
数据表确定模块12设置成:确定普通查询字段和关键查询字段所分别对应的数据库表;设置普通查询字段和关键查询字段所对应的各数据库表中存储的数据之间的关联关系;The data table determining module 12 is configured to: determine a database table corresponding to the common query field and the key query field respectively; and set an association relationship between the data stored in each database table corresponding to the common query field and the key query field;
可选地,该关联关系包括时间关联、位置关联等纬度关联字段中的至少一种;也即各查询字段对应的各数据库表为关联数据库表;Optionally, the association relationship includes at least one of a latitude association field such as a time association and a location association; that is, each database table corresponding to each query field is an associated database table;
关键数据查询模块13设置成:从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据;The key data query module 13 is configured to: query key data that meets the filtering conditions of the key query field data from the database table corresponding to the key query field;
关联数据查询模块14设置成:根据上述关联关系以及上述普通查询字段从普通查询字段对应的数据库表中查询出与关键数据关联的数据(也即各普通查询字段对应的数据)。The associated data query module 14 is configured to: query the data associated with the key data (that is, the data corresponding to each common query field) from the database table corresponding to the common query field according to the foregoing association relationship and the common query field.
本实施例中的数据查询装置1通过先查询出关键字段对应的关键数据,再利用关联关系直接查询到其他普通字段对应的关联数据,可以呈数量级的降低数据库的数据访问量,能明显降低资源消耗,并提升查询效率。 The data querying apparatus 1 in this embodiment firstly queries the key data corresponding to the key field, and then directly queries the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, and can significantly reduce the data access amount. Resource consumption and improve query efficiency.
本实施例中用户输入的关键字查询字段主要体现相应的查询指标,本实施例中的查询指标包括通过一个查询字段即可体现的指标,也包括通过多个查询字段体现的指标;当通过多个查询字段体现时,本实施例中的关键查询字段包括多个查询字段。因此,本实施例中的数据表确定模块12可包括计算处理子模块,用于当关键查询字段包括多个查询字段时,将多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到新的数据库表,该新的数据库表为关键字查询字段所对应的数据库表。The keyword query field input by the user in the embodiment mainly reflects the corresponding query index. The query indicator in this embodiment includes an indicator that can be embodied by using a query field, and includes an indicator that is reflected by multiple query fields; When the query fields are embodied, the key query field in this embodiment includes multiple query fields. Therefore, the data table determining module 12 in this embodiment may include a calculation processing sub-module, configured to: according to a preset algorithm, corresponding data of the plurality of query fields in the respective database tables when the key query field includes multiple query fields After processing, a new database table is obtained, and the new database table is a database table corresponding to the keyword query field.
例如,假设指标需要结合查询字段A+查询字段B体现,则本实施例中的关键字查询字段包括查询字段A和B;对应的确定数据库表时,分别提取出查询字段A和查询字段B中对应的数据表中的数据并进行相加得到新的数据库表,该新的数据库表即为关键字查询字段(即查询字段A+查询字段B)的数据库表。也即,本实施例中,对于通过多个查询字段运算得到指标的情况,可以先求多个查询字段计算后得到的数据表并从中查询出满足筛选条件(例如最大的10个值)的关键数据,再根据关键数据关联查询其他普通字段的值,可以起到很好的效率优化效果。For example, if the indicator needs to be combined with the query field A+the query field B, the keyword query field in this embodiment includes the query fields A and B; when the corresponding database table is determined, the corresponding corresponding in the query field A and the query field B are respectively extracted. The data in the data table is added to obtain a new database table, which is the database table of the keyword query field (ie, query field A + query field B). That is, in this embodiment, for the case where the index is obtained by multiple query field operations, the data table obtained by calculating the plurality of query fields may be first obtained and the key satisfying the screening condition (for example, the maximum 10 values) may be queried therefrom. Data, and then query the values of other common fields according to the key data association, can achieve a good efficiency optimization effect.
又例如,假设指标通过一个查询字段C即可体现,则本实施例中的关键字查询字段包括查询字段C;对应的确定数据库表时,查询字段C对应的数据表即为关键字查询字段的数据库表。For example, if the indicator is reflected by a query field C, the keyword query field in this embodiment includes the query field C; when the corresponding database table is determined, the data table corresponding to the query field C is the keyword query field. Database Table.
请参见图3所示,本实施例中的数据查询装置还包括比值判断模块15,用于在关键数据查询模块从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据之前,判断关键字查询字段包括的查询字段个数与普通查询字段包括的查询字段个数之比是否小于预设比值;如是,再通知关键数据查询模块从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据;否则,可直接针对各查询字段在各自对应的数据表中进行查询。As shown in FIG. 3, the data querying apparatus in this embodiment further includes a ratio determining module 15 configured to query, in the database table corresponding to the key query field, the key data query module to meet the key data of the key query field data screening condition. Before, it is determined whether the ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than a preset ratio; if yes, the key data query module is notified to query the database table corresponding to the key query field. Key data that meets the key query field data filtering criteria; otherwise, it can be queried directly in each corresponding data table for each query field.
本实施例中的预设比值可以取为小于等于二分之一,例如具体可取值为二分之一,假设关键字查询字段包括的查询字段个数与普通查询字段包括的查询字段个数之比为七分之一,小于预设比值二分之一,先查询关键查询字段对应的关键数据,再利用关联关系查询到关联的其他普通查询字段对应的 数据。The preset ratio in this embodiment may be less than or equal to one-half, for example, the specific value may be one-half, and the number of query fields included in the keyword query field and the number of query fields included in the common query field are assumed. The ratio is one-seventh, less than one-half of the preset ratio. The key data corresponding to the key query field is first queried, and then the associated relationship is used to query the corresponding common query fields. data.
本实施例中,在从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据之前,还包括结合数据库的数据量大小判断是否先查询关键查询字段对应的关键数据,再利用关联关系查询到关联的其他普通查询字段对应的数据。因为对于数据量较小的数据库可直接针对各查询字段在各自对应的数据表中进行查询。请参见图4所示,本实施例中的数据查询装置1还包括数据量判断模块16,用于在关键数据查询模块从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据之前,判断所述数据库表所在的数据库中存储的数据量是否大于预设阈值,如是,再通知关键数据查询模块从关键查询字段对应的数据库表中查询出满足关键查询字段数据筛选条件的关键数据。否则,直接针对各查询字段在各自对应的数据表中进行查询。In this embodiment, before the key data satisfying the data filtering condition of the key query field is queried from the database table corresponding to the key query field, the method further includes determining the key data corresponding to the key query field by combining the data size of the database, and then Use the association relationship to query the data corresponding to other common query fields of the association. Because the database with a small amount of data can be directly queried in the corresponding data table for each query field. As shown in FIG. 4, the data query apparatus 1 in this embodiment further includes a data quantity determining module 16 configured to query, in the database table corresponding to the key query field, the key data query module to meet the filtering conditions of the key query field data. Before the critical data, determining whether the amount of data stored in the database in which the database table is located is greater than a preset threshold, and then notifying the key data query module to query the data table corresponding to the key query field from the database table corresponding to the key query field. Key data. Otherwise, the query is directly made in the corresponding data table for each query field.
本实施例中,对于普通的关系数据库,可以根据该数据库中的数据表个数统计该数据库的数据量;对于列存储数据库,则可根据字段数统计该数据库的数据量,或根据字段数以及数据量规模统计该数据库的数据量。本实施例中的预设阈值可以根据具体的数据库以及应用场景等等具体选定设置。In this embodiment, for a common relational database, the data amount of the database may be counted according to the number of data tables in the database; for the column storage database, the data amount of the database may be counted according to the number of fields, or according to the number of fields and The amount of data is used to count the amount of data in the database. The preset threshold in this embodiment may be specifically selected according to a specific database and an application scenario or the like.
为了更好的理解本发明,下面再以一个具体示例进行说明。In order to better understand the present invention, a specific example will be described below.
假设某业务统计要求查询10个关联的查询字段,分别来自8个关联的数据库表,其中1个为关键查询字段,剩余的9个为普通查询字段,筛选条件为按照该关键查询字段的最小的100个值(也即Top min10)进行呈现。并假设每个数据表需要查询的数据量为1百万条,其查询过程如下:Suppose a service statistic requires querying 10 associated query fields, which are from 8 associated database tables, one of which is a key query field, and the remaining 9 are common query fields, and the filtering condition is the smallest according to the key query field. 100 values (ie Top min10) are presented. And assume that each data table needs to query the amount of data is 1 million, the query process is as follows:
先根据关键查询字段在其对应的数据表中查询出关键数据,此时需要访问该数据库表中的1百万条数据才能得到最小的100条数据;再根据这100条数据的时间和/或位置等关联维度字段来匹配查询其余9个查询字段对应数据库表中的对应数据,此时针对每个普通查询字段,根据数据之间的关联关系只需在对应的数据库表中访问对应的那100条数据即可,因此一共仅需访问1百万零900条数据即可得到最终结果;而采用相关的查询方法则至少需要访问1千万条数据,可见本实施例提供的方案极大的降低了数据库的读写消耗、并有效提升了统计效率。 First, according to the key query field, the key data is queried in its corresponding data table. At this time, it is necessary to access 1 million pieces of data in the database table to obtain the minimum 100 pieces of data; and then according to the time and/or of the 100 pieces of data. Position and other associated dimension fields to match the corresponding data in the database table corresponding to the remaining 9 query fields. At this time, for each common query field, according to the association relationship between the data, only the corresponding 100 in the corresponding database table is accessed. The data is OK, so you only need to access 1 million and 900 data to get the final result. The related query method needs to access at least 10 million data, which shows that the solution provided in this embodiment is greatly reduced. The database read and write consumption, and effectively improve the statistical efficiency.
本发明实施例还公开了一种计算机程序,包括程序指令,当该程序指令被计算机执行时,使得该计算机可执行上述任意的数据查询方法。The embodiment of the invention also discloses a computer program, comprising program instructions, which when executed by a computer, enable the computer to execute any of the above data query methods.
本发明实施例还公开了一种载有所述计算机程序的载体。The embodiment of the invention also discloses a carrier carrying the computer program.
以上内容是结合具体的实施方式对本发明所作的进一步详细说明,不能认定本发明的具体实施只局限于这些说明。对于本发明所属技术领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干简单推演或替换,都应当视为属于本发明的保护范围。The above is a further detailed description of the present invention in connection with the specific embodiments, and the specific embodiments of the present invention are not limited to the description. It will be apparent to those skilled in the art that the present invention may be made without departing from the spirit and scope of the invention.
工业实用性Industrial applicability
本发明实施例通过先查询出关键字段对应的关键数据,再利用关联关系直接查询到其他普通字段对应的关联数据,可以呈数量级的降低数据库的数据访问量,能明显降低资源消耗,并提升查询效率。因此本发明具有很强的工业实用性。 The embodiment of the present invention can firstly query the key data corresponding to the key segment, and then directly query the associated data corresponding to other common fields by using the association relationship, which can reduce the data access amount of the database by an order of magnitude, can significantly reduce resource consumption, and improve Query efficiency. Therefore, the present invention has strong industrial applicability.

Claims (12)

  1. 一种数据查询方法,包括:A data query method, including:
    获取查询条件,其中,所述查询条件包括关键查询字段、与所述关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;Obtaining a query condition, wherein the query condition includes a key query field, a common query field associated with the key query field, and a key query field data filtering condition;
    确定所述普通查询字段和所述关键查询字段所分别对应的数据库表;Determining a database table corresponding to the common query field and the key query field respectively;
    设置所述普通查询字段数据库表中存储的数据和所述关键查询字段所对应的数据库表中存储的数据之间的关联关系;Setting an association relationship between the data stored in the general query field database table and the data stored in the database table corresponding to the key query field;
    根据所述关键字查询字段从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据;Determining, according to the keyword query field, key data that meets the filtering condition of the key query field data from a database table corresponding to the key query field;
    根据所述关联关系从所述普通查询字段对应的数据库表中查询出与所述关键数据关联的数据。And querying, according to the association relationship, data associated with the key data from a database table corresponding to the common query field.
  2. 如权利要求1所述的数据查询方法,其中,当所述关键查询字段包括多个查询字段时,确定所述关键查询字段所对应的数据库表的步骤包括:The data query method according to claim 1, wherein when the key query field includes a plurality of query fields, the step of determining a database table corresponding to the key query field comprises:
    将所述多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到所述关键字查询字段所对应的数据库表。The corresponding data in the respective database tables is processed according to a preset algorithm to obtain a database table corresponding to the keyword query field.
  3. 如权利要求2所述的数据查询方法,其中,所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤之前,该方法还包括:The data query method according to claim 2, wherein before the step of querying the key data corresponding to the data filtering condition of the key query field from the database table corresponding to the key query field, the method further comprises:
    判断所述关键字查询字段包括的查询字段个数与所述普通查询字段包括的查询字段个数之比是否小于预设比值;如果小于,才执行所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤。Determining whether the ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than a preset ratio; if less than, executing the database table corresponding to the key query field The step of querying the key data that satisfies the data filtering condition of the key query field is queried.
  4. 如权利要求1-3中任一项所述的数据查询方法,其中,所述从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤之前,该方法还包括:The data query method according to any one of claims 1 to 3, wherein, before the step of querying the key data satisfying the data filtering condition of the key query field from the database table corresponding to the key query field, The method also includes:
    判断所述关键查询字段对应的数据库表所在的数据库中存储的数据量是否大于预设阈值,如果大于,才执行所述从所述关键查询字段对应的数据库 表中查询出满足所述关键查询字段数据筛选条件的关键数据的步骤。Determining whether the amount of data stored in the database in which the database table corresponding to the key query field is located is greater than a preset threshold, and if yes, executing the database corresponding to the key query field The step of querying the key data that satisfies the data filtering condition of the key query field is queried in the table.
  5. 如权利要求1-3中任一项所述的数据查询方法,其中,所述关联关系包括时间关联和位置关联中的至少一种。The data query method according to any one of claims 1 to 3, wherein the association relationship includes at least one of a time association and a location association.
  6. 一种数据查询装置,包括条件获取模块、数据表确定模块、关键数据查询模块和关联数据查询模块,其中,A data query device includes a condition acquisition module, a data table determination module, a key data query module, and an associated data query module, wherein
    所述条件获取模块设置成:获取查询条件,其中,所述查询条件包括关键查询字段、与所述关键查询字段关联的普通查询字段、以及关键查询字段数据筛选条件;The condition obtaining module is configured to: obtain a query condition, where the query condition includes a key query field, a common query field associated with the key query field, and a key query field data screening condition;
    所述数据表确定模块设置成:确定所述普通查询字段和关键查询字段所分别对应的数据库表,并设置所述普通查询字段所对应的数据库表中存储的数据和所述关键查询字段所对应的数据库表中存储的数据之间的关联关系;The data table determining module is configured to: determine a database table corresponding to the common query field and the key query field, and set data corresponding to the database table corresponding to the common query field and the key query field The relationship between the data stored in the database table;
    所述关键数据查询模块设置成:根据所述关键字查询字段从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据;The key data query module is configured to: query, according to the keyword query field, key data that meets the filtering condition of the key query field data from a database table corresponding to the key query field;
    所述关联数据查询模块设置成:根据所述关联关系从所述普通查询字段对应的数据库表中查询出与所述关键数据关联的数据。The associated data query module is configured to: query data associated with the key data from a database table corresponding to the common query field according to the association relationship.
  7. 如权利要求6所述的数据查询装置,其中,所述数据表确定模块包括计算处理子模块,设置成:The data query device according to claim 6, wherein said data table determining module comprises a computing processing sub-module configured to:
    当所述关键查询字段包括多个查询字段时,将所述多个查询字段在各自的数据库表中的对应数据按照预设算法进行处理后得到新的数据库表,该新的数据库表为所述关键字查询字段所对应的数据库表。When the key query field includes multiple query fields, the corresponding data in the respective database tables are processed according to a preset algorithm to obtain a new database table, and the new database table is The database table corresponding to the keyword query field.
  8. 如权利要求7所述的数据查询装置,该装置还包括比值判断模块,其中,The data query device according to claim 7, further comprising a ratio judgment module, wherein
    所述比值判断模块设置成:判断所述关键字查询字段包括的查询字段个数与所述普通查询字段包括的查询字段个数之比是否小于所述预设比值;如果小于,才通知所述关键数据查询模块从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据。The ratio determining module is configured to: determine whether a ratio of the number of query fields included in the keyword query field to the number of query fields included in the common query field is less than the preset ratio; if not, notify the The key data query module queries, from the database table corresponding to the key query field, key data that satisfies the data filtering condition of the key query field.
  9. 如权利要求6-8中任一项所述的数据查询装置,该装置还包括数据量 判断模块,其中,A data query device according to any one of claims 6-8, further comprising data amount Judging module, wherein
    所述数据量判断模块设置成:判断所述关键查询字段对应的数据库表所在的数据库中存储的数据量是否大于预设阈值,如果大于,才通知所述关键数据查询模块从所述关键查询字段对应的数据库表中查询出满足所述关键查询字段数据筛选条件的关键数据。The data amount judging module is configured to: determine whether the amount of data stored in the database in which the database table corresponding to the key query field is located is greater than a preset threshold, and if not, notify the key data query module from the key query field The corresponding database table queries the key data that meets the filtering conditions of the key query field data.
  10. 如权利要求6-8中任一项所述的数据查询装置,其中,所述关联关系包括时间关联和位置关联中的至少一种。The data query device according to any one of claims 6-8, wherein the association relationship comprises at least one of a time association and a location association.
  11. 一种计算机程序,包括程序指令,当该程序指令被计算机执行时,使得该计算机可执行权利要求1-5中任一项所述的数据查询方法。A computer program comprising program instructions which, when executed by a computer, cause the computer to perform the data query method of any of claims 1-5.
  12. 一种载有权利要求13所述计算机程序的载体。 A carrier carrying the computer program of claim 13.
PCT/CN2014/095684 2014-10-22 2014-12-30 Data query method and device WO2015184782A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410566706.4A CN105589864A (en) 2014-10-22 2014-10-22 Data inquiry method and apparatus
CN201410566706.4 2014-10-22

Publications (1)

Publication Number Publication Date
WO2015184782A1 true WO2015184782A1 (en) 2015-12-10

Family

ID=54766036

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/095684 WO2015184782A1 (en) 2014-10-22 2014-12-30 Data query method and device

Country Status (2)

Country Link
CN (1) CN105589864A (en)
WO (1) WO2015184782A1 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106933930A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 The method and apparatus for screening session
CN106933920A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 The screening technique and device of session
CN108241706A (en) * 2016-12-27 2018-07-03 北京金山云网络技术有限公司 A kind of data storage method and device
CN112131253A (en) * 2019-06-25 2020-12-25 北京沃东天骏信息技术有限公司 Data query method, device, equipment and storage medium
CN112732711A (en) * 2020-12-28 2021-04-30 北京金山云网络技术有限公司 Data storage method and device and electronic equipment
CN113111084A (en) * 2021-03-31 2021-07-13 北京沃东天骏信息技术有限公司 Method and device for processing data

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106326428A (en) * 2016-08-24 2017-01-11 华青融天(北京)技术股份有限公司 Data processing method and device
CN108427684B (en) * 2017-02-14 2020-12-25 华为技术有限公司 Data query method and device and computing equipment
CN109828993B (en) * 2017-08-31 2021-04-27 北京国双科技有限公司 Statistical data query method and device
CN109582694A (en) * 2017-09-29 2019-04-05 北京国双科技有限公司 A kind of method and Related product generating data query script
CN110321344B (en) * 2019-05-20 2024-03-15 深圳市晶测科技有限公司 Information query method and device for associated data, computer equipment and storage medium
CN110609954A (en) * 2019-08-30 2019-12-24 深圳壹账通智能科技有限公司 Data acquisition method and device, computer equipment and storage medium
CN112749190B (en) * 2019-10-31 2023-04-11 中国移动通信集团重庆有限公司 Data query method and device, computing equipment and computer storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101840430A (en) * 2010-04-28 2010-09-22 北京握奇数据系统有限公司 Intelligent card database multi-list operation method and device
CN102521416A (en) * 2011-12-28 2012-06-27 用友软件股份有限公司 Data correlation query method and data correlation query device
CN102799634A (en) * 2012-06-26 2012-11-28 中国农业银行股份有限公司 Data storage method and device
CN102867064A (en) * 2012-09-28 2013-01-09 用友软件股份有限公司 Associated field query device and associated field query method

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101087203A (en) * 2006-06-11 2007-12-12 上海全成通信技术有限公司 A statistical method of high magnitude of data
CN101742002A (en) * 2008-11-05 2010-06-16 北大方正集团有限公司 Method, device and system for managing service information
CN101770479B (en) * 2008-12-31 2012-06-13 亿阳信通股份有限公司 Association relationship query method and device
CN101840400B (en) * 2009-03-19 2012-02-01 北大方正集团有限公司 Multilevel classification retrieval method and system
US20140059069A1 (en) * 2012-08-21 2014-02-27 Michael William Taft Parallel Filter Method and User Interface for Student Database Searching
US10474652B2 (en) * 2013-03-14 2019-11-12 Inpixon Optimizing wide data-type storage and analysis of data in a column store database
CN103488692B (en) * 2013-09-02 2017-02-08 用友网络科技股份有限公司 Data query system and data query method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101840430A (en) * 2010-04-28 2010-09-22 北京握奇数据系统有限公司 Intelligent card database multi-list operation method and device
CN102521416A (en) * 2011-12-28 2012-06-27 用友软件股份有限公司 Data correlation query method and data correlation query device
CN102799634A (en) * 2012-06-26 2012-11-28 中国农业银行股份有限公司 Data storage method and device
CN102867064A (en) * 2012-09-28 2013-01-09 用友软件股份有限公司 Associated field query device and associated field query method

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106933930A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 The method and apparatus for screening session
CN106933920A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 The screening technique and device of session
CN108241706A (en) * 2016-12-27 2018-07-03 北京金山云网络技术有限公司 A kind of data storage method and device
CN108241706B (en) * 2016-12-27 2020-12-25 北京金山云网络技术有限公司 Data warehousing method and device
CN112131253A (en) * 2019-06-25 2020-12-25 北京沃东天骏信息技术有限公司 Data query method, device, equipment and storage medium
CN112732711A (en) * 2020-12-28 2021-04-30 北京金山云网络技术有限公司 Data storage method and device and electronic equipment
CN113111084A (en) * 2021-03-31 2021-07-13 北京沃东天骏信息技术有限公司 Method and device for processing data

Also Published As

Publication number Publication date
CN105589864A (en) 2016-05-18

Similar Documents

Publication Publication Date Title
WO2015184782A1 (en) Data query method and device
JP6964384B2 (en) Methods, programs, and systems for the automatic discovery of relationships between fields in a mixed heterogeneous data source environment.
US7930294B2 (en) Method for partitioning a query
US8996499B2 (en) Using temporary performance objects for enhanced query performance
US11687546B2 (en) Executing conditions with negation operators in analytical databases
US20140331235A1 (en) Resource allocation apparatus and method
US10872086B2 (en) Selectivity estimation for database query planning
CN110795458B (en) Interactive data analysis method, device, electronic equipment and computer readable storage medium
WO2016134580A1 (en) Data query method and apparatus
WO2015155561A1 (en) Accessing non-relational data stores using structured query language queries
US10795889B2 (en) Query path with aggregate projection
US11074259B2 (en) Optimize query based on unique attribute
US9734176B2 (en) Index merge ordering
US20210182293A1 (en) Candidate projection enumeration based query response generation
US8805811B2 (en) Executing user-defined function on a plurality of database tuples
WO2015131579A1 (en) Data storage method, apparatus and system
US10191942B2 (en) Reducing comparisons for token-based entity resolution
CN111459937A (en) Data table association method, device, server and storage medium
Rao et al. Efficient Iceberg query evaluation using compressed bitmap index by deferring bitwise-XOR operations
Lou et al. Research on data query optimization based on SparkSQL and MongoDB
US20140324868A1 (en) Method for rapid data classification
US20210240708A1 (en) Techniques for executing join operations using bitmap indices
WO2010089403A4 (en) Two-valued logic database management system with support for missing information
WO2015058628A1 (en) File access method and device
CN113032400B (en) High-performance TopN query method, system and medium for mass data

Legal Events

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

Ref document number: 14893951

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14893951

Country of ref document: EP

Kind code of ref document: A1