WO2017067117A1 - 数据查询方法和装置 - Google Patents

数据查询方法和装置 Download PDF

Info

Publication number
WO2017067117A1
WO2017067117A1 PCT/CN2016/073808 CN2016073808W WO2017067117A1 WO 2017067117 A1 WO2017067117 A1 WO 2017067117A1 CN 2016073808 W CN2016073808 W CN 2016073808W WO 2017067117 A1 WO2017067117 A1 WO 2017067117A1
Authority
WO
WIPO (PCT)
Prior art keywords
index
data
row
query
target
Prior art date
Application number
PCT/CN2016/073808
Other languages
English (en)
French (fr)
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 华为技术有限公司
Priority to EP16856564.6A priority Critical patent/EP3236365A4/en
Publication of WO2017067117A1 publication Critical patent/WO2017067117A1/zh
Priority to US15/958,267 priority patent/US20180239800A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2272Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/248Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9017Indexing; Data structures therefor; Storage structures using directory or table look-up

Definitions

  • the present invention relates to the field of databases, and in particular, to a data query method and apparatus.
  • a database table is an object used to store data in a database.
  • a database table usually stores multiple values in the form of rows and columns.
  • One row of data is a record (for example, all information of a person in the address book database), and a column of data ( A field) records all values of the same data type in the database table (such as the home address of everyone in the address book database).
  • An index is a structure that sorts the values of one or more columns in a database table.
  • the index usually includes a primary index (primary index) and a secondary index. The primary index records data of all the rows in the database table.
  • Each row of data is called an index row, and each column of data is called an index column, and each row is called an index column.
  • Any index data in the data corresponds to the row primary key (Rowkey) of the row, and the secondary index is usually established according to the index primary column in the primary index and the row primary key corresponding to each index data in the index column.
  • the client needs to query according to the index column of the query data (the query data is an index data in the entire row of data that the client wants to obtain)
  • the query data has multiple secondary indexes established by multiple index columns to which the query belongs, and each time a secondary index is queried, the client sends a query request (including query data) to the server (the database is located at the server). After receiving the query request, the server queries the corresponding secondary index.
  • the server After querying multiple secondary indexes, the server returns the result of multiple queries to the client (if multiple secondary indexes are queried) If the query data exists, the row primary key corresponding to the query data is obtained, and the main index is obtained according to the row primary key to obtain the entire row data corresponding to the row primary key, and finally the entire row data is returned to the client, if not in the multiple secondary indexes If the query data is queried, an indication that the data does not satisfy the condition is returned to the client). For example, the query data is a phone number, and the phone number as the query data may belong to any one of the three columns of the mobile phone number, the home number, and the office number in the main index, and the client needs to send a query to the server according to the phone number when querying.
  • the server queries the three indexes according to the three requests for querying the three indexes, and then the server provides the client to the client. The end returns the query result of querying these three indexes.
  • the inventor has found that the above method has at least the following defects: when performing the query, the foregoing method needs to separately query multiple secondary indexes, and the operation of the query process is multiplied and the query efficiency is low.
  • the present application provides a data query method and device.
  • the technical solution is as follows:
  • a data query method comprising:
  • the database end receives the query request sent by the client and includes the query data, and the query data is an index data recorded in the main index;
  • the database side queries the target secondary index in the primary index according to the received query request, and obtains a target row primary key corresponding to the query data, wherein the target secondary index includes a first index column, and the first index column records the primary index.
  • the second index column refers to the index column in the main index;
  • the database side queries the primary index according to the target row primary key, and obtains the index data in the target index row corresponding to the target row primary key, and the index data in the target index row is the data that the client wants to acquire;
  • the database side provides the client with the query of the index data completion data in the target index row.
  • the data query method provided by the present application queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column of the target secondary index, and the row primary key corresponding to the query data is obtained. Then, the index data corresponding to the primary key of the row is obtained, and the related technology needs to separately query multiple secondary indexes when performing the query, the operation of the query process is multiplied, and the query efficiency is low;
  • the query data can be queried in multiple second index columns, and the query process is simple and the query efficiency is high.
  • the method further includes:
  • the database side obtains index data in at least two second index columns from the primary index
  • the database side maps the index data in the at least two second index columns acquired into one virtual column, and the virtual column records the index data in the at least two second index columns;
  • the target secondary index is established according to the row primary key corresponding to each index data in the virtual column and the virtual column, and the virtual column is the first index column in the target secondary index.
  • the database side establishes the target secondary index, it can set an identifier for the target secondary index, which can distinguish and identify the target secondary index.
  • the target primary index may record the row primary key corresponding to each index data, or may not record the row primary key corresponding to each index data, but establish each index data between the row primary key corresponding to the index data in the primary index.
  • the mapping causes each index data to point to the row primary key of an index row in the primary index.
  • the process of establishing a secondary index may include a secondary index definition process and a data filling process, wherein the secondary index definition process is a process of establishing a secondary indexed architecture, the architecture may be considered as a table, and the table is determined
  • the process of filling the index data of the primary index and the identifier of the secondary index; and the data filling process is the process of filling the index data in the virtual column into the architecture of the secondary index.
  • the implementation method is a process of establishing a target secondary index, and the database side can establish any secondary index by the method.
  • the data query method provided by the present application uses the virtual column as the first index column of the secondary index, and achieves the effect that the first index column in the target secondary index can include multiple second index columns in the primary index.
  • each second index column in the primary index corresponds to one data type
  • the target secondary cable is established according to the row primary key corresponding to each index data in the virtual column and the virtual column, including:
  • the database determines the data type of each index data in the virtual column according to the data type corresponding to each index column in the at least two second index columns in the primary index that has a mapping relationship with the virtual column;
  • the data type of each index data in the virtual column is used as an additional column of the target secondary index, and the additional column may indicate the data of each index data in the first index column of the secondary index. Types of.
  • the data query method provided by the present application achieves the effect of being able to query the data type in the secondary index by adding an additional column in the secondary index.
  • the method further includes:
  • the database end receives the write request sent by the client and includes the newly added index row;
  • the database side writes the newly added index row to the primary index, and assigns a corresponding row primary key to the newly added index row;
  • the database end determines at least two second index columns corresponding to the virtual columns in the target secondary index, where the second index column corresponding to the virtual columns is a second index column that has a mapping relationship with the virtual columns;
  • the database side obtains index data belonging to at least two second index columns corresponding to the virtual column from the newly added index row;
  • the database side writes the index data belonging to the at least two second index columns in the newly added index row to the target secondary index, and completes the update of the target secondary index.
  • the implementation manner is an update process of the target secondary index. After receiving the write request, the database end may update any secondary index according to the manner.
  • the query request further includes an identifier of the target data type and the target secondary index, and the target secondary index of the primary index is queried according to the query request, and the target row primary key corresponding to the query data is obtained, including:
  • the database end determines the target secondary index according to the identifier of the target secondary index, where the identifier may be the name of the target secondary index, and the like, and the data of the target secondary index may be identified;
  • the database side searches for the target index row in which the target data type and the query data are recorded in the target secondary index
  • the row primary key of the target secondary index row is determined as the target row primary key.
  • the data query method provided by the present application uses the target data type and the query data to query the target secondary index with the additional column, thereby achieving the effect of narrowing the search range.
  • a data query device comprising:
  • a request receiving unit configured to receive a query request of the client, where the query request includes query data
  • An index query unit is configured to query a target secondary index of the primary index according to the query request, and obtain a target row primary key corresponding to the query data, where the target secondary index includes a first index column, and the first index column records at least two of the primary indexes.
  • Index data in the second index column, each index data of at least two second index columns respectively corresponding to one row primary key, and the row primary key corresponds to one index row in the primary index;
  • a data obtaining unit configured to obtain index data in a target index row corresponding to the target row primary key from the primary index
  • a data providing unit for providing index data in the target index row to the client.
  • the device also includes:
  • An index data obtaining unit configured to obtain an index in at least two second index columns from a primary index data
  • a virtual mapping unit configured to map index data in at least two second index columns into one virtual column, and record index data in at least two second index columns in the virtual column;
  • An index establishing unit is configured to establish a target secondary index according to a row primary key corresponding to each index data in the virtual column and the virtual column, where the virtual column is the first index column in the target secondary index.
  • each of the second index columns in the primary index corresponds to a data type
  • an index establishing unit is used to:
  • the target secondary index is established according to the row key value corresponding to each index data in the virtual column and the virtual column and the data type of each index data in the virtual column, and the data type of each index data in the virtual column constitutes an additional target secondary index Column.
  • the device also includes:
  • the write receiving unit is configured to receive a write request of the client, where the write request includes a new index row;
  • An index writing unit configured to write a new index row to the primary index, and assign a corresponding row primary key to the newly added index row;
  • An index column determining unit configured to determine at least two second index columns corresponding to the virtual columns in the target secondary index
  • a new data obtaining unit configured to obtain index data belonging to at least two second index columns from the newly added index row
  • a data writing unit configured to write index data belonging to at least two second index columns in the newly added index row to the target secondary index.
  • the query request also includes an identifier of the target data type and the target secondary index, and an index query unit for:
  • the index data in the target secondary index row is the same as the query data
  • the data type in the target secondary index row is the same as the target data type
  • the row primary key of the target secondary index row is determined as the target row primary key.
  • the index data in the at least two second index columns is recorded in one index column of the target secondary index, the row primary key corresponding to the query data is obtained, and the index corresponding to the row primary key is obtained.
  • the data solves the problem that the related technologies need to separately query multiple secondary indexes when performing the query, the operation of the query process is multiplied, and the query efficiency is low; and the second index column can be queried after performing one query.
  • the effect of the index data in the query process is simple and the query efficiency is high.
  • FIG. 1 is a schematic structural diagram of an implementation environment involved in a data query method according to various embodiments of the present invention
  • FIG. 2 is a flowchart of a data query method according to an embodiment of the present invention.
  • 3-1 is a flowchart of another data query method according to an embodiment of the present invention.
  • FIG. 3-1 is a flowchart of establishing a secondary index in the embodiment shown in FIG. 3-1;
  • 3-3 is a schematic diagram of a secondary index in the embodiment shown in FIG. 3-1;
  • Figure 3-4 is a schematic diagram of another secondary index in the embodiment shown in Figure 3-1;
  • FIG. 3-1 is a schematic diagram of another secondary index in the embodiment shown in FIG. 3-1;
  • FIG. 3-1 is a flowchart of obtaining a target row key value in the embodiment shown in FIG. 3-1;
  • 4-1 is a flowchart of another data query method according to an embodiment of the present invention.
  • 4-2 is a schematic diagram of writing a new index row to a primary index in the embodiment shown in FIG. 4-1;
  • 4-3 is a schematic diagram of obtaining index data from an index column in the embodiment shown in FIG. 4-1;
  • 5-1 is a block diagram of a data query apparatus according to an embodiment of the present invention.
  • FIG. 5-2 is a block diagram of another data query apparatus according to an embodiment of the present invention.
  • FIG. 5-3 is a block diagram of another data query apparatus according to an embodiment of the present invention.
  • FIG. 6 is a structural diagram of a data query apparatus according to an embodiment of the present invention.
  • FIG. 1 is a schematic structural diagram of an implementation environment involved in a data query method according to various embodiments of the present invention.
  • the implementation environment may include: a client 11 and a database terminal 12.
  • the client 11 is a terminal for the user to query data in the database, and the client 11 may be a terminal such as a mobile phone and a computer. This implementation environment does not limit the number of clients 11.
  • the database side 12 stores the data of the database, which can be used by the client 11 for querying.
  • the database end 12 can be a server, or a server cluster composed of several servers, or a cloud computing service center.
  • the client 11 and the database 12 can be connected to each other by a wired connection or a wireless connection.
  • the client 11 and the database 12 can also be located in one device, and the implementation environment is not limited.
  • FIG. 2 is a flowchart of a data query method according to an embodiment of the present invention.
  • the data query method is applied to the database terminal 12 in the implementation environment shown in FIG. 1 to illustrate.
  • the data query method can include the following steps:
  • Step 201 Receive a query request of a client, where the query request includes query data.
  • Step 202 Query a target secondary index of the primary index according to the query request, and obtain a target row primary key corresponding to the query data.
  • the target secondary index includes a first index column, and the first index column records at least two seconds in the primary index. Index data in the index column, each of the at least two second index columns corresponds to one row primary key, and the row primary key corresponds to one index row in the primary index.
  • Step 203 Obtain index data in a target index row corresponding to the target row primary key from the primary index.
  • Step 204 Provide the client with index data in the target index row.
  • the data query method queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, which solves the problem that the related technology needs to separately query multiple secondary indexes when performing the query, and the query process
  • the operation is multiplied and the query efficiency is low; the effect of querying the index data in multiple second index columns can be achieved by performing one query, and the query process is simple and the query efficiency is high.
  • FIG. 3-1 is a flowchart of another data query method according to an embodiment of the present invention.
  • the data query method is applied to the database terminal 12 in the implementation environment shown in FIG. 1 to illustrate.
  • the data query method can include the following steps:
  • Step 301 Establish at least one secondary index according to a second index column in the primary index, where the at least one secondary index includes a target secondary index.
  • At least one secondary index may be first established according to the second index column in the primary index, where the at least one secondary index may include the target secondary index, and the target secondary index is once A secondary index that is required in a data query (such as a data query performed by an embodiment of the present invention).
  • the second index column involved in various embodiments of the present invention refers to an index column in the main index.
  • the target secondary index (the secondary index used in the query in the embodiment of the present invention) is used as an example, as shown in FIG. 3-2.
  • This step can include the following three substeps:
  • Sub-step 3011 Obtain index data in at least two second index columns from the primary index.
  • index data in at least two second index columns may be first obtained from a primary index of the database.
  • the index data of the at least two second index columns may be data that is subsequently used to establish a target secondary index.
  • the selection may be performed according to the size of the selection degree of each second index column in the primary index, where the selection degree is different index data in a second index column.
  • index data in a plurality of (at least two) second index columns having a large degree of selection in the primary index may be acquired.
  • the second index column may be selected in other manners to improve the query efficiency of the subsequently established target secondary index, which is not limited in the embodiment of the present invention.
  • Sub-step 3012 the index data in the at least two second index columns is mapped into one virtual column, and the index data in the at least two second index columns is recorded in the virtual column.
  • the index data in the at least two second index columns may be mapped into one virtual column, and the index in the at least two second index columns in the virtual column is recorded data. Since the secondary index in the database is generally established according to the index data in a second index column in the primary index, the secondary index established in the embodiment of the present invention needs to be based on at least two second index columns in the primary index.
  • the index data is established, and no second index column in the main index contains the index data of the at least two second index columns, so that a virtual column can be first established, and the virtual column corresponds to the at least two
  • the index data in the index column can be followed by the virtual column as the first index column of the secondary index.
  • the target secondary index is established according to the row primary key corresponding to each index data in the virtual column and the virtual column, and the virtual column is the first index column in the target secondary index.
  • the target secondary index can be established according to the row primary key corresponding to each index data in the virtual column and the virtual column.
  • the row master key can be obtained through the main index.
  • the architecture of the target secondary index may be first established, (the establishment process may be referred to as a process of defining the target secondary index),
  • the architecture can be understood as a table of unfilled data (the table determines which columns of the primary index need to be filled in and the name of the target secondary index), after which the index data in the virtual column can be filled in. That is, the target secondary index can contain the schema with the target secondary index and the index data filled in the schema.
  • the architecture of the target secondary index may be determined first, and then the index data in the primary index may be obtained. Finally, the index data is filled in the architecture of the target secondary index, which is not limited in the embodiment of the present invention.
  • the first index column involved in various embodiments of the present invention refers to an index column in a secondary index.
  • the name of the secondary index can be set, and the name is used as the identifier of the secondary index, so that the user can select the secondary index and the database side distinguishes the secondary index.
  • the name of the target secondary index reference may be made to multiple data types of the index data in the virtual column (including the index data of the plurality of second index columns in the primary index) in the secondary index, exemplary. If the virtual column in a secondary index contains index data of three data types of data type "mobile phone number", "landline number” and "office number”, the secondary index may be named "phone number”. This is a naming manner for the data type in the primary index, and the secondary index established by the embodiment of the present invention may have other naming manners, which is not limited in the embodiment of the present invention.
  • This step can be used to establish the target secondary index.
  • the virtual column is used as the first index column in the target secondary index, and a mapping between each index data in the first index column and the row primary key corresponding to the index data in the primary index is established. That is, each index data in the first index column of the target secondary index is directed to the row primary key of one index row in the primary index.
  • the index column ⁇ is the name of the first index column L1. The name can be set by the database. In the secondary index S2, only the first index column L1 is actually recorded. Each index data in an index column L1 is mapped to a row primary key of an index row in the main index S1. It should be noted that the plurality of index data in the first index column L1 may be mapped into one row primary key in the main index S1.
  • the virtual column is used as the first index column in the target secondary index, and a row primary key column is established, so that each index data in the first index column of the target secondary index is in the same row as the corresponding row primary key, that is, The primary key is directly recorded in the target secondary index, as shown in FIG. 3-4, wherein the secondary index S2 includes a first index column L1 and a row primary key column K1, and each index data in the first index column L1 is associated with each row.
  • the row primary key of the same row in the primary key column K1 corresponds.
  • an additional column may also be added to the target secondary index, and the process may include:
  • the data type of each index data in the virtual column may be determined according to the data type corresponding to the index data in the at least two second index columns.
  • Each of the second index columns in the primary index corresponds to one data type, and each index data in the second index column is the same data type.
  • a second index column corresponds to the data type "date of birth", and the data type of any index data recorded in the second index column is "date of birth”.
  • the target secondary index that is, the virtual column
  • the target secondary index may be established according to the row key value corresponding to each index data in the virtual column and the virtual column and the data type of each index data in the virtual column.
  • the data type of each index data constitutes an additional column of the target secondary index, as shown in FIG. 3-5, which is the target secondary index established by the second mode, and the target secondary index S2 includes the first An index column L1, a row primary key column K1, and an additional column F.
  • the target secondary index established by one mode includes the first index column and the additional column, and details are not described herein again.
  • each index in the virtual column may also be used.
  • the data type of the data is directly recorded in the virtual column, so that the database side distinguishes when the index data in the virtual column is duplicated, wherein the data type of the index data can indicate the second index column to which the index data belongs in the primary index.
  • the database side can establish a plurality of secondary indexes including the target secondary index through steps 3011 and 3013.
  • Step 302 Receive a query request of a client, where the query request includes query data.
  • the query request of the client may be received, where the query request includes query data, and the query data is an index data in the primary index.
  • the query request may further include an identifier of the target secondary index, which is used to determine the target secondary index among the multiple secondary indexes.
  • Step 303 Query a target secondary index of the primary index according to the query request, and obtain a target row primary key corresponding to the query data.
  • the database side can query the target secondary index of the primary index according to the query request, and obtain the target row primary key corresponding to the query data.
  • the target secondary index includes a first index column, and the first index column records index data in at least two second index columns in the primary index, and each index data in each of the at least two second index columns corresponds to one
  • the row primary key, the row primary key corresponds to an index row in the primary index.
  • the query index can query the second index column of the plurality of primary indexes, and the secondary index in the prior art is based on the primary A second index column is established in the index, and only one second index column in the primary index can be queried in one query operation. To achieve the same search effect as the secondary index established in the embodiment of the present invention, multiple times are required. Query, the query efficiency is low.
  • the name of the column can be named for the data type of the second index column in the main index.
  • the secondary index named "OfficePhone” is According to the second index column named "OfficePhone", "185333” is the query data.
  • the statement indicates that the database side queries the three second index columns named "HomePhone", “Telphone”, and “OfficePhone” in the main index named "UserInfo”, and queries the data "185333”. Level index. When the amount of data in the main index is large, the query will seriously consume the performance of the database and affect the query speed.
  • this step can include the following three sub-steps:
  • the target secondary index is determined based on the identity of the target secondary index.
  • the database side can first determine the target secondary index in the multiple secondary indexes of the primary index according to the identifier of the target secondary index.
  • the target secondary index row is determined in the target secondary index according to the target data type and the query data, the index data in the target secondary index row is the same as the query data, and the data type in the target secondary index row Same as the target data type.
  • the database side may determine the target secondary index row in the target secondary index according to the target data type and the query data, and the index data in the target secondary index row is the same as the query data, and the target secondary index
  • the data type in the row is the same as the target data type, that is, the database finds the row with the same data as the target data type and the query data, and determines the row as the target secondary index row.
  • the secondary index when the secondary index includes an additional column, the secondary index can be regarded as a composite index, and when the secondary index is queried according to the target data type and the query data, the effect of reducing the query range can be achieved.
  • the database is usually sorted according to the index data, so the same index data will be arranged adjacently, so that when the database side queries in the secondary index, it only needs to query all the recorded target data in the secondary index.
  • a row of type, or a row in the secondary index that queries all records with query data can complete the query for the secondary index.
  • due to The data type has a high repetition rate, so the secondary index can be arranged by data type.
  • Table 1 it is a schematic table of a secondary index.
  • the leftmost column in Table 1 is the row primary key column, the middle column is the additional column added by the data type, and the rightmost column is the first index column in which the index data is recorded, and the order of the sorting is sorted by the additional column.
  • the query data in the query request is "169", and the target data type is "male". When the database side queries, it only needs to start from the first line, and after querying all the index rows listed as "male", it can be completed. A query for this secondary index.
  • the row primary key of the target secondary index row is determined as the target row primary key.
  • the database side can obtain the row primary key of the target secondary index row through the target secondary index, and determine the row primary key as the target row primary key.
  • Step 304 Obtain index data in a target index row corresponding to the target row primary key from the primary index.
  • the database side may obtain the index data in the target index row corresponding to the target row primary key from the primary index, where the index data is the data that the client wants to obtain.
  • the primary index is the primary index S1 in FIG. 3-3
  • the target row primary key is “3”
  • the index data “3a, 3b, 3c, 3d” can be obtained from the primary index S1.
  • Step 305 providing the client with index data in the target index row.
  • the database side can provide the index data in the target index row to the client to complete the query request of the client.
  • the data query method provided by the embodiment of the present invention can achieve the index data according to the virtual column and the virtual column by mapping the index data in the at least two second index columns into one virtual column.
  • the corresponding row primary key establishes the effect of the secondary index.
  • the data query method queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, and the related technologies need to separately query multiple secondary indexes when performing the query, and the operation of the query process is multiplied and the query efficiency is low.
  • Problem; it is possible to query multiple times by performing a query The effect of the index data in the second index column, the query process is simple, and the query efficiency is high.
  • FIG. 4-1 is a flowchart of another data query method according to an embodiment of the present invention. This embodiment is exemplified by the data query method applied to the database terminal 12 in the implementation environment shown in FIG.
  • the data query method can include the following steps:
  • Step 401 Establish at least one secondary index according to a second index column in the primary index, where the at least one secondary index includes a target secondary index.
  • At least one secondary index may be first established according to the second index column in the primary index, where the at least one secondary index may include the target secondary index, and the target secondary index is once The secondary index that is needed in the query (query performed by the embodiment of the present invention) is used.
  • step 301 For the step, reference may be made to step 301 in the embodiment shown in Figure 3-1, and details are not described herein again.
  • Step 402 Receive a write request from a client, where the write request includes a new index row.
  • the client may send a write request to the database through the client, the write The incoming request contains a new index row.
  • step 403 the newly added index row is written into the main index, and the corresponding row primary key is assigned to the newly added index row.
  • FIG. 4-2 it is a schematic diagram of the newly added index row z being written into the main index S1 to obtain the updated main index S1.
  • the main index S1 includes the name “mobile number” and “landline”. 4 second index columns of number, name, and office number, and a row primary key column.
  • the newly added index row z records "mobile number", “landline number”, "name", and "office number”. For 4 types of data, a new index row z is added to the last index row in the main index S1.
  • Step 404 Determine at least two second index columns corresponding to the virtual columns in the target secondary index.
  • the target secondary index can be updated.
  • the target secondary index can be determined first. At least two second index columns corresponding to the virtual column.
  • the second index column corresponding to the virtual column is a second index column that has a mapping relationship with the virtual column.
  • Step 405 Acquire index data belonging to the at least two second index columns from the newly added index row.
  • the index data belonging to the second index columns may be obtained from the newly added index row.
  • it is a main index S1 in which a new index row z is written, and if the second index column corresponding to the virtual column in the target secondary index is a “mobile number” and a “seat number” ", you can get the index data "139xxxx2" and "023xxxx3" belonging to "mobile number” and "landline number”.
  • Step 406 Write index data belonging to the at least two second index columns in the newly added index row to the target secondary index.
  • the index data may be written to the target secondary index, and at the same time, the row primary key of the newly added index row may be added.
  • the primary index S1 shown in FIG. 4-3 is taken as an example. If the secondary index S2 is established according to the second index column “mobile phone number” and “landline number”, the new acquired in step 406 is obtained.
  • index data of the two second index columns in the index row z is "139xxxx2" and "023xxxx3"
  • "139xxxx2" and "023xxxx3” can be written to the secondary index S2 and the row primary key of the index row z is newly added.
  • "101" is written to the secondary index S2, or a mapping relationship between "139xxxx2" and "023xxxx3” and the row primary key "101" of the newly added index row z is established in the secondary index S2.
  • Steps 402 to 406 are steps of updating the target secondary index, and the database side may update any secondary index according to the steps.
  • Step 407 Receive a query request of the client, where the query request includes query data.
  • the database end can receive the query request of the client, and the query request includes the query data, and the query data is an index data in the main index.
  • the query request may further include an identifier of the target secondary index, which is used to determine the target secondary index among the multiple secondary indexes.
  • Step 408 Query the target secondary index of the primary index according to the query request, and obtain a target row primary key corresponding to the query data.
  • the database side can query the target secondary index of the primary index according to the query request, and obtain the target row primary key corresponding to the query data.
  • the target secondary index includes a first index column, and the first index column records index data in at least two second index columns in the primary index, and each index data in each of the at least two second index columns corresponds to one Row master key The key corresponds to an index row in the primary index.
  • step 304 For the step, refer to step 304 in the embodiment shown in Figure 3-1, and details are not described herein.
  • Step 409 Obtain index data in a target index row corresponding to the target row primary key from the primary index.
  • the index data in the target index row corresponding to the target row primary key may be obtained from the primary index, where the index data is data that the client wants to obtain.
  • Step 410 providing the client with index data in the target index row.
  • the database side can provide the index data in the target index row to the client to complete the query request of the client.
  • the data query method provided by the embodiment of the present invention obtains a write request sent by the client, and updates the secondary index according to the write request, so that a plurality of second index columns can be recorded on the record. The effect of updating the secondary index of the index data in the update.
  • the data query method queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, and the related technologies need to separately query multiple secondary indexes when performing the query, and the operation of the query process is multiplied and the query efficiency is low.
  • the problem is that the query data in the second index column can be queried by performing a query, and the query process is simple and the query efficiency is high.
  • the data query apparatus can be implemented as part or all of the database terminal 12 by software, hardware, or a combination of both.
  • the data querying device 500 can include:
  • the request receiving unit 501 is configured to receive a query request of the client, where the query request includes query data.
  • the index query unit 502 is configured to query the target secondary index of the primary index according to the query request, and obtain the target row primary key corresponding to the query data, where the target secondary index includes the first index column, and the first index column records at least the primary index.
  • the data obtaining unit 503 is configured to obtain index data in a target index row corresponding to the target row primary key from the primary index.
  • the data providing unit 504 is configured to provide the client with index data in the target index row.
  • the data query apparatus queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, and the related technologies need to separately query multiple secondary indexes when performing the query, and the operation of the query process is multiplied and the query efficiency is low.
  • the problem is that the query data in the second index column can be queried by performing a query, and the query process is simple and the query efficiency is high.
  • the data querying apparatus 500 further includes:
  • the index data obtaining unit 505 is configured to obtain index data in at least two second index columns from the primary index.
  • the virtual mapping unit 506 is configured to map the index data in the at least two second index columns into one virtual column, and the index data in the at least two second index columns is recorded in the virtual column.
  • the index establishing unit 507 is configured to establish a target secondary index according to the row primary key corresponding to each index data in the virtual column and the virtual column, where the virtual column is the first index column in the target secondary index.
  • each of the second index columns in the primary index corresponds to one data type
  • the index establishing unit 507 is configured to:
  • the target secondary index is established according to the row key value corresponding to each index data in the virtual column and the virtual column and the data type of each index data in the virtual column, and the data type of each index data in the virtual column constitutes an additional target secondary index Column.
  • the data query apparatus 500 further includes:
  • the write receiving unit 508 is configured to receive a write request of the client, where the write request includes a new index row.
  • the index writing unit 509 is configured to write the newly added index row to the primary index, and assign a corresponding row primary key to the newly added index row.
  • the index column determining unit 510 is configured to determine at least two second index columns corresponding to the virtual columns in the target secondary index.
  • a new data obtaining unit 511 configured to acquire at least two second cables from the newly added index row Index data in the list.
  • the data writing unit 512 is configured to write index data belonging to at least two second index columns in the newly added index row to the target secondary index.
  • the query request further includes an identifier of the target data type and the target secondary index
  • the index query unit 502 is configured to:
  • the target secondary index is determined according to the identity of the target secondary index.
  • the target secondary index row is determined in the target secondary index according to the target data type and the query data.
  • the index data in the target secondary index row is the same as the query data, and the data type in the target secondary index row is the same as the target data type.
  • the row primary key of the target secondary index row is determined as the target row primary key.
  • the data query apparatus can achieve the index data according to the virtual column and the virtual column by mapping the index data in the at least two second index columns into one virtual column.
  • the corresponding row primary key establishes the effect of the secondary index.
  • the data query device obtains a write request sent by the client, and updates the secondary index according to the write request, so that a plurality of second index columns can be recorded on the record. The effect of updating the secondary index of the index data in the update.
  • the data query apparatus queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, and the related technologies need to separately query multiple secondary indexes when performing the query, and the operation of the query process is multiplied and the query efficiency is low.
  • the problem is that the query data in the second index column can be queried by performing a query, and the query process is simple and the query efficiency is high.
  • FIG. 6 is a structural diagram of a data query apparatus according to an embodiment of the present invention, including at least one processor 610 (for example, a CPU), at least one network interface 620 or other communication interface, a memory 630, and at least one communication bus 640, for Achieve connection communication between these devices.
  • the processor 610 is configured to execute the program 631 stored in the memory 630.
  • the memory 630 may include a high speed random access memory (RAM), and may also include a non-volatile memory such as at least one disk memory.
  • the communication connection between the data query device and the at least one other network element is implemented by at least one network interface 620 (which may be wired or wireless), and may use an Internet, a wide area network, a local network, a metropolitan area network, or the like.
  • the network interface 620 is configured to receive a query request of the client, where the query request includes query data.
  • the processor 610 is configured to query a target secondary index of the primary index according to the query request, and obtain a target row primary key corresponding to the query data, where the target secondary index includes a first index column, and the first index column records at least two of the primary indexes.
  • the index data in the second index column, each of the at least two second index columns corresponds to a row primary key, and the row primary key corresponds to one index row in the primary index.
  • the processor 610 is configured to obtain index data in a target index row corresponding to the target row primary key from the primary index.
  • the network interface 620 is configured to provide the client with index data in the target index row.
  • the processor 610 is configured to obtain index data in the at least two second index columns from the primary index.
  • the processor 610 is configured to map the index data in the at least two second index columns into one virtual column, and record the index data in the at least two second index columns in the virtual column.
  • the processor 610 is configured to establish a target secondary index according to a row primary key corresponding to each index data in the virtual column and the virtual column, where the virtual column is the first index column in the target secondary index.
  • each second index column in the primary index corresponds to one data type.
  • the processor 610 is configured to determine, according to a data type corresponding to each of the second index columns of the at least two second index columns in the primary index, a data type of each index data in the virtual column.
  • the processor 610 is configured to establish a target secondary index according to a row key value corresponding to each index data in the virtual column and the virtual column and a data type of each index data in the virtual column, and the data type of each index data in the virtual column is composed. An additional column for the target secondary index.
  • the network interface 620 is configured to receive a write request of the client, where the write request includes a new index row.
  • the processor 610 is configured to write a new index row to the primary index, and allocate a corresponding row primary key for the newly added index row.
  • the processor 610 is configured to determine at least two second index columns corresponding to the virtual columns in the target secondary index.
  • the processor 610 is configured to obtain index data belonging to at least two second index columns from the newly added index row.
  • the processor 610 is configured to write index data belonging to at least two second index columns in the newly added index row to the target secondary index.
  • the query request further includes an identifier of the target data type and the target secondary index.
  • the processor 610 is configured to determine a target secondary index according to the identifier of the target secondary index.
  • the processor 610 is configured to determine a target secondary index row in the target secondary index according to the target data type and the query data, where the index data in the target secondary index row is the same as the query data, and the data type in the target secondary index row is The target data type is the same.
  • the processor 610 is configured to determine a row primary key of the target secondary index row as a target row primary key.
  • the data query apparatus achieveds that the index data in the at least two index columns can be mapped to the virtual index and the index data in the virtual column.
  • the primary key of the row establishes the effect of the secondary index.
  • the data query device obtains a write request sent by the client, and updates the secondary index according to the write request, so that a plurality of second index columns can be recorded on the record. The effect of updating the secondary index of the index data in the update.
  • the data query apparatus queries the target secondary index by querying data, and the index data in at least two second index columns is recorded in the first index column in the target secondary index.
  • the row primary key corresponding to the query data is obtained, and the index data corresponding to the primary key of the row is obtained, and the related technologies need to separately query multiple secondary indexes when performing the query, and the operation of the query process is multiplied and the query efficiency is low.
  • the problem is that the query data in the second index column can be queried by performing a query, and the query process is simple and the query efficiency is high.

