A method, apparatus, medium and device for data query

By constructing baseline and incremental logical row numbers in the LSM-Tree architecture database, the query performance problem caused by comparing the primary keys of baseline and incremental data one by one is solved, and more efficient data query is achieved.

CN116521734BActive Publication Date: 2026-02-03BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310442731.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-23
Publication Date
2026-02-03
Estimated Expiration
2043-04-23

AI Technical Summary

Technical Problem

Existing LSM-Tree architecture databases require comparing the primary keys of baseline and incremental data one by one during queries, which leads to a decrease in query performance, especially when the primary key contains multiple data columns or character set types.

Method used

By constructing baseline logical row numbers in the baseline data and determining incremental logical row numbers based on the operation type when writing data, primary key comparisons are reduced, and query results from baseline and incremental data are directly merged.

Benefits of technology

It improves data query efficiency and reduces the time spent on primary key comparisons, especially when the primary key contains multiple data columns or character set types, significantly improving query performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116521734B_ABST
    Figure CN116521734B_ABST
Patent Text Reader

Abstract

The specification discloses a method, device, medium and equipment for data query, receives a specified operation request, finds a primary key corresponding to to-be-operated data in baseline data according to the primary key, determines a baseline logical row number corresponding to the query result according to the query result and the specified operation request, and determines an incremental logical row number corresponding to the to-be-operated data according to the baseline logical row number. The correspondence between the to-be-operated data and the incremental logical row number is stored as incremental data. When a query request is received, a first query result of the baseline data and a second query result of the incremental data are determined according to a query range of the query request, and the query results are merged according to the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result to determine a final query result. The data obtained through query is merged according to the incremental logical row number and the baseline logical row number, thereby improving the efficiency of data query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, medium and device for data query. Background Technology

[0002] With the development of technology, various databases have emerged. Currently, databases based on the Log-Structured Merge Tree (LSM-Tree) architecture are widely used. This architecture consists of two parts: incremental data (MemTable) and baseline data (Sorted String Table, SSTable). Incremental data is stored in memory, while baseline data is stored on disk, both ordered by primary key by default. Incremental data generated from data modifications is first stored in memory. When the data in memory reaches a certain threshold, the memory data is then transferred to disk, improving data write efficiency.

[0003] However, when querying data, incremental and baseline data must be queried sequentially, and the primary keys of the retrieved incremental and baseline data must be compared one by one. Based on the comparison results, the merged result of the incremental and baseline data is determined as the query result. Generally, databases contain a large amount of data, and both baseline and incremental data contain numerous primary keys. Performing a one-to-one comparison during merging significantly slows down query performance. This is especially true when the primary key contains multiple data columns, or when the primary key contains data columns that cannot be easily compared as byte streams, such as strings with character sets; the query efficiency will be further reduced.

[0004] Based on this, this solution provides a method for data querying. Summary of the Invention

[0005] This specification provides a method, apparatus, storage medium, and device for data querying, to at least partially solve the aforementioned problems existing in the prior art.

[0006] The following technical solution is adopted in this specification:

[0007] This specification provides a method for data querying, the method including:

[0008] Receive a specified operation request for the database, and search for the primary key in the baseline data according to the primary key corresponding to the data to be operated carried in the specified operation request to determine the query result of the specified operation;

[0009] Based on the specified operation query result and the specified operation request, determine the baseline logical row number corresponding to the specified operation query result, and determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number;

[0010] Determine the correspondence between the data to be operated on and the incremental logical row number, and store it as incremental data;

[0011] When a query request is received, based on the query scope of the query request, a first query result in the baseline data within the query scope and a second query result in the incremental data within the query scope are determined.

[0012] Based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, the query results are merged to determine the final query result.

[0013] Optionally, based on the specified operation query result and the specified operation request, the baseline logical row number corresponding to the specified operation query result is determined, and the incremental logical row number corresponding to the data to be operated is determined based on the baseline logical row number, specifically including:

[0014] The query result of the specified operation is determined to be the primary key in the baseline data;

[0015] If the specified operation request is to add, then the preset invalid identifier is determined as the baseline logical row number corresponding to the specified operation query result, the invalid identifier is used as the main incremental logical row number corresponding to the data to be operated, and the preset first value is used as the secondary incremental logical row number corresponding to the data to be operated.

[0016] If the specified operation request is either deletion or modification, then the baseline logical row number corresponding to the primary key in the baseline data is determined to be the baseline logical row number corresponding to the specified operation query result. The baseline logical row number is used as the primary incremental logical row number corresponding to the data to be operated on, and the preset second value is used as the secondary incremental logical row number corresponding to the data to be operated on.

[0017] Optionally, based on the specified operation query result and the specified operation request, the baseline logical row number corresponding to the specified operation query result is determined, and the incremental logical row number corresponding to the data to be operated is determined based on the baseline logical row number, specifically including:

[0018] When the query result of the specified operation is empty, the primary key that is sorted before the primary key corresponding to the data to be operated on is selected from the primary keys of the baseline data according to the primary key sorting and is used as the candidate primary key;

[0019] Determine the baseline logical row number corresponding to the last primary key in the sorting of each candidate primary key, and use it as the baseline logical row number corresponding to the query result;

[0020] The baseline logical row number corresponding to the query result of the specified operation is used as the primary incremental logical row number corresponding to the data to be operated, and the preset third value is used as the secondary incremental logical row number corresponding to the data to be operated.

[0021] Optionally, the method further includes:

[0022] When the query result of the specified operation is abnormal, the preset invalid identifier is used as the main incremental logical row number corresponding to the data to be operated, and the preset first value is used as the secondary incremental logical row number corresponding to the data to be operated.

[0023] Optionally, the query results are merged based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, specifically including:

[0024] For each incremental data in the second query result, if the incremental logical row number corresponding to the incremental data is a preset first value, then the incremental data is deleted.

[0025] If the incremental logical row number corresponding to the incremental data is a preset second value, then according to the main incremental logical row number corresponding to the incremental data, the specified operation corresponding to the incremental data is performed on the baseline data with the same main incremental logical row number in the first query result to determine the merged query result;

[0026] If the incremental data corresponds to the incremental logical row number of the preset third value, and the specified operation corresponding to the incremental data is addition or modification, the incremental data will be used as the merged query result.

[0027] If the incremental logical row number corresponding to the incremental data is the preset third value, and the specified operation corresponding to the incremental data is deletion, then the incremental data is deleted.

[0028] Optionally, the method further includes:

[0029] For each incremental data in the second query result, if the incremental logical row number corresponding to the incremental data is a preset first value, then the primary key corresponding to the incremental data is retrieved in the first query result.

