Data query method, computer equipment and program product
By obtaining the target business query identifier, the data storage location can be directly determined, solving the problems of slow data query speed and poor stability in high-concurrency scenarios, realizing fast and accurate data query, and enhancing the reliability and observability of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-14
AI Technical Summary
In high-concurrency scenarios, existing data query methods suffer from slow query speed and poor stability. In particular, in distributed systems, routing lookup methods and cache mapping schemes cannot effectively solve the problems of query speed and stability under high concurrency.
By obtaining the target business query identifier, including the user identifier and the business identifier, the target storage location of the data can be directly determined, avoiding access to the centralized routing service. The multi-shard key priority link routing strategy and short-circuit strategy are adopted to quickly and accurately determine the data storage location.
It improves the speed and stability of data queries, ensuring the speed and accuracy of data queries in high-concurrency scenarios, reducing additional input/output latency and database pressure, and enhancing the reliability and observability of the system.
Smart Images

Figure CN121858563A_ABST
Abstract
Description
Technical Field
[0001] This application relates to data transmission technology, including but not limited to a data query method, computer equipment, and program products. Background Technology
[0002] In the process of querying data, the solution typically used in related technologies is the route lookup table method.
[0003] This method requires first accessing a centralized routing service to obtain the storage location through a mapping table, and then accessing the storage location. This results in additional input / output and latency, which may lead to slow query speeds and poor stability when querying data in high-concurrency scenarios. Summary of the Invention
[0004] In view of this, the data query method, computer device, and program product provided in this application embodiment can realize data query in high-concurrency scenarios, ensuring the speed and stability of data query. The data query method, computer device, and program product provided in this application embodiment are implemented as follows: One aspect of this application provides a data query method, including: The first query request to obtain the first data includes a target business query identifier, which includes one or more of a plurality of identifiers, including: user identifier and business identifier; The target storage location of the first data is determined based on the target business query identifier; Retrieve the first data from the target storage location.
[0005] Another aspect of this application embodiment also provides a data query device, including: an acquisition module, a determination module, and a query module; The acquisition module is used to acquire a first query request for first data. The first query request includes a target business query identifier, which includes one or more of a plurality of identifiers, including a user identifier and a business identifier. The determination module is used to determine the target storage location of the first data based on the target business query identifier; The query module is used to retrieve the first data from the target storage location.
[0006] The computer device provided in this application includes a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the program to implement the method of this application.
[0007] The computer-readable storage medium provided in this application embodiment stores a computer program thereon, which, when executed by a processor, implements the method provided in this application embodiment.
[0008] The computer program product provided in this application includes a computer program that, when executed by a processor, implements the method provided in this application.
[0009] The data query method, computer device, and program product provided in this application embodiment can obtain a first query request for first data. The first query request includes a target business query identifier, which includes any one or more of a plurality of identifiers, including a user identifier and a business identifier. The method determines the target storage location of the first data based on the target business query identifier and queries the first data in the target storage location. Specifically, the target storage location of the first data can be quickly and directly determined through the business query identifier. This allows for rapid and accurate determination of the target storage location of the first data without accessing a centralized routing service, thereby improving the query speed for the first data. Furthermore, since there is no additional input / output latency during the access process, the stability of the data query is also improved, thus enabling data querying in high-concurrency scenarios and ensuring both speed and stability of the data query. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a schematic diagram illustrating the application scenarios provided in the embodiments of this application; Figure 2 This is a flowchart illustrating the data query method provided in the embodiments of this application; Figure 3 This is another flowchart illustrating the data query method provided in the embodiments of this application; Figure 4 This is another flowchart illustrating the data query method provided in the embodiments of this application; Figure 5 This is a logical diagram illustrating the target storage location for obtaining the first data as provided in an embodiment of this application. Figure 6 This is another logical diagram illustrating the target storage location for obtaining the first data provided in this embodiment of the application. Figure 7This is a schematic diagram of the abnormal data detection process provided in the embodiments of this application; Figure 8 This is a schematic diagram of the data writing process provided in the embodiments of this application; Figure 9 This is a flowchart illustrating the process of determining the storage location of the second data after data expansion, as provided in the embodiments of this application. Figure 10 This is a schematic diagram illustrating the process of determining the storage location of the first data after data expansion, as provided in the embodiments of this application. Figure 11 This is a schematic diagram of the data query device provided in the embodiments of this application; Figure 12 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0012] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.
[0013] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0014] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0015] It should be noted that the terms "first, second, third" used in the embodiments of this application are used to distinguish similar or different objects and do not represent a specific order of objects. It can be understood that "first, second, third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0016] In some business scenarios, such as distributed payment systems, during transaction exponentiation verification, callback notifications, or event handling, data from multiple sources may be involved in querying data stored in the database, which can lead to high concurrency.
[0017] The data query schemes used in related technologies typically employ a route-based lookup method. For example, a separate routing service is established to store a mapping table of "shard keys and shard numbers." Business requests first query this service to obtain the target table, and then operate on the database. However, this method involves additional network input and output, which increases latency. In high-concurrency scenarios, it may result in slow query speeds and poor stability.
[0018] Another possible approach is to use a cache mapping scheme, such as maintaining a mapping relationship between table partition numbers in the cache and querying the cache first when querying data. However, this approach can cause a surge in database pressure when the cache is missed, potentially leading to data inconsistency and other errors. It still cannot solve the problems of slow query speed and poor stability in high-concurrency scenarios.
[0019] To address the aforementioned problems in related technologies, this application provides a data query method, computer device, and program product. The following explains the application scenarios of this data query method and its implementation within those scenarios.
[0020] Figure 1 This is a schematic diagram illustrating the application scenario provided in the embodiments of this application. Please refer to... Figure 1 In this scenario, the system may include a server 110 and multiple electronic devices 120. The server 110 may be a computer device with a database located in the cloud. The server 110 may interact with the multiple electronic devices 120. In some scenarios, there may be a process where the electronic device 120 needs to query the relevant information of a certain data. In this process, the electronic device 120 will send a relevant request to the server 110. The server 110 will find the location of the data storage according to the request and can feed back the information related to the data to the electronic device 120.
[0021] The electronic device 120 may include, but is not limited to, mobile phones, wearable devices (such as smartwatches, smart bracelets, smart glasses, etc.), tablet computers, laptops, in-vehicle terminals, PCs (Personal Computers), etc. The functions implemented by this method can be achieved by the processor in the electronic device calling program code. Of course, the program code can be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.
[0022] In the above process, if multiple electronic devices 120 query the same server 110 for a period of time, it is a high-concurrency scenario. For example, if 1 million electronic devices query the server at the same time, the data query method provided in this application embodiment can be used to ensure the accuracy and timeliness of the data query.
[0023] The following section will explain one feasible implementation process of the data query method provided in the embodiments of this application, based on the above application scenarios.
[0024] Figure 2 This is a flowchart illustrating the data query method provided in the embodiments of this application. Please refer to it. Figure 2 Data query methods include: S210: First query request to obtain the first data.
[0025] It should be noted that the execution entity of this method can be the aforementioned server, which can be a computer device capable of communicating and connecting with multiple electronic devices, i.e., as shown above. Figure 1 The communication is implemented in the manner shown.
[0026] The first piece of data can be any data stored in the database on the server.
[0027] Optionally, the server's database may include multiple storage areas. When performing a data query, the storage location of the first data can be determined first, that is, which storage area of the database the first data is stored in, so that the data can be queried in the corresponding storage location.
[0028] In one embodiment, the data in the database can be stored in the form of tables. For multiple storage areas, that is, multiple sub-tables in the table, the storage location of the first data is the sub-table number of the table. After determining the sub-table number of the table, the data can be queried in the corresponding sub-table.
[0029] The first query request includes a target business query identifier, which includes one or more of a plurality of identifiers, including: user identifier and business identifier.
[0030] It should be noted that the first query request can be a request sent to the server by any electronic device. The query request can carry a corresponding target business query identifier, which can be, for example, a key value, and the first data can be queried through the specific result of the key value.
[0031] The target business query identifier can have one identifier or multiple identifiers; if there is only one specific identifier, the identifier can be any of the above-mentioned identifiers, such as user identifier, business identifier, or other types of custom identifiers, without specific restrictions here.
[0032] If multiple identifiers are included, these identifiers can be combined in any way, for example, including both user identifiers and business identifiers.
[0033] The user identifier can be determined based on the device identifier of the electronic device transmitting the first query request, or it can be determined based on the virtual identifier of the virtual account logged in on the electronic device. No specific restrictions are imposed, and any identifier method can be used as the user identifier. In a table partitioning scenario, the user identifier is typically used as the primary shard key, such as user_id.
[0034] The business identifier can be an identifier generated based on the corresponding business. For example, in a transaction scenario, a transaction identifier, order number identifier, or payment account identifier can be used as the business identifier. Alternatively, it can be an identifier obtained based on any one or more of the above identifiers, or it can be a custom identifier; no specific restrictions are placed here. In a table partitioning scenario, the business identifier typically refers to an ID generated by the system that uniquely identifies a business record, such as transaction_id. The key to this solution is that routing information is embedded in the business identifier during its generation.
[0035] For example, the first query request may include: a first query request carrying a user identifier, a first query request carrying a business identifier, a first query request carrying other custom identifiers, a first query request carrying both a user identifier and a business identifier, a first query request carrying both a user identifier and other custom identifiers, a first query request carrying both a business identifier and other custom identifiers, and a first query request carrying a user identifier, a business identifier, and other custom identifiers.
[0036] S220: Determine the target storage location of the first data based on the target business query identifier.
[0037] It should be noted that after obtaining the first query request for the first data, the target storage location of the first data can be determined based on the target business query identifier.
[0038] For different types of identifiers, the target storage location of the first data can be determined by the corresponding calculation method.
[0039] As explained above, the target storage location can be a sub-table number. That is to say, the specific sub-table number can be calculated based on the fields in the identifier using a preset calculation formula, thereby obtaining the target storage location of the first data.
[0040] S230: Query the first data in the target storage location.
[0041] It should be noted that after determining the target storage location, the first data can be queried by accessing the target storage location. For example, the entire content of the first data can be read, or a portion of the first data can be read. There are no specific restrictions here, and the appropriate method can be adopted according to the actual query requirements.
[0042] In one embodiment, if the target storage location is a sub-table number, the first data can be queried from the corresponding sub-table after the sub-table number is determined.
[0043] The data query method provided in this application embodiment can obtain a first query request for first data. The first query request includes a target business query identifier, which includes any one or more of multiple identifiers, including user identifiers and business identifiers. The target storage location of the first data is determined based on the target business query identifier. The first data is then queried from the target storage location. The business query identifier allows for quick and direct determination of the target storage location of the first data. This enables rapid and accurate determination of the target storage location of the first data without accessing a centralized routing service, thereby improving the query speed. Furthermore, since there is no additional input / output latency during the access process, the stability of the data query is also improved, thus enabling data querying in high-concurrency scenarios and ensuring both speed and stability of the data query.
[0044] It should be noted that, as explained above, the target business query identifier can include any one identifier or any number of identifiers. In the case of one identifier and multiple identifiers, different methods can be used to determine the target storage location.
[0045] The following explains another feasible implementation of the data query method provided in the embodiments of this application.
[0046] Figure 3 This is another flowchart illustrating the data query method provided in this application embodiment. Please refer to [link / reference]. Figure 3 The target storage location of the first data is determined based on the target business query identifier, including: S310: If the target business query identifier includes any one of the identifiers, determine the target storage location of the first data based on the method corresponding to the target business query identifier.
[0047] Optionally, the target business query identifier may include a user identifier or a business identifier.
[0048] In cases where the target business query identifier includes a user identifier, the corresponding sub-table number of the first data can be determined based on a preset calculation formula for the user identifier, thereby determining the target storage location of the first data.
[0049] When the target business query identifier includes a business identifier, the corresponding sub-table number of the first data can be determined based on the preset calculation formula of the business identifier, thereby determining the target storage location of the first data.
[0050] The data query method provided in this application embodiment can determine the target storage location of the first data based on the method corresponding to the target business query identifier, even when the target business query identifier includes any one of the identifiers. Different methods can be used to determine the target storage location of the first data for different identifiers. This improves the applicability of data querying, as it allows for data querying for query requests containing different identifiers.
[0051] The following explains another feasible implementation of the data query method provided in the embodiments of this application.
[0052] Figure 4 This is another flowchart illustrating the data query method provided in the embodiments of this application. Please refer to [link / reference]. Figure 4 The target storage location of the first data is determined based on the target business query identifier, including: S410: When the target business query identifier includes any number of identifiers, the target storage location of the first data is determined based on the target business query identifier with the highest priority among the multiple identifiers, according to the priority order of the multiple identifiers.
[0053] It should be noted that when the target business query identifier includes any number of identifiers, the priority order of these identifiers can be determined before determining the target storage location of the first data. For example, the priority of the user identifier can be set to be higher than that of the business identifier, and the priority of the business identifier can be set to be higher than that of other custom identifiers.
[0054] Specifically, a configurable priority chain can be defined, for example: user identifier → business identifier → other identifiers. When processing queries, the system attempts to perform route calculations using the keys in the request one by one, following the order of this chain. This approach can be called "multi-shard key priority chain routing".
[0055] In the process of determining the target storage location, the target storage location can be calculated first based on the identifier with the highest priority. For example, if the priority order is as described above, the corresponding table number of the first data can be determined based on the user identifier and the preset calculation formula of the user identifier, thereby determining the target storage location of the first data.
[0056] Correspondingly, if the target business query identifier does not include the user identifier, the corresponding table number of the first data can be determined based on the business identifier and the preset calculation formula of the business identifier, thereby determining the target storage location of the first data.
[0057] In one embodiment, once the target storage location is determined, a hit-and-return strategy can be adopted. That is, after determining the target storage location using any identifier, the target storage location can be returned, and data queries can be performed based on that location, without needing to query based on other identifiers. This reduces query power consumption and improves query efficiency. This strategy is known as the "hit-and-return" or "short-circuit" strategy, which guarantees that in most cases (data is normal and the query request carries at least one valid key), routing can be completed on the first attempt, achieving constant time complexity.
[0058] In one embodiment, if the highest priority identifier cannot determine the target storage location, the target storage location can be determined based on the second highest priority identifier; if none of the identifiers can determine the target storage location, a fallback process can be initiated, such as by throwing an error, issuing an operation and maintenance alarm, or performing a read-only cross-table operation to return the information to the corresponding electronic device.
[0059] The data query method provided in this application embodiment can determine the target storage location of the first data based on the highest priority target business query identifier among the multiple identifiers, even when the target business query identifier includes any number of identifiers. Specifically, when multiple identifiers exist, a priority order can be set, and the corresponding identifier can be selected according to the priority order to determine the target storage location of the first data. This improves the efficiency of determining the target storage location, thereby enabling accurate and rapid determination of the target storage location of the first data.
[0060] It should be noted that, regardless of the method used Figure 3 The diagram shows whether the target storage location of the first data is determined based on any one identifier, or by using... Figure 4 The method shown involves determining the target storage location of the first data based on any number of identifiers. In practice, the target storage location of the first data will be determined based on either the user identifier or the business identifier.
[0061] The following explains the implementation process of determining the target storage location of the first data based on the user identifier provided in the embodiments of this application.
[0062] Figure 5 This is a logical diagram illustrating the acquisition of the target storage location of the first data provided in this embodiment of the application. Please refer to... Figure 5In one embodiment, when the target service query identifier is a user identifier, determining the target storage location of the first data based on the target service query identifier includes: determining the target storage location of the first data based on the hash calculation value of the user identifier and the maximum index information.
[0063] It should be noted that the formula for calculating the target storage location of the first data based on the user identifier is as follows: TableNo = hash(user_id)&MaxIndex; Here, TableNo is the target storage location for the first data, which can be a table number; user_id can be the user identifier, and hash(user_id) can be the hash value of the user identifier; MaxIndex can be the maximum index information, where the value of MaxIndex is 2^k. 1. It can be configured by the server's database configuration center. k is the mask value, which is a positive integer, for example, it can be 7.
[0064] The maximum index information, MaxIndex, represents the number of available storage areas in the database. Each storage area can have a corresponding storage location. For example, when the storage location is represented by a table partition number, the storage area can be a specific table partition. When k is 7, the maximum index information is 128 (indicating that its value is between 0 and 127); when k is 8, the maximum index information is 256 (indicating that its value is between 0 and 255).
[0065] MaxIndex, a core configuration parameter, has a value of 2^k - 1 (where k is a positive integer), and it is essentially a bitmask. This design allows for efficient and even distribution of data across (2^k) partitions when performing bitwise AND (&) operations on hash values. Furthermore, setting the total number of partitions to a power of 2 (2^k) lays the foundation for smooth subsequent expansion, as expansion only requires increasing the value of k by 1 (e.g., expanding from k=7 to k=8), effectively doubling the number of partitions without modifying the complex hash algorithm.
[0066] In this case, if the value of k is small (e.g., k=6, 64 tables), management is simple, but the data volume of a single table grows rapidly, potentially requiring frequent expansion. If the value of k is large (e.g., k=10, 1024 tables), the data is distributed more finely, but the number of tables is large, increasing the complexity of operation and maintenance. In actual implementation, an appropriate value of k can be selected for table partitioning based on actual needs.
[0067] After receiving the first query instruction, if the location is determined based on the user identifier, the target storage location TableNo, such as a specific sub-table number, can be calculated based on the above formula. This allows us to determine the corresponding storage area of the first data in the database, thereby enabling the query of the first data.
[0068] It should be noted that during the data storage process, the above calculation formula can be used to determine the storage location of each piece of data. Then, during the data query process, the storage location of each piece of data can be determined according to the calculation formula, thereby realizing the query or retrieval of data.
[0069] In the data query method provided in this application embodiment, the target storage location of the first data can be determined based on the hash calculation value of the user identifier and the maximum index information. Since the target storage location can be calculated and determined based on the above method during the storage process of the first data, the result calculated in this way has high accuracy when the maximum index information remains unchanged, thus ensuring the accuracy of data query based on the user identifier.
[0070] The following explains the implementation process of determining the target storage location of the first data based on the business identifier provided in the embodiments of this application.
[0071] Figure 6 For another logical diagram illustrating the target storage location for obtaining the first data provided in this embodiment, please refer to... Figure 6 In one embodiment, when the target business query identifier is a business identifier, determining the target storage location of the first data based on the target business query identifier includes: determining the target storage location of the first data according to a preset field of the business identifier.
[0072] It should be noted that the formula for calculating the target storage location of the first data based on the business identifier is as follows: TableNo = parseSuffix(last n digits); Here, last n digits refers to the last n characters. For example, if n is 3, it means the last 3 characters. parseSuffix(last n digits) means to take the last n characters. For example, if a field is 1234, which has four characters, and n is 3, taking the last 3 characters will give the string "234".
[0073] It should be noted that "last n digits" refers to the preset field mentioned above. In this formula, the preset field is the field composed of the last three characters.
[0074] The value of n can be related to the maximum index information. For example, if the maximum index information is 256, it can be determined to be a three-digit number, and the value of n can be set to 3. If the maximum index information is 1024, it can be determined to be a four-digit number, and the value of n can be set to 4. If the maximum index information is 64, it can be determined to be a two-digit number, and the value of n can be set to 2.
[0075] In practice, the table storing the first data can be divided into multiple sub-tables according to the actual needs of the sub-tables, and then the value of n can be adjusted according to the number of multiple sub-tables.
[0076] It should be noted that during the data storage process, after determining the storage location of a data, the business identifier corresponding to the data can be calculated according to certain preset rules. For example, certain characters of the business identifier can be set as the table number. For example, if the last three characters are set as the table number, then when performing data query, the formula above can be n=3, and the last three characters can be taken to obtain the table number, thereby determining the target storage location.
[0077] In addition to setting the last few digits, you can also set the first few digits, the middle few digits as the sub-table number, or other characters used by the user to calculate the sub-table number. There are no specific restrictions here. If the corresponding method is used here, the string taken in the above formula can also be adjusted accordingly to obtain the sub-table number, thereby determining the target storage location.
[0078] In the data query method provided in this application embodiment, the target storage location of the first data can be determined based on a preset field of the business identifier. The business identifier can be calculated during data writing. During the data writing process, the target storage location can be written into the preset field of the business identifier. The target storage location can be obtained through this preset field. This method enables fast and accurate determination of the target storage location of the first data. Furthermore, since the content corresponding to the preset field is the target storage location, even if storage expansion occurs, the target storage location of the first data can still be accurately determined using this method, ensuring data security.
[0079] The following explains one feasible implementation process for detecting abnormal data provided in the embodiments of this application.
[0080] Figure 7 This is a schematic diagram of the abnormal data detection process provided in the embodiments of this application. Please refer to it. Figure 7 When the target business query identifier includes any number of identifiers, the method further includes: S710: Calculates multiple storage locations corresponding to multiple identifiers.
[0081] It should be noted that when the target business query identifier includes any number of identifiers, there may be data anomalies. To avoid this, an anomaly data detection process can be performed.
[0082] During anomaly detection, multiple storage locations can be calculated based on multiple identifiers. For example, storage location A can be calculated based on the user identifier, and storage location B can be calculated based on the business identifier.
[0083] Correspondingly, if there are other identifiers, such as other custom identifiers, the storage location C can also be calculated based on the custom identifier.
[0084] After calculating multiple storage locations, it can be determined whether these storage locations are the same location. If all locations are the same, it can be determined that the first data is normal data and there is no abnormality.
[0085] S720: Generates an alarm message if any two storage locations differ from each other in a set of multiple storage locations.
[0086] It should be noted that in the process of determining whether multiple storage locations are the same, if the storage locations calculated by any two methods for the same data are different, it can be determined that the first data may be abnormal. For example, the storage location may have been calculated incorrectly during the storage process, or the business identifier may have been calculated incorrectly, and an alarm message can be generated.
[0087] The alarm information is used to indicate that the first data is abnormal.
[0088] For example: Suppose a piece of data, `user_id`, is calculated using the formula `hash(user_id) & MaxIndex` and should reside in table `table_023`. However, the last three digits of its business identifier, `transaction_id`, are parsed to be 045, pointing to table `table_045`. The system, by comparing these values, finds that 023 is not equal to 045, and thus determines that there is an anomaly in the data or the query (this could be due to a routing calculation error during data writing or tampering with the query request), triggering an alert. This establishes a built-in consistency verification mechanism based on the data itself, improving the system's reliability and observability.
[0089] It should be noted that after determining that the first data is abnormal, the server can send feedback information to the electronic device that sent the corresponding first query request, informing that the first data is abnormal and cannot be read normally. Alternatively, the server can perform a database check itself to determine if there were any anomalies in the data writing process, ensuring data accuracy.
[0090] The data query method provided in this application embodiment can calculate multiple storage locations corresponding to multiple identifiers; if any two storage locations differ, an alarm message is generated. By verifying multiple storage locations, the accuracy of the obtained storage locations can be guaranteed. Furthermore, in the case of differing storage locations, generating an alarm message instructs the server to perform a storage self-check, thereby preventing abnormal data writing and improving the accuracy of data query and storage.
[0091] The user identifier and business identifier used in the data query process explained above can both be used or generated during the data writing process. The following explains one feasible implementation process of data writing in the data query method provided in this application embodiment.
[0092] Figure 8 This is a schematic diagram of the data writing process provided in the embodiments of this application. Please refer to it. Figure 8 Before the first query request to obtain the first data, the method also includes: S810: Get the first data to be stored.
[0093] It should be noted that before storing the first data, the server can first obtain the first data. The first data can be sent by other electronic devices and then received by the server, or it can be generated by the server itself. The first data can be stored in the server's database.
[0094] S820: Determine the target storage location of the first data based on the user identifier and maximum index information of the first data.
[0095] During the process of storing the first data into the server's database, the user identifier of the first data can be obtained. This user identifier can be an identifier defined by the server, or it can be an identifier carried by the first data itself. No specific restrictions are made here. In this embodiment, the identifier carried by the first data itself is used as an example for explanation.
[0096] The maximum index information is used to indicate the upper limit of the number of storable locations for the first data.
[0097] The maximum index information can be obtained by configuring the server's database configuration center; for example, it could be a maximum partition number.
[0098] After obtaining the user identifier and maximum index information of the first data, the target storage location TableNo can be calculated according to the above calculation formula: TableNo = hash(user_id)&MaxIndex.
[0099] S830: Generate a service identifier based on the random identifier and the target storage location, and store the first data in the target storage location.
[0100] It should be noted that before storing the first data in the target storage location, the business identifier corresponding to the first data can be calculated first.
[0101] The business identifier can consist of two parts. The first part can be a random identifier, for example, a random number can be generated by the snowflake algorithm and used as the random identifier. The second part can be the target storage location, which is a table number.
[0102] Assuming the business identifier field contains 7 characters, the first 4 characters can be the aforementioned random identifier, which is a generated four-digit random number, such as 5678, and the last 3 characters can be the aforementioned target storage location, which is a table partition number, such as 255 (representing the 256th partition).
[0103] In other words, the field of this business identifier can be 5678255, where the first 4 fields are random identifiers and the last 3 fields are the target storage location.
[0104] More specifically, the generation of a business identifier (such as transaction_id) can be described as: TransactionID = SnowflakeID + format(TableNo, “%03d”). Here, the SnowflakeID part provides global uniqueness, and the format(TableNo, “%03d”) part formats the calculated table number (e.g., 23) into a three-digit string (“023”) and appends it. This generates a business identifier that guarantees global uniqueness while also containing precise routing information.
[0105] After generating the business identifier using the above method, the first data can be stored in the target storage location.
[0106] During the subsequent data reading process, if the calculation is based on the user identifier, the corresponding target storage location can be determined according to the corresponding calculation formula. If the calculation is based on the business identifier, the field consisting of the last three characters of the business identifier can be used as the determined target storage location.
[0107] The data query method provided in this application embodiment can obtain first data to be stored; determine the target storage location of the first data based on the user identifier and maximum index information of the first data; generate a business identifier based on a random identifier and the target storage location; and store the first data in the target storage location. Specifically, during the writing process of the first data, the target storage location can be calculated using the user identifier and maximum index information, ensuring that the calculation method used in data writing and data querying is the same, which can improve the accuracy of data querying. Furthermore, during the data writing process, the business identifier is generated based on the random identifier and the target storage location. The random identifier ensures the identifier is non-repeating, and the target storage location ensures that the target storage location can be accurately obtained through the business identifier, thereby further improving the speed and accuracy of data querying.
[0108] In actual implementation, there may be situations where it is necessary to expand the database. If expansion is carried out, the storage area will increase. In this case, the storage location of the data will change. The following explains one feasible implementation process for data query after data expansion.
[0109] Figure 9 For a flowchart illustrating the process of determining the storage location of the second data after data expansion as provided in this application embodiment, please refer to... Figure 9 After storing the first data in the target storage location, the method further includes: S910: In response to an expansion command for a storage location, update the maximum index information.
[0110] The storage location expansion command can be an automatically generated command when the amount of data stored in the database reaches a certain threshold and expansion is required, or it can be a command initiated by the user when expansion is needed. There are no specific restrictions here, and the storage location expansion command can be generated in any way according to actual needs.
[0111] After generating an expansion command for a storage location, the number of storage areas in the database can be increased in response to the expansion command for that storage location, and the maximum index information will also be increased accordingly.
[0112] For example: when k is 7, the maximum index information is 128; if expansion is needed, k can be changed to 8, and the maximum index information is 256.
[0113] In other words, the expansion can be achieved by updating the mask k, which can double the amount of storage space. Correspondingly, the maximum index information can be updated, thus doubling the maximum index information as well.
[0114] S920: Obtain the second query request for the second data.
[0115] The second query request includes the user identifier corresponding to the second data, which is the data stored after the expansion instruction.
[0116] It should be noted that the aforementioned first data is the data stored before the expansion instruction, and the aforementioned second data is the data stored after the expansion instruction.
[0117] For this second data, during the query process, a query can be performed based on a second query request, which may include a user identifier.
[0118] S930: Determine the storage location of the second data based on the user identifier corresponding to the second data and the updated maximum index information.
[0119] It should be noted that after obtaining the user identifier corresponding to the second data, the storage location of the second data can be calculated based on the user identifier and the updated maximum index information mentioned above.
[0120] For example: For the first data, the maximum index information can be 128; for the second data, since the maximum index information has been updated, the updated index information can be 256.
[0121] The storage location of the second data can be calculated based on the aforementioned formula.
[0122] It should be noted that, for the second data, the calculation method has changed accordingly because the maximum index information has been updated during the process of calculating the storage location using the user identifier; however, the calculation method does not need to be adjusted because the business identifier contains the target storage location, and the determination steps are the same as those mentioned above, so they will not be repeated here.
[0123] The data query method provided in this application embodiment can update the maximum index information in response to a storage location expansion instruction; obtain a second query request for the second data; and determine the storage location of the second data based on the user identifier corresponding to the second data and the updated maximum index information. During the expansion process, the maximum index information can be updated, allowing data queries to be performed on the expanded data based on the updated maximum index information. This eliminates the need to migrate existing data, avoiding the additional power consumption associated with data migration and enabling smooth expansion of the storage location.
[0124] It should be noted that the target storage location of the second data can be determined using the two methods mentioned above. However, for the first data, since the maximum index information has changed, there may be anomalies during the calculation process using the user identifier. Therefore, other methods can be used to query the first data. The following explains one feasible implementation process for determining the target storage location of the first data after expansion.
[0125] Figure 10 For a flowchart illustrating the process of determining the storage location of the first data after data expansion as provided in this embodiment, please refer to... Figure 10 After updating the maximum index information in response to a storage location expansion command, the method further includes: S1010: The third query request to retrieve the first data.
[0126] The third query request includes the target business identifier.
[0127] It should be noted that the first data is the data written to the database before the maximum index information is updated, and the third query request is the query request obtained after the maximum index information is updated.
[0128] The third query request can be a request sent to the server by any electronic device; no specific restrictions are imposed here.
[0129] It should be noted that the third query request may include a target business identifier, which can be used to determine the target location of the first data.
[0130] S1020: Determine the target storage location of the first data based on the target business identifier.
[0131] It should be noted that after obtaining the third query request, the target storage location of the first data can be determined based on the target business identifier in the third query request. The method can be the formula for calculating the storage location based on the business identifier mentioned above. For example, the target storage location can be obtained based on the field composed of the last three characters of the target business identifier.
[0132] S1030: Query the first data in the target storage location.
[0133] Optionally, after obtaining the target storage location, the same steps as described in S230 above can be performed to query the first data in the target storage location.
[0134] It should be noted that since the maximum index information is used for calculation in determining the target storage location of the first data using the user identifier, the maximum index information is updated after data expansion. Continuing to use it may lead to calculation errors. Therefore, after data expansion, the target storage location of the first data can be calculated based on the target business identifier to ensure the accuracy of the target storage location calculation.
[0135] The data query method provided in this application embodiment can obtain a third query request for first data; determine the target storage location of the first data based on the target service identifier; and query the first data in the target storage location. Specifically, after data expansion, due to the update of the maximum index information, the target storage location of the first data can be determined through the target service identifier, thereby ensuring the accuracy of the target storage location determination while enabling successful data querying.
[0136] It should be understood that although the steps in the above flowcharts are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the above flowcharts may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0137] Based on the foregoing embodiments, this application provides a data query device, which includes various modules and units included in each module, and can be implemented by a processor; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.
[0138] Figure 11 This is a schematic diagram of the data query device provided in the embodiments of this application. Please refer to... Figure 11 The data query device includes: an acquisition module 1110, a determination module 1120, and a query module 1130.
[0139] The acquisition module 1110 is used to acquire a first query request for first data. The first query request includes a target business query identifier, which includes any one or more of a plurality of identifiers, including a user identifier and a business identifier. The determination module 1120 is used to determine the target storage location of the first data based on the target business query identifier; The query module 1130 is used to query the first data in the target storage location.
[0140] In one embodiment, the determining module 1120 is specifically used to determine the target storage location of the first data based on the method corresponding to the target business query identifier when the target business query identifier includes any one of the identifiers.
[0141] In one embodiment, the determining module 1120 is specifically used to determine the target storage location of the first data based on the target business query identifier with the highest priority among the multiple identifiers, when the target business query identifier includes any number of identifiers.
[0142] In one embodiment, when the target business query identifier is a user identifier, the determining module 1120 is specifically used to determine the target storage location of the first data based on the hash calculation value of the user identifier and the maximum index information; or, when the target business query identifier is a user identifier, the determining module 1120 is specifically used to determine the target storage location of the first data based on a preset field of the business identifier.
[0143] In one embodiment, the determining module 1120 is further configured to calculate multiple storage locations corresponding to multiple identifiers respectively; if any two storage locations are different among the multiple storage locations, an alarm message is generated, and the alarm message is used to indicate that the first data is abnormal data.
[0144] In one embodiment, the acquisition module 1110 is further configured to acquire the first data to be stored; determine the target storage location of the first data based on the user identifier and maximum index information of the first data, wherein the maximum index information is used to indicate the upper limit of the number of storage locations for the first data; generate a service identifier based on a random identifier and the target storage location, and store the first data in the target storage location.
[0145] In one embodiment, the determining module 1120 is further configured to update the maximum index information in response to the expansion instruction of the storage location; obtain a second query request for the second data, the second query request including the user identifier corresponding to the second data, the second data being the data stored after the expansion instruction; and determine the storage location of the second data based on the user identifier corresponding to the second data and the updated maximum index information.
[0146] In one embodiment, the determining module 1120 is further configured to obtain a third query request for the first data, the third query request including a target service identifier; determine the target storage location of the first data based on the target service identifier; and query the first data in the target storage location.
[0147] The data query device provided in this application embodiment can obtain a first query request for first data. The first query request includes a target business query identifier, which includes any one or more of a plurality of identifiers, including a user identifier and a business identifier. The device determines the target storage location of the first data based on the target business query identifier and queries the first data in the target storage location. The business query identifier allows for quick and direct determination of the target storage location of the first data. This enables rapid and accurate determination of the target storage location of the first data without accessing a centralized routing service, thereby improving the query speed. Furthermore, since there is no additional input / output latency during the access process, the stability of the data query is also improved, thus enabling data querying in high-concurrency scenarios and ensuring both speed and stability of the data query.
[0148] The descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0149] It should be noted that, in the embodiments of this application... Figure 11 The module division of the data query device shown is illustrative and represents only one logical functional division; in actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, exist as separate physical units, or be integrated into one unit by two or more units. The integrated units can be implemented in hardware, as software functional units, or a combination of both.
[0150] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0151] Figure 12 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application. Please refer to... Figure 12 This application provides a computer device, which can be the aforementioned server, and its internal structure diagram can be as follows. Figure 12 As shown, the computer device includes a processor 1220, memory, and a network interface 1240 connected via a system bus 1210. The processor 1220 provides computing and control capabilities. The memory includes a non-volatile storage medium 1231 and internal memory 1232. The non-volatile storage medium 1231 stores an operating system, computer programs, and a database. The internal memory 1232 provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium 1231. The database is used to store data. The network interface 1240 is used for communication with external terminals via a network connection. When the computer program is executed by the processor 1220, it implements the aforementioned methods.
[0152] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in the above embodiments.
[0153] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the method provided in the above-described method embodiments.
[0154] Those skilled in the art will understand that Figure 12 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0155] In one embodiment, the data query device provided in this application can be implemented as a computer program, and the computer program can be implemented in the form of, for example, Figure 12 The device operates on the computer device shown. The memory of the computer device can store the various program modules that make up the above-described apparatus. The computer program, composed of the various program modules, causes the processor to execute the steps of the methods in the various embodiments of this application described in this specification.
[0156] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0157] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" mentioned throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.
[0158] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.
[0159] It should be noted that, in this document, 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. Unless otherwise specified, 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 that element.
[0160] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or modules can be electrical, mechanical, or other forms.
[0161] The modules described above as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.
[0162] In addition, each functional module in the various embodiments of this application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the integrated modules can be implemented in hardware or in the form of hardware plus software functional units.
[0163] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0164] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0165] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0166] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0167] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0168] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data query method, characterized in that, include: A first query request to obtain first data, wherein the first query request includes a target business query identifier, and the target business query identifier includes any one or more of a plurality of identifiers, the plurality of identifiers including: user identifier and business identifier; The target storage location of the first data is determined based on the target business query identifier; Query the first data in the target storage location.
2. The method according to claim 1, characterized in that, Determining the target storage location of the first data based on the target business query identifier includes: If the target service query identifier includes any one of the identifiers, the target storage location of the first data is determined based on the method corresponding to the target service query identifier.
3. The method according to claim 1, characterized in that, Determining the target storage location of the first data based on the target business query identifier includes: When the target service query identifier includes any number of identifiers, the target storage location of the first data is determined based on the target service query identifier with the highest priority among the multiple identifiers, according to the priority order of the multiple identifiers.
4. The method according to any one of claims 1-3, characterized in that, When the target service query identifier is the user identifier, determining the target storage location of the first data based on the target service query identifier includes: The target storage location of the first data is determined based on the hash value of the user identifier and the maximum index information; or, When the target service query identifier is the service identifier, determining the target storage location of the first data based on the target service query identifier includes: The target storage location of the first data is determined based on the preset fields of the business identifier.
5. The method according to claim 3, characterized in that, When the target business query identifier includes any number of identifiers, the method further includes: Calculate the multiple storage locations corresponding to the multiple identifiers respectively; If any two storage locations differ among multiple storage locations, an alarm message is generated, which is used to indicate that the first data is abnormal data.
6. The method according to claim 1, characterized in that, Before the first query request to obtain the first data, the method further includes: Retrieve the first data to be stored; The target storage location of the first data is determined based on the user identifier of the first data and the maximum index information, wherein the maximum index information is used to indicate the upper limit of the number of storage locations for the first data. The service identifier is generated based on the random identifier and the target storage location, and the first data is stored in the target storage location.
7. The method according to claim 6, characterized in that, After storing the first data in the target storage location, the method further includes: In response to a storage location expansion command, update the maximum index information; Obtain a second query request for the second data, the second query request including the user identifier corresponding to the second data, the second data being the data stored after the expansion instruction; The storage location of the second data is determined based on the user identifier corresponding to the second data and the updated maximum index information.
8. The method according to claim 7, characterized in that, After updating the maximum index information in response to an expansion instruction from a storage location, the method further includes: A third query request to obtain the first data, wherein the third query request includes a target business identifier; The target storage location of the first data is determined based on the target service identifier; Query the first data in the target storage location.
9. A computer device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 8.
10. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 8.