Landscapes

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

Abstract

一种数据查询方法和装置,属于数据库领域。所述方法包括:接收客户端的查询请求,查询请求中包含有查询数据(201);根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行(202);从主索引中获取目标行主键对应的目标索引行中的索引数据(203);向客户端提供目标索引行中的索引数据(204)。该方法和装置解决了相关技术中在进行查询时,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。

Description

数据查询方法和装置 技术领域
本发明涉及数据库领域,特别涉及一种数据查询方法和装置。
背景技术
数据库表是数据库中用于存储数据的对象,数据库表中通常以行和列的形式存储着多个值,一行数据为一个记录(例如在通讯录数据库中某个人全部的信息),一列数据(一个字段)记录有该数据库表中同一数据类型的所有值(如通讯录数据库中所有人的家庭住址)。在数据库表中查询数据时,为了更快的获取想要获取的整行数据,通常需要建立索引。索引是对数据库表中一列或多列的值进行排序的一种结构。索引通常包括主索引(一级索引)和二级索引,主索引记录有数据库表中的所有行的数据,其中,每行数据称为一个索引行,每列数据称为一个索引列,每行数据中的任一索引数据都对应于该行的行主键(Rowkey),二级索引通常是根据主索引中的索引列与这索引列中每个索引数据对应的行主键建立的。
相关技术中有一种数据查询方法,在该方法中,客户端在不知道查询数据(该查询数据是客户端想要获取的整行数据中的一个索引数据)的所属索引列时,需要查询根据该查询数据多个可能所属的索引列建立的多个二级索引,而每查询一个二级索引,客户端就要向服务端(数据库位于服务端)发送一次查询请求(包含有查询数据),服务端在接收到这一查询请求后,会查询对应的二级索引,在查询完多个二级索引后,服务端向客户端返回多次查询的结果(若查询到多个二级索引中存在该查询数据,则获取该查询数据对应的行主键,根据该行主键查询主索引得到行主键对应的整行数据,最后向客户端返回该整行数据,若在多个二级索引中未查询到该查询数据,则向客户端返回没有满足条件的数据的指示)。例如:查询数据为电话号码,作为查询数据的电话号码可能属于主索引中手机号码、家庭号码和办公号码这三列数据中的任一列,客户端在查询时需要根据电话号码向服务端发送查询根据手机号码、家庭号码和办公号码这三列数据建立的三个二级索引的三个请求,服务端会根据查询这三个索引的三个请求分别查询这三个索引,之后服务端向客户端返回查询这三个索引的查询结果。
发明人在实现本发明的过程中,发现上述方式至少存在如下缺陷:上述方式在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低。
发明内容
为了解决相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题,本申请提供了一种数据查询方法和装置。所述技术方案如下:
第一方面,提供一种数据查询方法,所述方法包括:
数据库端接收客户端发送的包含有查询数据的查询请求,查询数据为主索引中记录的一个索引数据;
数据库端根据接收到的查询请求查询主索引中的目标二级索引,得到查询数据对应的目标行主键,其中目标二级索引包含有第一索引列,该第一索引列中记录了主索引中至少两个第二索引列中的索引数据,且每个第二索引列中的每个索引数据各自与主索引中的一个行主键对应,第一索引列是指二级索引中的索引列,第二索引列是指主索引中的索引列;
数据库端在获取了目标行主键后,根据目标行主键查询主索引,并获取目标行主键对应的目标索引行中的索引数据,该目标索引行中的索引数据为客户端想要获取的数据;
数据库端向客户端提供目标索引行中的索引数据完成数据的查询。
本申请提供的数据查询方法,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
在一个可能的设计中,该方法还包括:
在建立二级索引时,数据库端从主索引中获取至少两个第二索引列中的索引数据;
数据库端将获取的至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据;
根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引,虚拟列为目标二级索引中的第一索引列。数据库端在建立目标二级索引时,可以给目标二级索引设置一个标识,该标识可以区分与识别目标二级索引。
目标二级索引中可以记录有每个索引数据对应的行主键,也可以不记录每个索引数据对应的行主键,而是建立每个索引数据与主索引中该索引数据对应的行主键之间的映射,使每个索引数据各自指向主索引中的一个索引行的行主键。
此外,建立二级索引的过程可以包含二级索引的定义过程与数据填充过程,其中二级索引的定义过程为建立二级索引的架构的过程,该架构可以认为是一个表格,且该表格确定了需要将主索引中的哪几列索引数据填入其中以及二级索引的标识;而数据填充过程为将虚拟列中的索引数据填入二级索引的架构的过程。
本实现方法为建立目标二级索引的过程,数据库端可以以该方法建立任一二级索引。
本申请提供的数据查询方法,通过虚拟列来作为二级索引的第一索引列,达到了目标二级索引中的第一索引列能够包含主索引中多个第二索引列的效果。
在一个可能的设计中,主索引中每个第二索引列各自对应一种数据类型,根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索,包括:
数据库端根据主索引中与虚拟列存在映射关系的至少两个第二索引列中每个索引列对应的数据类型确定虚拟列中每个索引数据的数据类型;
数据库端在建立目标二级索引时,将虚拟列中每个索引数据的数据类型作为目标二级索引的附加列,该附加列可以指示二级索引的第一索引列中每个索引数据的数据类型。
本申请提供的数据查询方法,通过在二级索引中添加附加列,达到了能够在二级索引中查询到数据类型的效果。
在一个可能的设计中,根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引之后,该方法还包括:
在对目标二级索引进行更新时,数据库端接收客户端发送的包含有新增索引行的写入请求;
数据库端将新增索引行写入主索引,并为新增索引行分配对应的行主键;
数据库端确定目标二级索引中虚拟列对应的至少两个第二索引列,其中虚拟列对应的第二索引列为与虚拟列存在映射关系的第二索引列;
数据库端从新增索引行中获取属于与虚拟列对应的至少两个第二索引列中的索引数据;
数据库端将新增索引行中属于至少两个第二索引列中的索引数据写入目标二级索引,完成对目标二级索引的更新。
本实现方式为对目标二级索引的更新过程,数据库端接收到写入请求后,可以根据该方式更新任一二级索引。
在一个可能的设计中,查询请求中还包含有目标数据类型和目标二级索引的标识,根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,包括:
数据库端根据目标二级索引的标识确定目标二级索引,该标识可以为目标二级索引的名称等可以识别目标二级索引的数据;
数据库端在目标二级索引中寻找记录有目标数据类型和查询数据的目标索引行;
数据库端获取目标索引行的行主键后,将目标二级索引行的行主键确定为目标行主键。
本申请提供的数据查询方法,通过目标数据类型和查询数据来查询含有附加列的目标二级索引,达到了缩小搜索范围的效果。
第二方面,提供一种数据查询装置,该装置包括:
请求接收单元,用于接收客户端的查询请求,查询请求中包含有查询数据;
索引查询单元,用于根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行;
数据获取单元,用于从主索引中获取目标行主键对应的目标索引行中的索引数据;
数据提供单元,用于向客户端提供目标索引行中的索引数据。
在一个可能的设计中,该装置还包括:
索引数据获取单元,用于从主索引中获取至少两个第二索引列中的索引 数据;
虚拟映射单元,用于将至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据;
索引建立单元,用于根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引,虚拟列为目标二级索引中的第一索引列。
在一个可能的设计中,主索引中每个第二索引列各自对应一种数据类型,索引建立单元,用于:
根据主索引中的至少两个第二索引列中每个第二索引列各自对应的数据类型确定虚拟列中每个索引数据的数据类型;
根据虚拟列和虚拟列中每个索引数据对应的行键值以及虚拟列中每个索引数据的数据类型建立目标二级索引,虚拟列中每个索引数据的数据类型组成目标二级索引的附加列。
在一个可能的设计中,该装置还包括:
写入接收单元,用于接收客户端的写入请求,写入请求中包含有新增索引行;
索引写入单元,用于将新增索引行写入主索引,并为新增索引行分配对应的行主键;
索引列确定单元,用于确定目标二级索引中虚拟列对应的至少两个第二索引列;
新增数据获取单元,用于从新增索引行中获取属于至少两个第二索引列中的索引数据;
数据写入单元,用于将新增索引行中属于至少两个第二索引列中的索引数据写入目标二级索引。
在一个可能的设计中,查询请求中还包含有目标数据类型和目标二级索引的标识,索引查询单元,用于:
根据目标二级索引的标识确定目标二级索引;
根据目标数据类型和查询数据在目标二级索引中确定目标二级索引行,目标二级索引行中的索引数据与查询数据相同,目标二级索引行中的数据类型与目标数据类型相同;
将目标二级索引行的行主键确定为目标行主键。
本申请提供的技术方案可以包括以下有益效果:
通过查询数据查询目标二级索引,该目标二级索引中的一个索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本发明。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本发明的实施例,并与说明书一起用于解释本发明的原理。
图1是本发明各个实施例提供的数据查询方法所涉及的实施环境的结构示意图;
图2是本发明实施例示出的一种数据查询方法的流程图;
图3-1是本发明实施例示出的另一种数据查询方法的流程图;
图3-2是图3-1所示实施例中建立二级索引的流程图;
图3-3是图3-1所示实施例中一种二级索引的示意图;
图3-4是图3-1所示实施例中另一种二级索引的示意图;
图3-5是图3-1所示实施例中另一种二级索引的示意图;
图3-6是图3-1所示实施例中一种获取目标行键值的流程图;
图4-1是本发明实施例示出的另一种数据查询方法的流程图;
图4-2是图4-1所示实施例中将新增索引行写入主索引的示意图;
图4-3是图4-1所示实施例中从索引列获取索引数据的示意图;
图5-1是本发明实施例示出的一种数据查询装置的框图;
图5-2是本发明实施例示出的另一种数据查询装置的框图;
图5-3是本发明实施例示出的另一种数据查询装置的框图;
图6是本发明实施例提供的一种数据查询装置的结构图。
通过上述附图,已示出本发明明确的实施例,后文中将有更详细的描述。这些附图和文字描述并不是为了通过任何方式限制本发明构思的范围,而是通过参考特定实施例为本领域技术人员说明本发明的概念。
具体实施方式
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本发明相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本发明的一些方面相一致的装置和方法的例子。
图1是本发明各个实施例提供的数据查询方法所涉及的实施环境的结构示意图,该实施环境可以包括:客户端11和数据库端12。
客户端11为用来供用户对数据库中的数据进行查询的终端,客户端11可以是手机和计算机等终端。本实施环境不对客户端11的数量作出限制。
数据库端12中存储有数据库的数据,可以供客户端11进行查询,数据库端12可以为一台服务器,或者由若干台服务器组成的服务器集群,或者是一个云计算服务中心。
客户端11和数据库端12可以建立有有线连接或无线连接,此外客户端11和数据库端12还可以位于一台设备中,本实施环境不作出限制。
图2是本发明实施例示出的一种数据查询方法的流程图,本实施例以该数据查询方法应用于图1所示实施环境中的数据库端12来举例说明。该数据查询方法可以包括如下几个步骤:
步骤201,接收客户端的查询请求,查询请求中包含有查询数据。
步骤202,根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行。
步骤203,从主索引中获取目标行主键对应的目标索引行中的索引数据。
步骤204,向客户端提供目标索引行中的索引数据。
综上所述,本发明实施例提供的数据查询方法,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的 操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
图3-1是本发明实施例示出的另一种数据查询方法的流程图,本实施例以该数据查询方法应用于图1所示实施环境中的数据库端12来举例说明。该数据查询方法可以包括如下几个步骤:
步骤301,根据主索引中的第二索引列建立至少一个二级索引,至少一个二级索引包括目标二级索引。
在使用本发明实施例提供的数据查询方法时,可以首先根据主索引中的第二索引列建立至少一个二级索引,该至少一个二级索引可以包括目标二级索引,目标二级索引为一次数据查询(如本发明实施例进行的数据查询)中需要用到的二级索引。本发明各个实施例所涉及的第二索引列是指主索引中的索引列。
为便于解释建立本发明实施例提供的二级索引的原理,以建立目标二级索引(本发明实施例进行的查询要用到的二级索引)为例来描述,如图3-2所示,本步骤可以包括下面3个子步骤:
子步骤3011,从主索引中获取至少两个第二索引列中的索引数据。
在建立至少一个二级索引时,可以首先从数据库的主索引中获取至少两个第二索引列中的索引数据。这至少两个第二索引列的索引数据可以是后续用来建立目标二级索引的数据。
示例性的,在选择这至少两个第二索引列时,可以根据主索引中每个第二索引列的选择度的大小来进行选择,其中选择度为一个第二索引列中不同索引数据的数目与该第二索引列中索引数据总数的比值(如索引列A中有2000个索引数据,其中有1000个不同的值,则该索引列A的选择度为1000/2000=0.5),该比值越大,选择度就越大,以该第二索引列建立的二级索引的查询效率就越高。在本步骤中可以获取主索引中选择度较大的几个(至少两个)第二索引列中的索引数据。
需要说明的是,本步骤还可以通过其它方式来选择第二索引列以提高后续建立的目标二级索引的查询效率,本发明实施例不作出限制。
子步骤3012,将至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据。
在获取了至少两个第二索引列中的索引数据之后,可以将至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据。由于数据库中的二级索引通常是根据主索引中的一个第二索引列中的索引数据所建立的,但本发明实施例建立的二级索引需要根据主索引中的至少两个第二索引列的索引数据来建立,主索引中并没有哪个第二索引列包含有这至少两个第二索引列的索引数据,因此可以首先建立一个虚拟列,并使该虚拟列对应于该至少两个第二索引列中的索引数据,之后可以以该虚拟列作为二级索引的第一索引列。
子步骤3013,根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引,虚拟列为目标二级索引中的第一索引列。
在获得虚拟列之后,可以根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引。其中,行主键可以通过主索引来获取。在根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引时,可以首先建立目标二级索引的架构,(该建立过程可以称为定义目标二级索引的过程),该架构可以理解为一个未填充数据的表格(该表格确定了需要将主索引中的哪几列索引数据填入其中以及目标二级索引的名称),之后可以将虚拟列中的索引数据填入其中,即目标二级索引可以包含有目标二级索引的架构以及填入该架构中的索引数据。此外,还可以先确定目标二级索引的架构,再获取主索引中的索引数据,最后将索引数据填入目标二级索引的架构中,本发明实施例不作出限制。本发明各个实施例所涉及的第一索引列是指二级索引中的索引列。
需要说明的是,在建立二级索引时,可以设置二级索引的名称,并将该名称作为二级索引的标识,以方便用户端选择二级索引以及数据库端区分二级索引。例如,在设置目标二级索引的名称时,可以参考该二级索引中的虚拟列(包含有主索引中多个第二索引列的索引数据)中索引数据的多个数据类型,示例性的,一个二级索引中的虚拟列包含有数据类型为“手机号码”、“座机号码”和“办公号码”这三个数据类型的索引数据,则可以将该二级索引命名为“电话号码”,此种为对主索引中的数据类型进行上位的命名方式,而本发明实施例建立的二级索引还可以有其它命名方式,本发明实施例不作出限制。
本步骤在建立目标二级索引时,可以包括下面两种方式:
第一种方式:
将虚拟列作为该目标二级索引中的第一索引列,并建立该第一索引列中的每个索引数据与主索引中该索引数据对应的行主键之间的映射。也就是说,使目标二级索引的第一索引列中每个索引数据各自指向主索引中的一个索引行的行主键。如图3-3所示,其中,“索引列β”为第一索引列L1的名称,该名称可以由数据库端进行设置,二级索引S2中实际仅记录了第一索引列L1,而第一索引列L1中的每个索引数据均与主索引S1中的索引行的行主键存在映射关系。需要说明的是,第一索引列L1中的多个索引数据可能在主索引S1中映射为一个行主键。
第二种方式:
将虚拟列作为该目标二级索引中的第一索引列,并建立一个行主键列,使目标二级索引的第一索引列中的每个索引数据与对应的行主键位于同一行,即将行主键直接记录在目标二级索引中,如图3-4所示,其中二级索引S2中包括第一索引列L1和行主键列K1,第一索引列L1中的每个索引数据各自与行主键列K1中同一行的行主键对应。
需要说明的是,在通过上述两种方式建立目标二级索引时,还可以在目标二级索引中添加一个附加列,该过程可以包括:
1)根据主索引中的至少两个第二索引列中每个第二索引列各自对应的数据类型确定虚拟列中每个索引数据的数据类型。
由于虚拟列与主索引中的至少两个第二索引列存在映射关系,因而可以根据这至少两个第二索引列中的索引数据对应的数据类型确定虚拟列中每个索引数据的数据类型。其中,主索引中的每个第二索引列各自对应于一种数据类型,该第二索引列中的每个索引数据都为同种数据类型。示例性的,一个第二索引列与数据类型“出生日期”所对应,则该第二索引列中记录的任一索引数据的数据类型为“出生日期”。
2)根据虚拟列和虚拟列中每个索引数据对应的行键值以及虚拟列中每个索引数据的数据类型建立目标二级索引。
在获取了虚拟列中索引数据的数据类型之后,可以根据虚拟列和虚拟列中每个索引数据对应的行键值以及虚拟列中每个索引数据的数据类型建立目标二级索引,即虚拟列中每个索引数据的数据类型组成了目标二级索引的附加列,如图3-5所示,其为上述第二种方式建立的目标二级索引,该目标二级索引S2中包含有第一索引列L1、行主键列K1和附加列F。而通过上述第 一种方式建立的目标二级索引中包括第一索引列和附加列,在此不再赘述。
需要说明的是,在主索引中某一行的多个索引数据存在重复的情况,且该情况可能影响查询结果时(可能无法得知索引数据的数据类型),还可以将虚拟列中每个索引数据的数据类型直接记录于虚拟列中,以方便数据库端在虚拟列中的索引数据出现重复时进行区分,其中索引数据的数据类型可以表明该索引数据在主索引中所属的第二索引列。
数据库端可以通过步骤3011和步骤3013建立包含目标二级索引在内的多个二级索引。
步骤302,接收客户端的查询请求,查询请求中包含有查询数据。
在建立了包含目标二级索引的至少一个二级索引之后,可以接收客户端的查询请求,该查询请求中包含有查询数据,该查询数据为主索引中的一个索引数据。查询请求中还可以包含有目标二级索引的标识,该标识用于在多个二级索引中确定目标二级索引。
步骤303,根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键。
在获取了客户端的查询请求之后,数据库端可以根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键。其中,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行。
由于目标二级索引是根据多个第二索引列中的索引数据建立的,因而一次查询操作就可以查询多个主索引中的第二索引列,而现有技术中的二级索引是根据主索引中的一个第二索引列建立的,一次查询操作只能查询主索引中的一个第二索引列,若要达到和本发明实施例建立的二级索引同样的搜索效果,就需要进行多次查询,查询效率较低。
示例性的,相关技术中,数据库端在进行查询时的语句可以为“SELECT*FROM UserInfo WHERE HomePhone='185333'OR Telphone='185333'OR OfficePhone='185333';”,其中,“UserInfo”为主索引的名称,“HomePhone”、“Telphone”和“OfficePhone”为主索引的三个二级索引的名称,这三个二级索引均是根据其记录的第二索引列的名称(第二索引列的名称可以为主索引中该第二索引列的数据类型)命名的,例如名称为“OfficePhone”的二级索引是 根据名称为“OfficePhone”的第二索引列建立的,“185333”为查询数据。该语句表示数据库端在名为“UserInfo”的主索引中,以查询数据“185333”分别查询名为“HomePhone”、“Telphone”和“OfficePhone”的三个第二索引列,需要查询三个二级索引。这种查询方式在主索引中的数据量较大时,会严重耗费数据库端的性能,影响查询速度。
而本发明实施例中,数据库端在进行查询时的语句可以为“SELECT*FROM UserInfo WHERE PhoneNum='185333';”其中“PhoneNum”为步骤301建立的二级索引中的一个二级索引的名称(即该二级索引的标识),该二级索引可以是根据名称为“HomePhone”、“Telphone”和“OfficePhone”的三个第二索引列建立而成的,该语句表示数据库端在名为“UserInfo”的主索引中,以查询数据“185333”查询名称为“PhoneNum”的二级索引,只需要进行一次查询就能达到相关技术中三次查询的效果,查询过程简单快捷。
而在查询请求中包含有目标数据类型和目标二级索引的标识时,如图3-6所示,本步骤可以包括下面3个子步骤:
在子步骤3031中,根据目标二级索引的标识确定目标二级索引。
数据库端首先可以根据目标二级索引的标识在主索引的多个二级索引中确定目标二级索引。
在子步骤3032中,根据目标数据类型和查询数据在目标二级索引中确定目标二级索引行,目标二级索引行中的索引数据与查询数据相同,且目标二级索引行中的数据类型与目标数据类型相同。
数据库端在确定了目标二级索引之后,可以根据目标数据类型和查询数据在目标二级索引中确定目标二级索引行,目标二级索引行中的索引数据与查询数据相同,目标二级索引行中的数据类型与目标数据类型相同,即数据库找到记录的数据与目标数据类型和查询数据相同的一行,并将该行确定为目标二级索引行。
需要说明的是,在二级索引中包含有附加列时,可以将二级索引看做一个复合索引,根据目标数据类型与查询数据来查询二级索引时,能够达到减小查询范围的效果,这是由于数据库中通常是按照索引数据来进行排序的,因而相同的索引数据会相邻进行排列,这样数据库端在二级索引中查询时,只需要在二级索引中查询所有记录有目标数据类型的行,或者在二级索引中查询所有记录有查询数据的行,就能够完成对二级索引的查询。此外,由于 数据类型的重复率较高,因而二级索引中可以按数据类型进行排列。
示例性的,如表1所示,其为一个二级索引的示意表。
行主键 附加列 第一索引列
2 175
4 169
3 160
1 165
在表1中最左边一列为行主键列,中间一列为以数据类型添加的附加列,最右边一列为记录有索引数据的第一索引列,其中的排列顺序是以附加列进行排序的,若查询请求中的查询数据为“169”,目标数据类型为“男”,则数据库端在查询时,只需要从第一行开始,查询完所有附加列为“男”的索引行,就能够完成对该二级索引的查询。
在子步骤3033中,将目标二级索引行的行主键确定为目标行主键。
数据库端在确定了目标二级索引行之后,可以通过目标二级索引获取该目标二级索引行的行主键,并将该行主键确定为目标行主键。
步骤304,从主索引中获取目标行主键对应的目标索引行中的索引数据。
数据库端在获取了查询数据对应的目标行主键之后,可以从主索引中获取该目标行主键对应的目标索引行中的索引数据,该索引数据即为客户端想要获取的数据。示例性的,主索引为图3-3中的主索引S1,目标行主键为“3”,则可以从主索引S1中获取索引数据“3a、3b、3c、3d”。
步骤305,向客户端提供目标索引行中的索引数据。
数据库端在获取了目标索引行中的索引数据之后,可以向客户端提供目标索引行中的索引数据,以完成客户端的查询请求。
需要补充说明的是,本发明实施例提供的数据查询方法,通过将至少两个第二索引列中的索引数据映射为一个虚拟列,达到了可以根据该虚拟列以及该虚拟列中的索引数据对应的行主键建立二级索引的效果。
综上所述,本发明实施例提供的数据查询方法,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个 第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
图4-1是本发明实施例示出的另一种数据查询方法的流程图,本实施例以该数据查询方法应用于图1所示实施环境中的数据库端12来举例说明。该数据查询方法可以包括如下几个步骤:
步骤401,根据主索引中的第二索引列建立至少一个二级索引,至少一个二级索引包括目标二级索引。
在使用本发明实施例提供的数据查询方法时,可以首先根据主索引中的第二索引列建立至少一个二级索引,该至少一个二级索引可以包括目标二级索引,目标二级索引为一次查询(本发明实施例进行的查询)中需要用到的二级索引。
本步骤可以参考图3-1所示实施例中的步骤301,在此不再赘述。
步骤402,接收客户端的写入请求,写入请求中包含有新增索引行。
在建立了包含有目标二级索引的至少一个二级索引之后,若用户想要在主索引中写入新的索引行(记录),则可以通过客户端向数据库端发送写入请求,该写入请求中包含有新增索引行。
步骤403,将新增索引行写入主索引,并为新增索引行分配对应的行主键。
数据库端在获取了新增索引行之后,可以将新增索引行写入主索引,并为新增索引行分配对应的行主键。新增索引行在写入主索引之后,数据库端可以为该新增索引行分配一个对应的行主键。示例性的,如图4-2所示,其为将新增索引行z写入主索引S1得到更新后的主索引S1的示意图,主索引S1中包含有名称为“手机号码”、“座机号码”、“姓名”和“办公号码”4个第二索引列以及一个行主键列,新增索引行z中记录有“手机号码”、“座机号码”、“姓名”和“办公号码”这4种类型的数据,在该图中新增索引行z添加为了主索引S1中的最后一个索引行。
步骤404,确定目标二级索引中虚拟列对应的至少两个第二索引列。
数据库端在将新增索引行写入主索引,并为新增索引行分配对应的行主键后,可以开始更新目标二级索引,在更新目标二级索引时,可以首先确定目标二级索引中虚拟列对应的至少两个第二索引列。其中,虚拟列对应的第二索引列为与虚拟列存在映射关系的第二索引列。
步骤405,从新增索引行中获取属于该至少两个第二索引列中的索引数据。
在确定目标二级索引中虚拟列对应的至少两个第二索引列后,可以从新增索引行中获取属于这些第二索引列中的索引数据。示例性的,如图4-3所示,其为写入了新增索引行z的主索引S1,若目标二级索引中虚拟列对应的第二索引列为“手机号码”和“座机号码”,则可以获取属于“手机号码”和“座机号码”中的索引数据“139xxxx2”和“023xxxx3”。
步骤406,将新增索引行中属于该至少两个第二索引列中的索引数据写入目标二级索引。
在获取了新增索引行中属于虚拟列对应的至少两个第二索引列的索引数据后,可以将这些索引数据写入目标二级索引,与此同时,可以将新增索引行的行主键写入目标二级索引,或者在目标二级索引中建立这些索引数据与新增索引行的行主键间的映射关系。示例性的,以图4-3所示的主索引S1为例,若二级索引S2是根据第二索引列“手机号码”和“座机号码”建立的,而在步骤406中获取的新增索引行z中这两个第二索引列的索引数据为“139xxxx2”和“023xxxx3”,则可以将“139xxxx2”和“023xxxx3”写入二级索引S2,并将新增索引行z的行主键“101”写入二级索引S2,或者在二级索引S2中建立“139xxxx2”和“023xxxx3”与新增索引行z的行主键“101”间的映射关系。
步骤402至步骤406为更新目标二级索引的步骤,数据库端可以根据这几个步骤更新任一二级索引。
步骤407,接收客户端的查询请求,查询请求中包含有查询数据。
数据库端可以接收客户端的查询请求,查询请求中包含有查询数据,该查询数据为主索引中的一个索引数据。查询请求中还可以包含有目标二级索引的标识,该标识用于在多个二级索引中确定目标二级索引。
步骤408,根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键。
在获取了客户端的查询请求之后,数据库端可以根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键。其中,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主 键对应于主索引中的一个索引行。
本步骤可以参考图3-1所示实施例中的步骤304,在此不再赘述。
步骤409,从主索引中获取目标行主键对应的目标索引行中的索引数据。
在获取了查询数据对应的目标行主键之后,可以从主索引中获取该目标行主键对应的目标索引行中的索引数据,该索引数据即为客户端想要获取的数据。
步骤410,向客户端提供目标索引行中的索引数据。
数据库端在获取了目标索引行中的索引数据之后,可以向客户端提供目标索引行中的索引数据,以完成客户端的查询请求。
需要补充说明的是,本发明实施例提供的数据查询方法,通过获取客户端发送的写入请求,并根据该写入请求来更新二级索引,达到了可以对记录有多个第二索引列中的索引数据的二级索引进行更新的效果。
综上所述,本发明实施例提供的数据查询方法,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
下述为本发明装置实施例,可以用于执行本发明方法实施例。对于本发明装置实施例中未披露的细节,请参照本发明方法实施例。
图5-1是本发明实施例示出的一种数据查询装置的框图,该数据查询装置可以通过软件、硬件或者两者的结合实现成为数据库端12的部分或者全部。该数据查询装置500可以包括:
请求接收单元501,用于接收客户端的查询请求,查询请求中包含有查询数据。
索引查询单元502,用于根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行。
数据获取单元503,用于从主索引中获取目标行主键对应的目标索引行中的索引数据。
数据提供单元504,用于向客户端提供目标索引行中的索引数据。
综上所述,本发明实施例提供的数据查询装置,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
可选的,如图5-2所示,该数据查询装置500还包括:
索引数据获取单元505,用于从主索引中获取至少两个第二索引列中的索引数据。
虚拟映射单元506,用于将至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据。
索引建立单元507,用于根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引,虚拟列为目标二级索引中的第一索引列。
可选的,主索引中每个第二索引列各自对应一种数据类型,索引建立单元507,用于:
根据主索引中的至少两个第二索引列中每个第二索引列各自对应的数据类型确定虚拟列中每个索引数据的数据类型。
根据虚拟列和虚拟列中每个索引数据对应的行键值以及虚拟列中每个索引数据的数据类型建立目标二级索引,虚拟列中每个索引数据的数据类型组成目标二级索引的附加列。
可选的,如图5-3所示,数据查询装置500还包括:
写入接收单元508,用于接收客户端的写入请求,写入请求中包含有新增索引行。
索引写入单元509,用于将新增索引行写入主索引,并为新增索引行分配对应的行主键。
索引列确定单元510,用于确定目标二级索引中虚拟列对应的至少两个第二索引列。
新增数据获取单元511,用于从新增索引行中获取属于至少两个第二索 引列中的索引数据。
数据写入单元512,用于将新增索引行中属于至少两个第二索引列中的索引数据写入目标二级索引。
可选的,查询请求中还包含有目标数据类型和目标二级索引的标识,索引查询单元502,用于:
根据目标二级索引的标识确定目标二级索引。
根据目标数据类型和查询数据在目标二级索引中确定目标二级索引行,目标二级索引行中的索引数据与查询数据相同,目标二级索引行中的数据类型与目标数据类型相同。
将目标二级索引行的行主键确定为目标行主键。
需要补充说明的是,本发明实施例提供的数据查询装置,通过将至少两个第二索引列中的索引数据映射为一个虚拟列,达到了可以根据该虚拟列以及该虚拟列中的索引数据对应的行主键建立二级索引的效果。
需要补充说明的是,本发明实施例提供的数据查询装置,通过获取客户端发送的写入请求,并根据该写入请求来更新二级索引,达到了可以对记录有多个第二索引列中的索引数据的二级索引进行更新的效果。
综上所述,本发明实施例提供的数据查询装置,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
图6是本发明一个实施例提供的数据查询装置的结构图,包括至少一个处理器610(例如CPU),至少一个网络接口620或者其他通信接口,存储器630,和至少一个通信总线640,用于实现这些装置之间的连接通信。处理器610用于执行存储器630中存储的程序631。存储器630可能包含高速随机存取存储器(RAM:Random Access Memory),也可能还包括非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。通过至少一个网络接口620(可以是有线或者无线)实现该数据查询装置与至少一个其他网元之间的通信连接,可以使用互联网,广域网,本地网,城域网等。
网络接口620,用于接收客户端的查询请求,查询请求中包含有查询数据。
处理器610,用于根据查询请求查询主索引的目标二级索引,得到查询数据对应的目标行主键,目标二级索引包括第一索引列,第一索引列中记录有主索引中的至少两个第二索引列中的索引数据,至少两个第二索引列中每个索引数据各自对应一个行主键,行主键对应于主索引中的一个索引行。
处理器610,用于从主索引中获取目标行主键对应的目标索引行中的索引数据。
网络接口620,用于向客户端提供目标索引行中的索引数据。
可选的,处理器610,用于从主索引中获取至少两个第二索引列中的索引数据。
处理器610,用于将至少两个第二索引列中的索引数据映射为一个虚拟列,虚拟列中记录有至少两个第二索引列中的索引数据。
处理器610,用于根据虚拟列和虚拟列中每个索引数据对应的行主键建立目标二级索引,虚拟列为目标二级索引中的第一索引列。
可选的,主索引中每个第二索引列各自对应一种数据类型。
处理器610,用于根据主索引中的至少两个第二索引列中每个第二索引列各自对应的数据类型确定虚拟列中每个索引数据的数据类型。
处理器610,用于根据虚拟列和虚拟列中每个索引数据对应的行键值以及虚拟列中每个索引数据的数据类型建立目标二级索引,虚拟列中每个索引数据的数据类型组成目标二级索引的附加列。
可选的,网络接口620,用于接收客户端的写入请求,写入请求中包含有新增索引行。
处理器610,用于将新增索引行写入主索引,并为新增索引行分配对应的行主键。
处理器610,用于确定目标二级索引中虚拟列对应的至少两个第二索引列。
处理器610,用于从新增索引行中获取属于至少两个第二索引列中的索引数据。
处理器610,用于将新增索引行中属于至少两个第二索引列中的索引数据写入目标二级索引。
可选的,查询请求中还包含有目标数据类型和目标二级索引的标识。
处理器610,用于根据目标二级索引的标识确定目标二级索引。
处理器610,用于根据目标数据类型和查询数据在目标二级索引中确定目标二级索引行,目标二级索引行中的索引数据与查询数据相同,目标二级索引行中的数据类型与目标数据类型相同。
处理器610,用于将目标二级索引行的行主键确定为目标行主键。
需要补充说明的是,本发明实施例提供的数据查询装置,通过将至少两个索引列中的索引数据映射为一个虚拟列,达到了可以根据该虚拟列以及该虚拟列中的索引数据对应的行主键建立二级索引的效果。
需要补充说明的是,本发明实施例提供的数据查询装置,通过获取客户端发送的写入请求,并根据该写入请求来更新二级索引,达到了可以对记录有多个第二索引列中的索引数据的二级索引进行更新的效果。
综上所述,本发明实施例提供的数据查询装置,通过查询数据查询目标二级索引,该目标二级索引中的第一索引列中记录有至少两个第二索引列中的索引数据,得到查询数据对应的行主键,再获取该行主键对应的索引数据,解决了相关技术中在进行查询时,需要分别查询多个二级索引,查询过程的操作成倍增长,查询效率较低的问题;达到了进行一次查询就能够查询多个第二索引列中的索引数据的效果,查询过程操作简单,查询效率较高。
关于上述实施例中的装置,其中各个单元执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。
以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (10)

  1. 一种数据查询方法,其特征在于,所述方法包括:
    接收客户端的查询请求,所述查询请求中包含有查询数据;
    根据所述查询请求查询主索引的目标二级索引,得到所述查询数据对应的目标行主键,所述目标二级索引包括第一索引列,所述第一索引列中记录有所述主索引中的至少两个第二索引列中的索引数据,所述至少两个第二索引列中每个索引数据各自对应一个行主键,所述行主键对应于所述主索引中的一个索引行;
    从所述主索引中获取所述目标行主键对应的目标索引行中的索引数据;
    向所述客户端提供所述目标索引行中的索引数据。
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述查询请求查询主索引的目标二级索引之前,所述方法还包括:
    从所述主索引中获取至少两个第二索引列中的索引数据;
    将所述至少两个第二索引列中的索引数据映射为一个虚拟列,所述虚拟列中记录有所述至少两个第二索引列中的索引数据;
    根据所述虚拟列和所述虚拟列中每个索引数据对应的行主键建立所述目标二级索引,所述虚拟列为所述目标二级索引中的第一索引列。
  3. 根据权利要求2所述的方法,其特征在于,所述主索引中每个第二索引列各自对应一种数据类型,所述根据所述虚拟列和所述虚拟列中每个索引数据对应的行主键建立所述目标二级索引,包括:
    根据所述主索引中的所述至少两个第二索引列中每个第二索引列各自对应的数据类型确定所述虚拟列中每个索引数据的数据类型;
    根据所述虚拟列和所述虚拟列中每个索引数据对应的行键值以及所述虚拟列中每个索引数据的数据类型建立所述目标二级索引,所述虚拟列中每个索引数据的数据类型组成所述目标二级索引的附加列。
  4. 根据权利要求2所述的方法,其特征在于,所述根据所述虚拟列和所述虚拟列中每个索引数据对应的行主键建立所述目标二级索引之后,所述方法还包括:
    接收所述客户端的写入请求,所述写入请求中包含有新增索引行;
    将所述新增索引行写入所述主索引,并为所述新增索引行分配对应的行主键;
    确定所述目标二级索引中虚拟列对应的所述至少两个第二索引列;
    从所述新增索引行中获取属于所述至少两个第二索引列中的索引数据;
    将所述新增索引行中属于所述至少两个第二索引列中的索引数据写入所述目标二级索引。
  5. 根据权利要求3所述的方法,其特征在于,所述查询请求中还包含有目标数据类型和所述目标二级索引的标识,
    所述根据所述查询请求查询主索引的目标二级索引,得到所述查询数据对应的目标行主键,包括:
    根据所述目标二级索引的标识确定所述目标二级索引;
    根据所述目标数据类型和所述查询数据在所述目标二级索引中确定目标二级索引行,所述目标二级索引行中的索引数据与查询数据相同,且所述目标二级索引行中的数据类型与所述目标数据类型相同;
    将所述目标二级索引行的行主键确定为所述目标行主键。
  6. 一种数据查询装置,其特征在于,所述装置包括:
    请求接收单元,用于接收客户端的查询请求,所述查询请求中包含有查询数据;
    索引查询单元,用于根据所述查询请求查询主索引的目标二级索引,得到所述查询数据对应的目标行主键,所述目标二级索引包括第一索引列,所述第一索引列中记录有所述主索引中的至少两个第二索引列中的索引数据,所述至少两个第二索引列中每个索引数据各自对应一个行主键,所述行主键对应于所述主索引中的一个索引行;
    数据获取单元,用于从所述主索引中获取所述目标行主键对应的目标索引行中的索引数据;
    数据提供单元,用于向所述客户端提供所述目标索引行中的索引数据。
  7. 根据权利要求6所述的装置,其特征在于,所述装置还包括:
    索引数据获取单元,用于从所述主索引中获取至少两个第二索引列中的索引数据;
    虚拟映射单元,用于将所述至少两个第二索引列中的索引数据映射为一个虚拟列,所述虚拟列中记录有所述至少两个第二索引列中的索引数据;
    索引建立单元,用于根据所述虚拟列和所述虚拟列中每个索引数据对应的行主键建立所述目标二级索引,所述虚拟列为所述目标二级索引中的第一索引列。
  8. 根据权利要求7所述的装置,其特征在于,所述主索引中每个第二索引列各自对应一种数据类型,所述索引建立单元,用于:
    根据所述主索引中的所述至少两个第二索引列中每个第二索引列各自对应的数据类型确定所述虚拟列中每个索引数据的数据类型;
    根据所述虚拟列和所述虚拟列中每个索引数据对应的行键值以及所述虚拟列中每个索引数据的数据类型建立所述目标二级索引,所述虚拟列中每个索引数据的数据类型组成所述目标二级索引的附加列。
  9. 根据权利要求7所述的装置,其特征在于,所述装置还包括:
    写入接收单元,用于接收所述客户端的写入请求,所述写入请求中包含有新增索引行;
    索引写入单元,用于将所述新增索引行写入所述主索引,并为所述新增索引行分配对应的行主键;
    索引列确定单元,用于确定所述目标二级索引中虚拟列对应的所述至少两个第二索引列;
    新增数据获取单元,用于从所述新增索引行中获取属于所述至少两个第二索引列中的索引数据;
    数据写入单元,用于将所述新增索引行中属于所述至少两个第二索引列中的索引数据写入所述目标二级索引。
  10. 根据权利要求8所述的装置,其特征在于,所述查询请求中还包含有目标数据类型和所述目标二级索引的标识,所述索引查询单元,用于:
    根据所述目标二级索引的标识确定所述目标二级索引;
    根据所述目标数据类型和所述查询数据在所述目标二级索引中确定目标二级索引行,所述目标二级索引行中的索引数据与查询数据相同,且所述目标二级索引行中的数据类型与所述目标数据类型相同;
    将所述目标二级索引行的行主键确定为所述目标行主键。