[0030] If the primary key exists in the lookup result and the specified operation corresponding to the incremental data is "add", then delete the incremental data.

[0031] If the primary key exists in the lookup result and the specified operation corresponding to the incremental data is modification, the baseline data corresponding to the lookup result is updated according to the incremental data to determine the merged query result;

[0032] If the primary key exists in the lookup result, and the specified operation corresponding to the incremental data is deletion, delete the incremental data and the baseline data corresponding to the lookup result;

[0033] If the primary key does not exist in the lookup result, and the specified operation corresponding to the incremental data is deletion, then delete the incremental data.

[0034] If the primary key does not exist in the lookup result, and the specified operation corresponding to the incremental data is modification or addition, the incremental data will be included in the merged query result.

[0035] Optionally, if the incremental data corresponds to a sub-increment logical row number that is a preset third value, and the specified operation corresponding to the incremental data is an add or modify operation, then the incremental data is used as the merged query result, specifically including:

[0036] If the incremental logical row number corresponding to the incremental data is a preset third value, the baseline logical row number is determined to be no greater than the baseline data of the main incremental logical row number based on the main incremental logical row number corresponding to the incremental data.

[0037] The incremental data is inserted after the determined baseline data and used as the result of the merged query.

[0038] Optionally, query results can be merged, specifically including:

[0039] The incremental data in the second query result that is not merged with the first query result is identified as unmerged data.

[0040] Identify incremental data with the same primary key among the unmerged data;

[0041] The incremental data with the same primary key are merged according to their respective specified operations to determine the merged data;

[0042] The final query result is determined based on the data obtained by merging the first query result and the second query result, as well as the merged data.

[0043] Optionally, the query results are merged based on the baseline logical row number corresponding to each data point in the first query result and the incremental logical row number corresponding to each data point in the second query result. Specifically, this includes:

[0044] Determine the ascending order of the main incremental logical row numbers of the incremental data in the second query result;

[0045] In the order described above, for each incremental data in the second query result, based on the main incremental logical row number corresponding to the incremental data, determine each baseline data in the first query result whose baseline logical row number is not after the main incremental logical row number, and take it as the data to be updated.

[0046] Based on the main incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data, the data to be updated is updated. The update result and the remaining data in the first query result are used as the first query result again. The remaining incremental data in the second query result are traversed until all incremental data in the second query result are traversed. Then, the updated first query result is determined to be the merged query result.

[0047] Optionally, the data to be updated is updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data, specifically including:

[0048] When the incremental logical row number corresponding to the incremental data is a preset first value, check back whether the primary key corresponding to the incremental data exists in the first query result;

[0049] If it exists, and the specified operation corresponding to the incremental data is either modification or deletion, then the data to be updated is updated according to the specified operation and the incremental data to obtain the update result;

[0050] If the data does not exist, and the specified operation corresponding to the incremental data is either modification or addition, then the incremental data in the second query result is inserted into the data to be updated to obtain the update result.

[0051] Optionally, the data to be updated is updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data, specifically including:

[0052] When the incremental logical row number corresponding to the incremental data is a preset third value, and the specified operation is either an add or a modify operation, the incremental data in the second query result is inserted into the tail of the data to be updated to obtain the update result.

[0053] Optionally, the data to be updated is updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data, specifically including:

[0054] When the incremental logical row number corresponding to the incremental data is a preset second value, the baseline data in the data to be updated that has the same primary key as the incremental data is updated according to the specified operation and the incremental data, and the update result is obtained.

[0055] This specification provides a data query device, comprising:

[0056] The receiving module is used to receive a specified operation request to the database, and according to the primary key corresponding to the data to be operated carried in the specified operation request, search for the primary key in the baseline data to determine the specified operation query result.

[0057] The first determining module is used to determine the baseline logical row number corresponding to the specified operation query result based on the specified operation query result and the specified operation request, and to determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number.

[0058] The storage module is used to determine the correspondence between the data to be operated on and the incremental logical row number, and to store the data as incremental data;

[0059] The query module is used to, when a query request is received, determine a first query result in the baseline data within the query range and a second query result in the incremental data within the query range, based on the query range of the query request.

[0060] The second determining module is used to merge the query results based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, and determine the final query result.

[0061] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described data query method.

[0062] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described data query method.

[0063] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:

[0064] In the data query method provided in this specification, firstly, a specified operation request for the database is received. Based on the primary key corresponding to the data to be operated on, carried in the specified operation request, the primary key is searched in the baseline data. Then, based on the query result and the specified operation request, the baseline logical row number corresponding to the query result is determined, and the incremental logical row number corresponding to the data to be operated on is determined based on this baseline logical row number. Furthermore, the correspondence between the data to be operated on and the incremental logical row numbers is determined and stored as incremental data. Finally, when a query request is received, based on the query scope of the query request, a first query result for the baseline data and a second query result for the incremental data are determined. The query results are then merged based on the baseline logical row numbers corresponding to each baseline data in the first query result and the incremental logical row numbers corresponding to each incremental data in the second query result to determine the final query result.

[0065] As can be seen from the above method, by constructing baseline logical row numbers corresponding to each primary key in the baseline data, and determining the incremental logical row number of the incremental data based on the operation type of the written data, the primary key corresponding to the written data, and the baseline logical row number during data writing, the queried data can be merged and output when performing data queries to merge the baseline data and incremental data. This eliminates the need to compare the primary keys of the queried baseline data and incremental data one by one, reducing the time spent on primary key comparisons and improving the efficiency of data querying. Attached Figure Description

[0066] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and their descriptions, serving to explain this specification and do not constitute an undue limitation thereof.

[0067] In the picture:

[0068] Figure 1 This is a flowchart illustrating one of the data query methods described in this specification.

[0069] Figure 2a This is a schematic diagram of a baseline logical row number provided in this specification;

[0070] Figure 2b This is a schematic diagram of an incremental logical line number provided in this specification;

[0071] Figure 3 This is a schematic diagram illustrating a query result merging method provided in this specification.

[0072] Figure 4 This is a schematic diagram illustrating a query result merging method provided in this specification.

[0073] Figure 5 A schematic diagram of a data query device provided in this specification;

[0074] Figure 6 The corresponding information provided in this specification Figure 1 A schematic diagram of an electronic device. Detailed Implementation

[0075] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments in this specification without creative effort are within the scope of protection of this application.

[0076] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.

[0077] Figure 1 This is a flowchart illustrating a data query method provided in this specification, which may specifically include the following steps:

