US-20260127190-A1 - DATA QUERY METHOD AND APPARATUS
Abstract
One or more implementations of this specification provide a data query method and apparatus, including: performing range filtering on pre-constructed index data based on a query condition in a data query instruction and row-stored data in the index data to obtain a first data range; filtering the first data range based on another query condition and column-stored data in the index data to obtain a second data range; and processing data in the second data range based on the data query instruction to obtain a data query result. In the implementations of this specification, row-stored data and column-stored data are pre-constructed, so that in a data query operation, the row-stored data and the column-stored data can be invoked simultaneously, and a data intersection is calculated by using the row-stored data and the column-stored data, to quickly select a queried data range, thereby improving data query efficiency of a database.
Inventors
- Zhuoran Zhang
- Zhenjiang Xie
Assignees
- Beijing Oceanbase Technology Co., Ltd.
Dates
- Publication Date
- 20260507
- Application Date
- 20251229
- Priority Date
- 20231122
Claims (20)
- 1 . A data query method, comprising: receiving a data query instruction, the data query instruction including a plurality of query conditions; performing range filtering on index data based on a first query condition of the plurality of query conditions and a first one of row-stored data or column-stored data in the index data to obtain a first data range; filtering the first data range based on a second query condition of the plurality of query conditions and a second one of the row-stored data or the column-stored data in the index data to obtain a second data range; and processing data in the second data range based on the data query instruction to obtain a data query result.
- 2 . The method according to claim 1 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining, from the index data based on a query field corresponding to the first query condition and the first one of the row-stored data or the column-stored data, a first offset in row or in column corresponding to the first one of the row-stored data or the column-stored data that satisfies the first query condition; and performing range filtering on the index data based on the first offset to obtain the first data range.
- 3 . The method according to claim 1 , wherein the filtering the first data range based on the second query condition of the plurality of query conditions and the second one of the row-stored data or the column-stored data in the index data to obtain the second data range comprises: determining, from the index data based on a query field corresponding to the second query condition and the second one of the row-stored data or the column-stored data, a third data range that satisfies the second query condition; and determining the second data range based on an intersection of the third data range and the first data range.
- 4 . The method according to claim 1 , wherein the processing data in the second data range based on the data query instruction to obtain the data query result comprises: reading the data in the second data range based on the first one of the row-stored data or the column-stored data in response to that a quantity of columns or rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range meets a threshold, and processing the data to obtain the data query result; and reading the data in the second data range based on the second one of the row-stored data or the column-stored data in response to that the quantity of the columns or the rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range does not meet the threshold, and processing the data to obtain the data query result.
- 5 . The method according to claim 1 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining target index data from a plurality of pieces of index data based on a query field corresponding to the first query condition; and performing range filtering on the target index data based on the first query condition and the target index data to obtain the first data range.
- 6 . The method according to claim 1 , comprising: generating an index table based on to-be-stored data; writing the to-be-stored data into a data storage element based on the index table; respectively generating the row-stored data and the column-stored data based on data in the data storage element in response to that an amount of data written into the data storage element reaches a capacity threshold; and constructing the index data based on the row-stored data and the column-stored data generated.
- 7 . The method according to claim 1 , comprising: generating a plurality of index tables based on a query field in to-be-stored data; and for each index table of the plurality of index tables, constructing corresponding index data based on the index table.
- 8 . A database system, comprising: one or more processors; and one or more storage elements, the one or more storage element, individually or collectively, storing computer instructions, the computer instructions, when executed by the one or more processors, enabling the one or more processors to, individually or collectively, perform acts including: receiving a data query instruction, the data query instruction including a plurality of query conditions; performing range filtering on index data based on a first query condition of the plurality of query conditions and a first one of row-stored data or column-stored data in the index data to obtain a first data range; filtering the first data range based on a second query condition of the plurality of query conditions and a second one of the row-stored data or the column-stored data in the index data to obtain a second data range; and processing data in the second data range based on the data query instruction to obtain a data query result.
- 9 . The database system according to claim 8 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining, from the index data based on a query field corresponding to the first query condition and the first one of the row-stored data or the column-stored data, a first offset in row or in column corresponding to the first one of the row-stored data or the column-stored data that satisfies the first query condition; and performing range filtering on the index data based on the first offset to obtain the first data range.
- 10 . The database system according to claim 8 , wherein the filtering the first data range based on the second query condition of the plurality of query conditions and the second one of the row-stored data or the column-stored data in the index data to obtain the second data range comprises: determining, from the index data based on a query field corresponding to the second query condition and the second one of the row-stored data or the column-stored data, a third data range that satisfies the second query condition; and determining the second data range based on an intersection of the third data range and the first data range.
- 11 . The database system according to claim 8 , wherein the processing data in the second data range based on the data query instruction to obtain the data query result comprises: reading the data in the second data range based on the first one of the row-stored data or the column-stored data in response to that a quantity of columns or rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range meets a threshold, and processing the data to obtain the data query result; and reading the data in the second data range based on the second one of the row-stored data or the column-stored data in response to that the quantity of the columns or the rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range does not meet the threshold, and processing the data to obtain the data query result.
- 12 . The database system according to claim 8 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining target index data from a plurality of pieces of index data based on a query field corresponding to the first query condition; and performing range filtering on the target index data based on the first query condition and the target index data to obtain the first data range.
- 13 . The database system according to claim 8 , wherein the acts include: generating an index table based on to-be-stored data; writing the to-be-stored data into a data storage element based on the index table; respectively generating the row-stored data and the column-stored data based on data in the data storage element in response to that an amount of data written into the data storage element reaches a capacity threshold; and constructing the index data based on the row-stored data and the column-stored data generated.
- 14 . The database system according to claim 8 , wherein the acts include: generating a plurality of index tables based on a query field in to-be-stored data; and for each index table of the plurality of index tables, constructing corresponding index data based on the index table.
- 15 . A storage medium, having computer instructions stored therein, wherein the computer instructions, when executed by one or more processors, enable the one or more processors to, individually or collectively, implement acts comprising: receiving a data query instruction, the data query instruction including a plurality of query conditions; performing range filtering on index data based on a first query condition of the plurality of query conditions and a first one of row-stored data or column-stored data in the index data to obtain a first data range; filtering the first data range based on a second query condition of the plurality of query conditions and a second one of the row-stored data or the column-stored data in the index data to obtain a second data range; and processing data in the second data range based on the data query instruction to obtain a data query result.
- 16 . The storage medium according to claim 15 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining, from the index data based on a query field corresponding to the first query condition and the first one of the row-stored data or the column-stored data, a first offset in row or in column corresponding to the first one of the row-stored data or the column-stored data that satisfies the first query condition; and performing range filtering on the index data based on the first offset to obtain the first data range.
- 17 . The storage medium according to claim 15 , wherein the filtering the first data range based on the second query condition of the plurality of query conditions and the second one of the row-stored data or the column-stored data in the index data to obtain the second data range comprises: determining, from the index data based on a query field corresponding to the second query condition and the second one of the row-stored data or the column-stored data, a third data range that satisfies the second query condition; and determining the second data range based on an intersection of the third data range and the first data range.
- 18 . The storage medium according to claim 15 , wherein the processing data in the second data range based on the data query instruction to obtain the data query result comprises: reading the data in the second data range based on the first one of the row-stored data or the column-stored data in response to that a quantity of columns or rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range meets a threshold, and processing the data to obtain the data query result; and reading the data in the second data range based on the second one of the row-stored data or the column-stored data in response to that the quantity of the columns or the rows of the data corresponding to the second one of the row-stored data or the column-stored data in the second data range does not meet the threshold, and processing the data to obtain the data query result.
- 19 . The storage medium according to claim 15 , wherein the performing range filtering on the index data based on the first query condition of the plurality of query conditions and the first one of the row-stored data or the column-stored data in the index data to obtain the first data range comprises: determining target index data from a plurality of pieces of index data based on a query field corresponding to the first query condition; and performing range filtering on the target index data based on the first query condition and the target index data to obtain the first data range.
- 20 . The storage medium according to claim 15 , wherein the acts comprise: generating an index table based on to-be-stored data; writing the to-be-stored data into a data storage element based on the index table; respectively generating the row-stored data and the column-stored data based on data in the data storage element in response to that an amount of data written into the data storage element reaches a capacity threshold; and constructing the index data based on the row-stored data and the column-stored data generated.
Description
TECHNICAL FIELD One or more implementations of this specification relate to the field of database technologies, and in particular, to a data query method and apparatus. BACKGROUND With development of technologies, data amounts of various types of data increase explosively, and a database can provide services such as data storage and query. In a related technology, as an amount of business data continuously increase, an amount of index data created to query the business data increases accordingly. SUMMARY One or more implementations of this specification provide a data query method and apparatus, a database system, and a storage medium. According to a first aspect of one or more implementations of this specification, a data query method is provided, including: obtaining a data query instruction, where the data query instruction includes a plurality of query conditions; performing range filtering on pre-constructed index data based on at least one query condition in the plurality of query conditions and row-stored data in the index data to obtain a first data range; filtering the first data range based on another query condition in the plurality of query conditions and column-stored data in the index data to obtain a second data range; and processing data in the second data range based on the data query instruction to obtain a data query result. In one or more implementations of this specification, the performing range filtering on pre-constructed index data based on at least one query condition in the plurality of query conditions and row-stored data in the index data to obtain a first data range includes: determining, from the index data based on a query field corresponding to the at least one query condition and the row-stored data, a row offset that satisfies the query condition; and performing range filtering on the index data based on the row offset to obtain the first data range. In one or more implementations of this specification, the filtering the first data range based on another query condition in the plurality of query conditions and column-stored data in the index data to obtain a second data range includes: determining, from the index data based on a query field corresponding to the another query condition and the column-stored data, a column data range that satisfies the query condition; and determining the second data range based on an intersection of the column data range and the first data range. In one or more implementations of this specification, the processing data in the second data range based on the data query instruction to obtain a data query result includes: reading the data in the second data range based on the row-stored data in response to that a quantity of columns of the data in the second data range is greater than a preset threshold, and processing the data to obtain the data query result; and reading the data in the second data range based on the column-stored data in response to that column data of the data in the second data range is less than or equal to the preset threshold, and processing the data to obtain the data query result. In one or more implementations of this specification, the performing range filtering on pre-constructed index data based on at least one query condition in the plurality of query conditions and row-stored data in the index data to obtain a first data range includes: determining target index data from a plurality of pieces of pre-constructed index data based on a query field corresponding to the at least one query condition; and performing range filtering on the target index data based on the at least one query condition and the target index data to obtain the first data range. In one or more implementations of this specification, a process of pre-constructing the index data includes: generating a preset index table based on to-be-stored data; writing the to-be-stored data into a memory based on the preset index table; respectively generating row-stored data and column-stored data in each column based on data in the memory in response to that an amount of data written into the memory reaches a preset capacity; and constructing the index data based on the row-stored data and the column-stored data. In one or more implementations of this specification, a process of pre-constructing the index data includes: generating a plurality of preset index tables based on a query field in to-be-stored data; and for each preset index table, constructing corresponding index data based on the preset index table. According to a second aspect of one or more implementations of this specification, a data query apparatus is provided, including: an instruction acquisition module, configured to obtain a data query instruction, where the data query instruction includes a plurality of query conditions; a first filtering module, configured to perform range filtering on pre-constructed index data based on at least one query condition in the plurality of query conditions