PCT/CN2016/073808 2015-10-21 2016-02-15 数据查询方法和装置 WO2017067117A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP16856564.6A EP3236365A4 (en) 2015-10-21 2016-02-15 Data query method and device
US15/958,267 US20180239800A1 (en) 2015-10-21 2018-04-20 Data query method and apparatus

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510689335.3 2015-10-21
CN201510689335.3A CN105354255B (zh) 2015-10-21 2015-10-21 数据查询方法和装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US15/958,267 Continuation US20180239800A1 (en) 2015-10-21 2018-04-20 Data query method and apparatus

Publications (1)

Publication Number Publication Date
WO2017067117A1 true WO2017067117A1 (zh) 2017-04-27

Family

ID=55330228

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/073808 WO2017067117A1 (zh) 2015-10-21 2016-02-15 数据查询方法和装置

Country Status (4)

Country Link
US (1) US20180239800A1 (zh)
EP (1) EP3236365A4 (zh)
CN (2) CN105354255B (zh)
WO (1) WO2017067117A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111797134A (zh) * 2020-06-23 2020-10-20 北京小米松果电子有限公司 分布式数据库的数据查询方法、装置和存储介质
CN112486979A (zh) * 2019-09-12 2021-03-12 阿里巴巴集团控股有限公司 数据处理方法、装置和系统、电子设备以及计算机可读存储介质
CN113268488A (zh) * 2020-02-14 2021-08-17 北京京东振世信息技术有限公司 数据持久化的方法和装置
CN117093611A (zh) * 2023-10-16 2023-11-21 北京人大金仓信息技术股份有限公司 数据库组合索引建议处理方法、存储介质和计算机设备

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105354255B (zh) * 2015-10-21 2018-01-02 华为技术有限公司 数据查询方法和装置
CN105740405B (zh) * 2016-01-29 2020-06-26 华为技术有限公司 存储数据的方法和装置
CN106776785B (zh) * 2016-11-24 2021-06-22 腾讯科技(深圳)有限公司 一种数据写入方法及装置和数据处理系统
CN108255882A (zh) * 2016-12-29 2018-07-06 北京国双科技有限公司 数据查询方法及装置
CN110019292B (zh) * 2017-09-06 2021-05-04 华为技术有限公司 一种数据的查询方法及装置
CN109101516B (zh) * 2017-11-30 2019-09-17 新华三大数据技术有限公司 一种数据查询方法和服务器
CN108427736B (zh) * 2018-02-28 2020-01-17 华为技术有限公司 一种用于查询数据的方法
CN109086456B (zh) * 2018-08-31 2020-11-03 中国联合网络通信集团有限公司 数据索引方法及装置
CN109299106B (zh) * 2018-10-31 2020-09-22 中国联合网络通信集团有限公司 数据查询方法和装置
CN109783508B (zh) * 2018-12-29 2021-04-09 亚信科技(南京)有限公司 数据查询方法、装置、计算机设备和存储介质
CN109918472A (zh) * 2019-02-27 2019-06-21 北京百度网讯科技有限公司 存储和查询数据的方法、装置、设备和介质
CN112380243B (zh) * 2020-11-19 2021-11-09 东北大学 基于机器学习的sql查询选择度预估方法
CN117555893A (zh) * 2022-08-05 2024-02-13 华为技术有限公司 一种处理全局二级索引的方法及装置

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6266660B1 (en) * 1998-07-31 2001-07-24 Unisys Corporation Secondary index search
CN101079074A (zh) * 2007-07-26 2007-11-28 杭州华三通信技术有限公司 一种数据存储与检索的方法及系统
CN102024047A (zh) * 2010-12-14 2011-04-20 青岛普加智能信息有限公司 数据检索方法及装置
CN102117305A (zh) * 2010-01-06 2011-07-06 中国移动通信集团公司 查询数据的系统、方法和数据管理系统
CN102243664A (zh) * 2011-08-22 2011-11-16 西北大学 一种复合字段的数据存储及查询方法
EP2605158A1 (en) * 2011-12-12 2013-06-19 Sap Ag Mixed join of row and column database tables in native orientation

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5701459A (en) * 1993-01-13 1997-12-23 Novell, Inc. Method and apparatus for rapid full text index creation
US6505188B1 (en) * 2000-06-15 2003-01-07 Ncr Corporation Virtual join index for relational databases
US20050027692A1 (en) * 2003-07-29 2005-02-03 International Business Machines Corporation. Method, system, and program for accessing data in a database table
US7337167B2 (en) * 2005-04-14 2008-02-26 International Business Machines Corporation Estimating a number of rows returned by a recursive query
US8078652B2 (en) * 2007-12-06 2011-12-13 Oracle International Corporation Virtual columns
CN102867064B (zh) * 2012-09-28 2015-12-02 用友网络科技股份有限公司 关联字段查询装置和关联字段查询方法
CN103123650B (zh) * 2013-03-06 2016-03-02 同方知网(北京)技术有限公司 一种基于整数映射的xml数据库全文索引方法
WO2015027425A1 (zh) * 2013-08-29 2015-03-05 华为技术有限公司 存储数据的方法和装置
US9213764B2 (en) * 2013-11-22 2015-12-15 Sap Se Encrypted in-memory column-store
CN103631910A (zh) * 2013-11-26 2014-03-12 烽火通信科技股份有限公司 一种分布式数据库多列复合查询的系统及方法
CN103902701B (zh) * 2014-03-31 2017-12-29 北京皮尔布莱尼软件有限公司 一种数据存储系统和存储方法
CN105354255B (zh) * 2015-10-21 2018-01-02 华为技术有限公司 数据查询方法和装置

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6266660B1 (en) * 1998-07-31 2001-07-24 Unisys Corporation Secondary index search
CN101079074A (zh) * 2007-07-26 2007-11-28 杭州华三通信技术有限公司 一种数据存储与检索的方法及系统
CN102117305A (zh) * 2010-01-06 2011-07-06 中国移动通信集团公司 查询数据的系统、方法和数据管理系统
CN102024047A (zh) * 2010-12-14 2011-04-20 青岛普加智能信息有限公司 数据检索方法及装置
CN102243664A (zh) * 2011-08-22 2011-11-16 西北大学 一种复合字段的数据存储及查询方法
EP2605158A1 (en) * 2011-12-12 2013-06-19 Sap Ag Mixed join of row and column database tables in native orientation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3236365A4 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112486979A (zh) * 2019-09-12 2021-03-12 阿里巴巴集团控股有限公司 数据处理方法、装置和系统、电子设备以及计算机可读存储介质
CN112486979B (zh) * 2019-09-12 2023-12-22 阿里巴巴集团控股有限公司 数据处理方法、装置和系统、电子设备以及计算机可读存储介质
CN113268488A (zh) * 2020-02-14 2021-08-17 北京京东振世信息技术有限公司 数据持久化的方法和装置
CN113268488B (zh) * 2020-02-14 2023-11-03 北京京东振世信息技术有限公司 数据持久化的方法和装置
CN111797134A (zh) * 2020-06-23 2020-10-20 北京小米松果电子有限公司 分布式数据库的数据查询方法、装置和存储介质
CN117093611A (zh) * 2023-10-16 2023-11-21 北京人大金仓信息技术股份有限公司 数据库组合索引建议处理方法、存储介质和计算机设备
CN117093611B (zh) * 2023-10-16 2024-03-19 北京人大金仓信息技术股份有限公司 数据库组合索引建议处理方法、存储介质和计算机设备