[0078] S100: Receive a specified operation request for the database, and search for the primary key in the baseline data according to the primary key corresponding to the data to be operated carried in the specified operation request, and determine the specified operation query result.

[0079] Currently, in databases based on the LSM-Tree architecture, the incremental data in memory and the baseline data on disk are updated asynchronously. Therefore, during data queries, there are situations where baseline data with the same primary key is merged with incremental data for output. However, merging baseline and incremental data requires comparing the primary keys of each data type in the baseline data with those in the incremental data. A large number of primary key comparisons degrade query performance, especially when the primary key contains multiple data columns, and when these columns are types that cannot be easily compared as byte streams, such as strings with character sets. This specification provides a data query method that can effectively improve data query performance.

[0080] It should be noted that in one or more embodiments of this specification, a "primary key" is used for ease of description. This primary key represents the position of different rows of data in a database table. However, due to different business requirements, different read / write efficiency requirements, etc., some databases do not have primary keys. This method is still applicable to databases without primary keys. For databases without primary keys, logical row numbers can be determined based on identifiers that locate different rows of data in the database; the specific method is not limited in this specification. For ease of description, one or more embodiments of this specification will use a database with a primary key as an example.

[0081] Furthermore, in one or more embodiments of this specification, the baseline data of the database is provided with baseline logical row numbers, and each primary key in the baseline data corresponds one-to-one with these baseline logical row numbers. It should be noted that the database can be a relational database, a non-relational database, a distributed database, etc., and this specification does not limit the specific type of database. Since different types of databases have different functions for different nodes, for ease of description, this specification uses a server as the execution entity for explanation.

[0082] Specifically, first, the server can receive a specified operation request, which includes insert, delete, and update operations. Then, based on the primary key of the data to be operated on carried in the specified operation request, the server queries the baseline data for that primary key to determine the query result for the specified operation.

[0083] Because a constraint check is performed during data writing to prevent duplicate primary keys, a query is performed in the baseline data based on the primary key corresponding to the data being written. This query determines whether the primary key exists, and subsequent steps, based on the query results and the operation type, determine whether the specified operation can be executed correctly.

[0084] S102: Based on the specified operation query result and the specified operation request, determine the baseline logical row number corresponding to the specified operation query result, and determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number.

[0085] S104: Determine the correspondence between the data to be operated and the incremental logical row number, and store it as incremental data.

[0086] In one or more embodiments of this specification, after the server receives a specified operation request through the above steps, queries the primary key in the baseline data according to the primary key corresponding to the data to be operated, and determines the specified operation query result, it can also determine the baseline logical row number corresponding to the specified operation query result according to the specified operation query result and the specified operation request, and then determine the incremental logical row number corresponding to the data to be operated according to the baseline logical row number.

[0087] Specifically, first, the server can query the baseline data based on the primary key corresponding to the data to be operated on, and determine the baseline logical row number corresponding to the query result of the specified operation based on the specified operation request. Then, it determines the incremental logical row number corresponding to the data to be operated on based on the baseline logical row number. Finally, it determines the correspondence between the data to be operated on and the incremental logical row number, and stores this relationship as incremental data.

[0088] Since the data is first written to memory, and the data in memory and on disk are updated asynchronously in a database based on an LSM-Tree architecture, the position of the primary key corresponding to the data to be operated on cannot be immediately and accurately determined in the baseline data under different operation scenarios. Therefore, the position of the data to be operated on cannot be determined solely by the baseline logical row number of the primary key corresponding to the data to be operated on. Therefore, in one or more embodiments of this specification, for incremental data, an incremental logical row number is used to identify its position in the baseline data. The incremental logical row number consists of a primary incremental logical row number and a secondary incremental logical row number. The primary incremental logical row number is used to identify the position of the primary key corresponding to the data to be operated on in the current baseline data, and the secondary incremental logical row number is used to identify the actual position of the data to be operated on under different operation scenarios such as adding, deleting, and modifying.

[0089] Furthermore, when the server determines that the primary key corresponding to the primary key of the data to be operated on is the primary key in the baseline data (meaning the primary key corresponding to the data to be operated on exists in the baseline data), if the specified operation request is an increment, since the principle of unique primary keys cannot be violated, a preset invalidity flag can be used as the baseline logical row number corresponding to the specified operation query result. Then, the preset invalidity flag can be used as the primary incremental logical row number corresponding to the data to be operated on, and a preset first value can be used as the secondary incremental logical row number corresponding to the data to be operated on. Here, the preset first value indicates that the baseline logical row number corresponding to the query result is invalid and / or the query has encountered an anomaly, and the preset invalidity flag indicates that the primary incremental logical row number in the incremental logical row number is invalid.

[0090] If the specified operation request is deletion or modification, it indicates that the data to be deleted or modified can be found in the baseline data. Therefore, the baseline logical row number in the baseline data corresponding to the primary key can be used as the baseline logical row number corresponding to the query result. This baseline logical row number is then used as the primary incremental logical row number corresponding to the data to be modified, and a preset second value is used as the secondary incremental logical row number corresponding to the data to be modified. The preset second value indicates that the baseline logical row number corresponding to the specified operation query result is precise, meaning that the corresponding data can be found in the baseline data based on the baseline logical row number of the query result.

[0091] When the query result for the primary key corresponding to the data to be operated on is empty, meaning the primary key corresponding to the data does not exist in the baseline data, regardless of the type of operation, the primary key sorted before the primary key in the baseline data is selected as the candidate primary key. Then, the baseline logical row number corresponding to the last primary key among the candidate primary keys is determined and used as the baseline logical row number corresponding to the query result of the specified operation. Finally, the baseline logical row number corresponding to the query result of the specified operation is used as the primary incremental logical row number corresponding to the data to be operated on, and a preset third value is used as the secondary incremental logical row number corresponding to the data to be operated on. The preset third value indicates that the position of the primary key corresponding to the data to be operated on is between the baseline logical row number corresponding to the query result of the specified operation and the baseline logical row number + 1.

[0092] Furthermore, when querying the primary key corresponding to the data to be operated on in the baseline data, if a partial logical error or physical error occurs in the database, causing the query to fail, an error message will be returned. For example, if the database is a distributed database, and the primary key corresponding to the data to be operated on in the baseline data is stored on another device, meaning a network connection is required to query the primary key corresponding to the data to be operated on in the baseline data, then a network outage will prevent the query from proceeding and will return an error message. Therefore, when the query result is abnormal, a preset invalid identifier can be used as the primary incremental logical row number corresponding to the data to be operated on, and a preset first value can be used as the secondary incremental logical row number corresponding to the data to be operated on.

[0093] It should be noted that in one or more embodiments of this specification, the baseline logical row number corresponds one-to-one with the primary key of the baseline data. The baseline logical row number can be constructed based on the sorting of the primary keys, assigning numbers to each primary key. Assuming the primary keys corresponding to the five rows of data in the baseline data are arranged in ascending order as 50, 100, 160, 200, and 1000, then their corresponding baseline logical row numbers are 0, 1, 2, 3, and 4, respectively. Of course, numbering can start from 0 or 10; the values ​​of the logical row numbers used do not need to be consecutive, as long as they mark each row of data in a certain order. Furthermore, the numbering of logical row numbers is not limited to numbers; letters can also be used, and rows can be marked according to lexicographical order, etc. However, using consecutive numbers is the most convenient and efficient method. For ease of description, in one or more embodiments of this specification, natural numbers are used to mark the baseline logical row numbers corresponding to each primary key in the baseline data.

[0094] The method for setting the preset first, second, and third values, as well as the preset invalid identifier, is the same; it can be a single number, multiple numbers, or special characters. Of course, using a simpler representation method is more conducive to improving query efficiency. For ease of description, in one or more embodiments of this specification, "11" represents the preset first value, "00" represents the preset second value, and "01" represents the preset third value, while "-1" represents the preset invalid identifier.

[0095] Furthermore, there are many ways to connect the primary and secondary incremental logical row numbers for the incremental logical row numbers corresponding to the data to be operated on. One method is to use ".". Alternatively, the primary incremental logical row number can be written first, followed by the secondary incremental logical row number, i.e., without a gap. For example, when using "01", "00", and "11" as secondary incremental logical row numbers, we know that the last two digits of the incremental logical row number are the secondary incremental logical row number; removing the last two digits gives the primary incremental logical row number. This specification does not limit the connection method. For ease of description, one or more embodiments in this specification are described in the form of (primary incremental logical row number.secondary incremental logical row number).

[0096] like Figure 2a and Figure 2b The figures show a baseline logical row number representation method and an incremental logical row number representation method provided in this specification. Figure 2a As can be seen, a unique identifier V_TID (1-7), representing the baseline logical row number, is constructed based on the sorting of the primary keys in the baseline data (i.e., the key values ​​from smallest to largest). Figure 2b As can be seen, the primary keys corresponding to the data to be operated on for different operation types are arranged in order. Each primary key has a unique identifier V_TID, which consists of two parts separated by ".". The first part of "." is the primary incremental logical line number, and the second part is the secondary incremental logical line number, which is one of the preset first value "11", the preset second value "00", and the preset third value "01".

[0097] Assuming the primary keys corresponding to all existing data in the baseline data are as follows: Figure 2a As shown, no data has been written to memory yet. When a data entry with key 50 is added (i.e., corresponding to...),... Figure 2bThe first operation in the process involves searching for the primary key corresponding to the data in memory, which is 50. Clearly, this primary key is not present in the baseline data, so the insert operation can proceed. Since it's an insert operation and the primary key is not in the baseline data, all primary keys preceding this primary key in the baseline data must be found (empty for primary key 50 here), and the baseline logical row number of the last primary key preceding it is selected as the incremental logical row number corresponding to the query result for this primary key. Since there is no primary key less than 50 in the baseline data, it can be determined that this primary key is the smallest among all primary keys. The smallest baseline logical row number in the baseline data is 1, so it can be set to 0 here, which is the primary incremental logical row number. Furthermore, "01" is used as the secondary incremental logical row number to indicate that the baseline logical row number of the primary key corresponding to this data is not precise; its actual position should be between 0 and 0+1. Finally, the incremental logical row number corresponding to this data is (0.01).

[0098] The second piece of data to be modified has a primary key of 50. Since this is a modification operation, it does not conflict with the first operation of adding data with a primary key of 50. Therefore, we can search for this primary key in the baseline data, but it is obviously not found. This modification operation is equivalent to an addition operation, and we can use the same method described above for adding data with a primary key of 50 to obtain the corresponding incremental logical row number.

[0099] The primary key of the third piece of data to be deleted is 200. This primary key exists in the baseline data, so the exact position of the data to be deleted in the baseline data can be found, which is the baseline logical row number 2. Therefore, the primary incremental logical row number corresponding to this data is determined to be 2. Then, "00" is used as the secondary incremental logical row number to indicate that the position of the primary key corresponding to the data to be deleted in the baseline data is precise; that is, the position of the data to be deleted is the baseline logical row number of the primary key in the baseline data. Therefore, the incremental logical row number of this data is represented by (2.00).

[0100] For the fourth data to be modified, the primary key is 600. Since the baseline data for this primary key is stored on another device, and a network anomaly occurred during the query, the server was unable to establish a connection with the other device, resulting in an error and a returned error message. Therefore, "11" is used to indicate that the query result for this primary key is abnormal, and a preset invalid flag "-1" is used to indicate that the query result for this primary key is abnormal. Therefore, its incremental logical row number is (-1.11). Of course, when the query result is abnormal, the incremental logical row number corresponding to each query result can be directly represented by "11". The primary incremental logical row number can be left unset or set to any value; this manual does not restrict the specific setting. In other words, when the incremental logical row number is "11", its primary incremental logical row number is invalid regardless of its value.

[0101] The primary key for the fifth piece of data to be added is 800. Since this primary key cannot be found in the baseline data, we can identify the primary keys preceding it in the baseline data as candidate primary keys: 100, 200, 400, 450, 500, 600, and 700. Then, we determine the baseline logical row number of the primary key at the end of the candidate primary keys, which corresponds to primary key 700: 7. We use 7 as the primary increment logical row number for the data to be added, and finally, we use "01" as the secondary increment logical row number, determining the increment logical row number to be (7.01).

[0102] After determining the incremental logical row number corresponding to the data to be operated on, the server can determine and store the correspondence between the data to be operated on and the incremental logical row number. This allows for the merging of baseline data and incremental data in subsequent steps using both the incremental logical row number and the baseline logical row number.

[0103] S106: When a query request is received, based on the query scope of the query request, determine the first query result in the baseline data within the query scope and the second query result in the incremental data within the query scope.

[0104] S108: Based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, merge the query results to determine the final query result.

[0105] Since the data is written to memory first, and the data in memory and the data on disk are updated asynchronously in a database based on LSM-Tree architecture, when performing a data query, some data in memory has not yet been updated to disk. It is necessary to query both baseline data and incremental data, and then merge the query results to obtain the final result.

[0106] Specifically, when a query request is received, the server can determine the first query result in the baseline data and the second query result in the incremental data based on the query range of the query conditions. Then, for each incremental data in the second query result, the query results are merged according to the incremental logical row number corresponding to that incremental data and the baseline logical row number of the primary key corresponding to that incremental data in the baseline data to determine the final query result. For example, there is an information table about the name, unit price, purchase price, and quantity of a product, with the name set as the primary key. Now, to query the information of products with a unit price in the range of 20-30, the server first retrieves the primary key of the product with a unit price in the range of 20-30 by using the unit price index. Then, based on the retrieved primary key, the server scans the baseline data and the incremental data to obtain the first query result in the baseline data and the second query result in the incremental data.

[0107] Furthermore, since the data in the second query result is the latest version, when merging the data in the first and second query results, we can first traverse the incremental logical row number corresponding to each incremental data in the second query result to determine whether the data in the first query result has been modified, and then merge the data.

[0108] Specifically, since the incremental logical row number is used to record the actual position of each incremental data, the incremental logical row number of each incremental data can be determined first. For each incremental data in the second query result, if the incremental logical row number corresponding to that incremental data is a preset first value, then that incremental data is deleted. In other words, if this specified operation is incorrect, the incremental data written into the incremental data according to this specified operation can be directly deleted.

[0109] If the incremental logical row number corresponding to the incremental data is a preset second value, then based on the primary incremental logical row number corresponding to the incremental data, the specified operation corresponding to the incremental data is executed on the baseline data with the same primary incremental logical row number in the first query result to determine the merged query result. When the incremental logical row number is a preset second value, it can be a modification or deletion operation. That is, the position of the baseline data corresponding to the incremental data is the baseline data at the position corresponding to the primary incremental logical row number. Therefore, based on the deletion or modification operation, the baseline data at the position corresponding to the primary incremental logical row number of the incremental data is deleted or modified to obtain the query result corresponding to the primary key of the incremental data after the specified operation modification.

[0110] If the incremental logical row number corresponding to the incremental data is a preset third value, and the specified operation corresponding to the incremental data is add or modify, then based on the main incremental logical row number corresponding to the incremental data, determine the baseline logical row number that is not greater than the main incremental logical row number, and insert the incremental data after the determined baseline data as the merged query result.

[0111] Since the data to be deleted is written to the incremental data before deletion, this data will not appear in the baseline data (it does not exist). Therefore, when the incremental logical row number corresponding to this incremental data is the preset third value and the specified operation is deletion, this incremental data does not need to be output. Therefore, if the incremental logical row number corresponding to this incremental data is the preset third value and the specified operation is deletion, then this incremental data is deleted.

[0112] Furthermore, since the specified operation might result in a query error due to some kind of mistake, it would also cause the incremental logical index to return to the first value. Therefore, the server can also, for each incremental data in the second query result, if the incremental logical row number corresponding to that incremental data is a preset first value, look up the primary key corresponding to that incremental data in the first query result.

[0113] When the primary key exists in the lookup result, if the specified operation for the incremental data is "add," it means that the primary key baseline data corresponding to the added incremental data already exists. Since primary keys cannot be duplicated, the specified operation cannot be performed, and the incremental data in the second query result is deleted. The query result corresponding to this primary key is then the data in the baseline data corresponding to that primary key. When the primary key does not exist in the lookup result, and the specified operation for the incremental data is "add," the incremental data is included in the merged query result.

[0114] When the primary key exists in the lookup result, if the specified operation corresponding to the incremental data is modification, the baseline data corresponding to the lookup result is updated based on the incremental data to determine the merged query result. When the primary key does not exist in the lookup result, and the specified operation corresponding to the incremental data is modification, the incremental data is used as data in the merged query result. For example, if a modification operation has an incremental logical row number of (11.-1), it can be inferred from the incremental logical "-1" that the operation could not be performed due to a logical or physical error. Therefore, the baseline data can be looked up based on the primary key of the data corresponding to the modification operation to determine whether the primary key exists in the baseline data. If it exists, the data corresponding to the primary key is modified according to the modification operation. If it does not exist, it means that the data corresponding to the modification operation does not exist in the baseline data, and the modification operation is performed as an insert operation, that is, the data corresponding to the modification operation is to be written to the baseline data. Therefore, the query result corresponding to the primary key of the incremental data is the incremental data itself.

[0115] When the primary key exists in the lookup result, and the specified operation for the incremental data is deletion (meaning the primary key for this deletion operation exists in the baseline data), then the deletion operation can be performed in the baseline data based on the primary key of the data corresponding to this deletion operation. When the primary key does not exist in the lookup result, and the specified operation for the incremental data is deletion, then the incremental data is deleted. In other words, the primary key corresponding to the data to be deleted does not exist, therefore the query result for that primary key must not exist, and the incremental data can be deleted.

[0116] When merging query results, the server first identifies the incremental data in the second query result that was not merged with the first query result, treating it as unmerged data. Then, it identifies the incremental data with the same primary key among the unmerged data and merges them according to their respective specified operations, determining the merged data. Finally, based on the merged data from the first and second query results, and the merged data, the final query result is determined.

[0117] Figure 3 This is a schematic diagram illustrating a query result merging method provided in this specification. It assumes the primary key range of the queried data is 50-1000. Figure 3As can be seen, based on the query conditions, the primary key that meets the conditions is found in the baseline data to obtain the first query result, and the primary key that meets the conditions is found in the incremental data to obtain the second query result. Then, the data is merged according to the baseline logical row numbers corresponding to each baseline data in the first query result and the incremental logical row numbers corresponding to each incremental data in the second query result to obtain the final query result. First, the primary key corresponding to each data in the second query result must be traversed. Here, we take the data with key 200 and incremental logical row number (2.00) as an example. According to the specified operation corresponding to this incremental data, namely the deletion operation, and its incremental logical row number is 00, it is determined that the primary incremental logical row number corresponding to this incremental data is accurate, and the primary incremental logical row number indicates the position of the primary key of this incremental data in the baseline data. Then, the baseline data corresponding to the primary incremental logical row number can be directly found in the first query result. Therefore, the incremental data corresponding to the second query result can be deleted from the baseline data, and then the data after deleting the incremental data from the baseline data corresponding to the primary key is used as the first query result corresponding to the primary key, that is, the latest data with primary key 200 is obtained.

[0118] Based on the incremental data in the second query result, the latest versions of the first and second query results are determined. Then, the first and second query results are merged to obtain the final query result.

[0119] It should be noted that when merging each incremental data in the second query result with the first query result, the query merging can be performed sequentially according to the time order of each specified operation recorded in the log.

[0120] based on Figure 1 The data query method shown constructs baseline logical row numbers corresponding to each primary key in the baseline data. During data writing, the incremental logical row number of the data to be operated on is determined based on the operation type, the primary key corresponding to the data being written, and the baseline logical row number. Then, when merging the baseline and incremental data during the data query, the queried data can be merged and output based on both the incremental and baseline logical row numbers. This eliminates the need to compare the primary keys of the queried baseline and incremental data one by one, reducing the time spent on primary key comparisons and improving the efficiency of data querying.

[0121] Furthermore, in step S108 above, when the server merges the query results based on the baseline logical row number corresponding to each data in the first query result and the incremental logical row number corresponding to each data in the second query result, the following method may also be used.

[0122] Specifically, the main incremental logical row numbers of the incremental data in the second query result are determined in ascending order. Following this order, for each incremental data in the second query result, based on its corresponding main incremental logical row number, the baseline data in the first query result whose baseline logical row numbers are not after the main incremental logical row numbers are identified as data to be updated. Then, based on the corresponding main incremental logical row number and the specified operation, the data to be updated is updated. The updated result, along with the remaining data in the first query result, is used as the new first query result. This process continues, iterating through the remaining incremental data in the second query result until all incremental data in the second query result has been traversed. Finally, the updated first query result is determined to be the merged query result.

[0123] In order to merge incremental data and baseline data, when updating the data to be updated based on the incremental logical row number and the specified operation corresponding to the data, the value of the incremental logical row number corresponding to the data must first be determined.

[0124] Specifically, when the incremental logical row number corresponding to the incremental data is a preset first value, check whether the primary key corresponding to the incremental data exists in the first query result.

[0125] If the data exists, and the specified operation corresponding to the incremental data is either modification or deletion, then the data to be updated is updated according to the specified operation and the incremental data to obtain the update result. If the data does not exist, and the specified operation corresponding to the incremental data is either modification or addition, then the incremental data from the second query result is inserted into the data to be updated to obtain the update result.

[0126] When the incremental logical row number corresponding to the incremental data is the preset third value, and the specified operation is either add or modify, the incremental data in the second query result is inserted into the tail of the data to be updated, and the update result is obtained.

[0127] When the incremental logical row number corresponding to the incremental data is a preset second value, the baseline data in the data to be updated that has the same primary key as the incremental data is updated according to the specified operation and the incremental data, and the update result is obtained.

[0128] After iterating through all the data in the second query result, that is, updating each piece of data in the second query result to the first query result in turn, the data in the first query result is the latest version of the data. Therefore, the updated first query result (updated result) is the final query result, and the final query result can be returned.

[0129] like Figure 4 The image shown is a schematic diagram illustrating a query result merging method provided in this specification. Figure 4In the first query result, we need to iterate through all the data in the second query result. The first operation adds data with a primary key of 50. Its incremental logical row number is "01" and its major incremental logical row number is 0. Since it doesn't correspond to any row in the baseline data, this data can be directly added to the first query result. In the second operation, which updates data with a primary key of 50, the first query result has already been updated based on the first operation, so the updated result will have a primary key of 50. Therefore, we can modify the data with the primary key of 50 accordingly. The third operation deletes data with a primary key of 200. Its incremental logical row number is "00", so its major incremental logical row number is accurate. This data can be directly deleted from the updated first query result. For the fourth operation, which updates data with a primary key of 600, since its incremental logical row number is 11, we need to check the first query result to determine if a primary key of 600 exists. The query result clearly shows that it does, so we can update the data with the primary key of 600 in the first query result according to this specified operation.

[0130] The final operation is to add data. The primary key of this added data is 800, and its incremental logical row number is 01. Therefore, we can first output the baseline data located at the main incremental logical row number (7) and all data before it as the data to be updated. Finally, we query the first query result. The primary key of the data with baseline logical row number 7 is inconsistent with the primary key of the added data. Therefore, this data can be directly written into the data to be updated. It can be seen that by updating the first query result with each data in the second query result according to the incremental logical row number, we can obtain the final query result. Figure 4 As shown in the final query results, the data corresponding to each primary key enclosed in dashed boxes are the final query results.

[0131] It should be noted that in one or more embodiments described herein, the baseline data and incremental data are arranged in order according to the primary key. Whether sorted in ascending or descending order by the primary key size, or by lexicographical order, the baseline logical row number is simply a number assigned to each primary key based on its sorting order. Therefore, the magnitude of the value corresponding to the primary key is not necessarily related to the magnitude of its corresponding baseline logical row number. In other words, the baseline logical row number corresponding to data with a larger primary key value may be larger than the baseline logical row number corresponding to data with a smaller primary key value. That is, the baseline logical row number corresponds to the relative position of each primary key.

[0132] Based on the data query method described above, this specification also provides a corresponding schematic diagram of a device for data query, as shown in the embodiments. Figure 5 As shown.

[0133] Figure 5This is a schematic diagram of a data query apparatus provided in an embodiment of this specification. The apparatus includes:

[0134] The receiving module 500 is used to receive a specified operation request to the database, and search for the primary key in the baseline data according to the primary key corresponding to the data to be operated carried in the specified operation request, and determine the specified operation query result.

[0135] The first determining module 502 is used to determine the baseline logical row number corresponding to the specified operation query result based on the specified operation query result and the specified operation request, and to determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number.

[0136] Storage module 504 is used to determine the correspondence between the data to be operated and the incremental logical row number, and to store the data as incremental data;

[0137] The query module 506 is used to, when a query request is received, determine a first query result in the baseline data within the query range and a second query result in the incremental data within the query range, based on the query range of the query request;

[0138] The second determining module 508 is used to merge the query results based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, and determine the final query result.

[0139] Optionally, the first determining module 502 is specifically used to determine that the specified operation query result is the primary key in the baseline data; if the specified operation request is an add, then a preset invalid identifier is determined as the baseline logical row number corresponding to the specified operation query result, the invalid identifier is used as the primary incremental logical row number corresponding to the data to be operated, and a preset first value is used as the secondary incremental logical row number corresponding to the data to be operated; if the specified operation request is a delete or modify, then the baseline logical row number corresponding to the primary key in the baseline data is determined as the baseline logical row number corresponding to the specified operation query result, the baseline logical row number is used as the primary incremental logical row number corresponding to the data to be operated, and a preset second value is used as the secondary incremental logical row number corresponding to the data to be operated.

[0140] Optionally, the first determining module 502 is specifically configured to, when the query result of the specified operation is empty, select, according to the sorting of the primary keys, the primary key sorted before the primary key corresponding to the data to be operated, from the primary keys of the baseline data as the candidate primary keys; determine the baseline logical row number corresponding to the primary key at the end of the sorting among the candidate primary keys as the baseline logical row number corresponding to the query result; use the baseline logical row number corresponding to the query result of the specified operation as the primary incremental logical row number corresponding to the data to be operated, and use the preset third value as the secondary incremental logical row number corresponding to the data to be operated.

[0141] Optionally, the first determining module 502 is further configured to, when the query result of the specified operation is abnormal, use a preset invalid identifier as the main incremental logical row number corresponding to the data to be operated, and use a preset first value as the secondary incremental logical row number corresponding to the data to be operated.

[0142] Optionally, the second determining module 508 is specifically configured to, for each incremental data in the second query result, if the incremental data corresponds to a sub-increment logical row number of the incremental data and is a preset first value, delete the incremental data; if the incremental data corresponds to a sub-increment logical row number of the incremental data and is a preset second value, perform the specified operation corresponding to the incremental data on the baseline data with the same main incremental logical row number in the first query result according to the main incremental logical row number corresponding to the incremental data, and determine the merged query result; if the incremental data corresponds to a sub-increment logical row number of the incremental data and is a preset third value, and the specified operation corresponding to the incremental data is add or modify, use the incremental data as the merged query result; if the incremental data corresponds to a sub-increment logical row number of the incremental data and is a preset third value, and the specified operation corresponding to the incremental data is delete, delete the incremental data.

[0143] Optionally, the second determining module 508 is further configured to, for each incremental data in the second query result, if the incremental logical row number corresponding to the incremental data is a preset first value, retrieve the primary key corresponding to the incremental data in the first query result; if the retrieved result contains the primary key and the specified operation corresponding to the incremental data is add, delete the incremental data; if the retrieved result contains the primary key and the specified operation corresponding to the incremental data is modify, update the baseline data corresponding to the retrieved result based on the incremental data to determine the merged query result; if the retrieved result contains the primary key and the specified operation corresponding to the incremental data is delete, delete the incremental data and the baseline data corresponding to the retrieved result; if the retrieved result does not contain the primary key and the specified operation corresponding to the incremental data is delete, delete the incremental data; if the retrieved result does not contain the primary key and the specified operation corresponding to the incremental data is modify or add, use the incremental data as data in the merged query result.

[0144] Optionally, the second determining module 508 is specifically used to determine, if the incremental logical row number corresponding to the incremental data is a preset third value, a baseline logical row number not greater than the main incremental logical row number according to the main incremental logical row number corresponding to the incremental data; and to insert the incremental data after the determined baseline data as the merged query result.

[0145] Optionally, the second determining module 508 is specifically used to determine the incremental data in the second query result that is not merged with the first query result as unmerged data; determine the incremental data with the same primary key in the unmerged data; merge the incremental data with the same primary key according to their corresponding specified operation to determine the merged data; and determine the final query result based on the data after merging the first query result and the second query result, and the merged data.

[0146] Optionally, the second determining module 508 is specifically used to determine the ascending order of the main incremental logical row numbers of the incremental data in the second query result; sequentially for each incremental data in the second query result according to the order, determine the baseline data in the first query result whose baseline logical row numbers are not after the main incremental logical row numbers, based on the main incremental logical row number corresponding to the incremental data, and use them as data to be updated; update the data to be updated according to the main incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data; use the updated result and the remaining data in the first query result as the first query result again, and continue to traverse the remaining incremental data in the second query result until all incremental data in the second query result have been traversed, and determine the updated first query result as the merged query result.

[0147] Optionally, the second determining module 508 is specifically used to check whether the primary key corresponding to the incremental data exists in the first query result when the incremental logical row number corresponding to the incremental data is a preset first value; if it exists, and the specified operation corresponding to the incremental data is one of modification or deletion, then the data to be updated is updated according to the specified operation and the incremental data to obtain an update result; if it does not exist, and the specified operation corresponding to the incremental data is one of modification or addition, then the incremental data in the second query result is inserted into the data to be updated to obtain an update result.

[0148] Optionally, the second determining module 508 is specifically used to insert the incremental data in the second query result into the tail of the data to be updated when the incremental logical row number corresponding to the incremental data is a preset third value and the specified operation is either addition or modification, so as to obtain the update result.

[0149] Optionally, the second determining module 508 is specifically used to update the baseline data in the data to be updated that has the same primary key as the incremental data, according to the specified operation and the incremental data, when the incremental logical row number corresponding to the incremental data is a preset second value, so as to obtain the update result.

[0150] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the data query method described above.

[0151] Based on the data query method described above, the embodiments of this specification also propose... Figure 6 The diagram shows a schematic structural representation of the electronic device. Figure 6 At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the data query method described above.

[0152] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0153] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages ​​and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.

[0154] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0155] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.

[0156] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware.

[0157] Those skilled in the art will understand that embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0158] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0159] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0160] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0161] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0162] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0163] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0164] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0165] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0166] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0167] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0168] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.

Claims

1. A method for data querying, wherein baseline data stored in a database is configured with baseline logical row numbers, and each primary key in the baseline data corresponds one-to-one with a baseline logical row number, the method comprising: Receive a specified operation request for the database, and search for the primary key in the baseline data according to the primary key corresponding to the data to be operated carried in the specified operation request to determine the query result of the specified operation; Based on the specified operation query result and the specified operation request, determine the baseline logical row number corresponding to the specified operation query result, and determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number; Determine the correspondence between the data to be operated on and the incremental logical row number, and store it as incremental data; When a query request is received, based on the query scope of the query request, a first query result in the baseline data within the query scope and a second query result in the incremental data within the query scope are determined. Based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, the query results are merged to determine the final query result.

2. The method as described in claim 1, wherein the baseline logical row number corresponding to the specified operation query result is determined based on the specified operation query result and the specified operation request, and the incremental logical row number corresponding to the data to be operated is determined based on the baseline logical row number, specifically including: The query result of the specified operation is determined to be the primary key in the baseline data; If the specified operation request is to add, then the preset invalid identifier is determined as the baseline logical row number corresponding to the specified operation query result, the invalid identifier is used as the main incremental logical row number corresponding to the data to be operated, and the preset first value is used as the secondary incremental logical row number corresponding to the data to be operated. If the specified operation request is either deletion or modification, then the baseline logical row number corresponding to the primary key in the baseline data is determined to be the baseline logical row number corresponding to the specified operation query result. The baseline logical row number is used as the primary incremental logical row number corresponding to the data to be operated on, and the preset second value is used as the secondary incremental logical row number corresponding to the data to be operated on.

3. The method as described in claim 1, wherein the baseline logical row number corresponding to the specified operation query result is determined based on the specified operation query result and the specified operation request, and the incremental logical row number corresponding to the data to be operated is determined based on the baseline logical row number, specifically including: When the query result of the specified operation is empty, the primary key that is sorted before the primary key corresponding to the data to be operated on is selected from the primary keys of the baseline data according to the primary key sorting and is used as the candidate primary key; Determine the baseline logical row number corresponding to the last primary key in the sorting of each candidate primary key, and use it as the baseline logical row number corresponding to the query result; The baseline logical row number corresponding to the query result of the specified operation is used as the primary incremental logical row number corresponding to the data to be operated, and the preset third value is used as the secondary incremental logical row number corresponding to the data to be operated.

4. The method of claim 1, further comprising: When the query result of the specified operation is abnormal, the preset invalid identifier is used as the main incremental logical row number corresponding to the data to be operated, and the preset first value is used as the secondary incremental logical row number corresponding to the data to be operated.

5. The method as described in any one of claims 2 to 4, wherein the query results are merged based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, specifically including: For each incremental data in the second query result, if the incremental logical row number corresponding to the incremental data is a preset first value, then the incremental data is deleted. If the incremental logical row number corresponding to the incremental data is a preset second value, then according to the main incremental logical row number corresponding to the incremental data, the specified operation corresponding to the incremental data is performed on the baseline data with the same main incremental logical row number in the first query result to determine the merged query result; If the incremental data corresponds to the third preset logical row number, and the specified operation corresponding to the incremental data is add or modify, then the incremental data will be used as the merged query result. If the incremental logical row number corresponding to the incremental data is the preset third value, and the specified operation corresponding to the incremental data is deletion, then the incremental data is deleted.

6. The method of claim 5, further comprising: For each incremental data in the second query result, if the incremental logical row number corresponding to the incremental data is a preset first value, then the primary key corresponding to the incremental data is retrieved in the first query result. If the primary key exists in the lookup result and the specified operation corresponding to the incremental data is "add", then delete the incremental data. If the primary key exists in the lookup result and the specified operation corresponding to the incremental data is modification, the baseline data corresponding to the lookup result is updated according to the incremental data to determine the merged query result; If the primary key exists in the lookup result, and the specified operation corresponding to the incremental data is deletion, delete the incremental data and the baseline data corresponding to the lookup result; If the primary key does not exist in the lookup result, and the specified operation corresponding to the incremental data is deletion, then delete the incremental data. If the primary key does not exist in the lookup result, and the specified operation corresponding to the incremental data is modification or addition, the incremental data will be included in the merged query result.

7. The method as described in claim 5, wherein if the incremental logical row number corresponding to the incremental data is a preset third value, and the specified operation corresponding to the incremental data is add or modify, the incremental data is used as the merged query result, specifically including: If the incremental logical row number corresponding to the incremental data is a preset third value, the baseline logical row number is determined to be no greater than the baseline data of the main incremental logical row number based on the main incremental logical row number corresponding to the incremental data. The incremental data is inserted after the determined baseline data and used as the result of the merged query.

8. The method described in claim 5, specifically including merging query results, includes: The incremental data in the second query result that is not merged with the first query result is identified as unmerged data. Identify incremental data with the same primary key among the unmerged data; The incremental data with the same primary key are merged according to their respective specified operations to determine the merged data; The final query result is determined based on the data obtained by merging the first query result and the second query result, as well as the merged data.

9. The method as described in any one of claims 2 to 4, wherein the query results are merged based on the baseline logical row number corresponding to each data in the first query result and the incremental logical row number corresponding to each data in the second query result, specifically including: Determine the ascending order of the main incremental logical row numbers of the incremental data in the second query result; In the order described above, for each incremental data in the second query result, based on the main incremental logical row number corresponding to the incremental data, determine each baseline data in the first query result whose baseline logical row number is not after the main incremental logical row number, and take it as the data to be updated. Based on the main incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data, the data to be updated is updated. The update result and the remaining data in the first query result are used as the first query result again. The remaining incremental data in the second query result are traversed until all incremental data in the second query result are traversed. Then, the updated first query result is determined to be the merged query result.

10. The method as described in claim 9, wherein updating the data to be updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data specifically includes: When the incremental logical row number corresponding to the incremental data is a preset first value, check back whether the primary key corresponding to the incremental data exists in the first query result; If it exists, and the specified operation corresponding to the incremental data is either modification or deletion, then the data to be updated is updated according to the specified operation and the incremental data to obtain the update result; If the data does not exist, and the specified operation corresponding to the incremental data is either modification or addition, then the incremental data in the second query result is inserted into the data to be updated to obtain the update result.

11. The method as described in claim 9, wherein updating the data to be updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data specifically includes: When the incremental logical row number corresponding to the incremental data is a preset third value, and the specified operation is either an add or a modify operation, the incremental data in the second query result is inserted into the tail of the data to be updated to obtain the update result.

12. The method as described in claim 9, wherein updating the data to be updated according to the incremental logical row number corresponding to the incremental data and the specified operation corresponding to the incremental data specifically includes: When the incremental logical row number corresponding to the incremental data is a preset second value, the baseline data in the data to be updated that has the same primary key as the incremental data is updated according to the specified operation and the incremental data, and the update result is obtained.

13. A data query apparatus, wherein baseline data stored in a database is configured with baseline logical row numbers, and each primary key in the baseline data corresponds one-to-one with a baseline logical row number, the apparatus comprising: The receiving module is used to receive a specified operation request to the database, and according to the primary key corresponding to the data to be operated carried in the specified operation request, search for the primary key in the baseline data to determine the specified operation query result. The first determining module is used to determine the baseline logical row number corresponding to the specified operation query result based on the specified operation query result and the specified operation request, and to determine the incremental logical row number corresponding to the data to be operated based on the baseline logical row number. The storage module is used to determine the correspondence between the data to be operated on and the incremental logical row number, and to store the data as incremental data; The query module is used to, when a query request is received, determine a first query result in the baseline data within the query range and a second query result in the incremental data within the query range, based on the query range of the query request. The second determining module is used to merge the query results based on the baseline logical row number corresponding to each baseline data in the first query result and the incremental logical row number corresponding to each incremental data in the second query result, and determine the final query result.

14. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1-12.

15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method according to any one of claims 1-12.

Citation Information

Patent Citations

  • Method for querying data

    CN108427736A

  • Database table scanning method, device and equipment

    CN115563116A