Also Published As

Publication number Publication date
CN105354255A (zh) 2016-02-24
US20180239800A1 (en) 2018-08-23
EP3236365A1 (en) 2017-10-25
EP3236365A4 (en) 2018-01-03
CN105354255B (zh) 2018-01-02
CN108170726A (zh) 2018-06-15

Similar Documents

Publication Publication Date Title
WO2017067117A1 (zh) 数据查询方法和装置
US10467245B2 (en) System and methods for mapping and searching objects in multidimensional space
US10628449B2 (en) Method and apparatus for processing database data in distributed database system
US8819076B2 (en) Distributed multidimensional range search system and method
US8676951B2 (en) Traffic reduction method for distributed key-value store
US20140122510A1 (en) Distributed database managing method and composition node thereof supporting dynamic sharding based on the metadata and data transaction quantity
WO2021169113A1 (zh) 数据管理方法、装置、计算机设备和存储介质
WO2020052379A1 (zh) 分布式存储系统中处理对象的元数据的方法及装置
CN103838770A (zh) 一种数据逻辑分区的方法和系统
CN113220659B (zh) 一种数据迁移的方法、系统、电子装置和存储介质
WO2016191995A1 (zh) 一种分布式数据库中关联表分区的方法和设备
TW201248418A (en) Distributed caching and cache analysis
CN107636655B (zh) 实时提供数据即服务(DaaS)的系统和方法
CN113806300B (zh) 数据存储方法、系统、装置、设备及存储介质
CN117008818A (zh) 数据处理方法、装置、计算机设备和计算机可读存储介质
CN109597903A (zh) 图像文件处理装置和方法、文件存储系统及存储介质
US10482076B2 (en) Single level, multi-dimension, hash-based table partitioning
CN107797758B (zh) 数据存储方法、数据访问方法及装置
CN105208096A (zh) 分布式缓存系统和方法
CN112380004A (zh) 内存管理方法、装置、计算机可读存储介质及电子设备
CN114338718B (zh) 面向巨量遥感数据的分布式存储方法、装置及介质
CN111428114A (zh) Elasticsearch搜索引擎的索引创建方法及装置
WO2021004295A1 (zh) 一种元数据的处理方法、装置及计算机可读存储介质
CN105389368A (zh) 一种mpp架构数据库集群元数据管理方法
CN110597809A (zh) 一种支持树状数据结构的一致性算法系统及其实现方法

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: 16856564

Country of ref document: EP

Kind code of ref document: A1

REEP Request for entry into the european phase

Ref document number: 2016856564

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE