Data reading and writing method and device, electronic equipment and computer storage medium
Through the learning index layer and adaptive radix tree layer in the hybrid index architecture, the problem of low database reading and writing efficiency is solved, and efficient processing of data reading and writing is achieved.
Patent Information
- Application Number
- CN202510621009.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-09-09
AI Technical Summary
In the prior art, the index structure of the database is not compatible with data read and write operations at the same time, resulting in low read and write efficiency.
A hybrid index architecture is adopted, combining the learning index layer and the adaptive radix tree layer. The data storage location is quickly determined in the learning index layer through the location prediction function, and adaptive retrieval is performed in the adaptive radix tree layer to resolve storage location conflicts.
The efficiency of data reading and writing is improved, and efficient reading and writing performance of the database is achieved.
Smart Images

Figure CN120610658A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data indexing technology, and in particular to a data reading and writing method, device, electronic equipment and computer storage medium. Background Art
[0002] With the continuous development of computer technology, the application of databases is becoming more and more extensive, and the size of databases is also growing.
[0003] In the prior art, the reading and writing efficiency of data in the database is usually improved by building an index for the data stored in the database. Due to the limitations of its structure, the existing index usually has restrictions on data reading or writing operations. It often can only have good performance in one aspect of data reading or data writing, but performs poorly in the other aspect and cannot be compatible with data reading or writing operations at the same time, resulting in low database reading and writing efficiency.
[0004] It can be seen that the existing technology cannot simultaneously have excellent data reading operations or writing operations, resulting in low database reading and writing efficiency. Summary of the Invention
[0005] In view of this, it is necessary to provide a data reading and writing method, device, electronic device and computer storage medium to solve the problem that the existing technology cannot simultaneously have excellent data reading operations or writing operations, resulting in low database reading and writing efficiency.
[0006] In order to solve the above problems, in a first aspect, the present invention provides a data reading and writing method applicable to a hybrid indexing architecture including a learning index layer and an adaptive radix tree layer, comprising: Obtain the key of the indexed data, predict the key using a preset position prediction function in the learning index layer, and predict the first storage location corresponding to the key; When the first storage location does not conflict with a read operation or a write operation on the indexed data, performing a read operation or a write operation on the indexed data at the first storage location; When the first storage location conflicts with the read or write operation of the indexed data, the key is adaptively retrieved in the adaptive radix tree layer to determine the second storage location corresponding to the key; and the indexed data is read or written at the second storage location.
[0007] In one possible implementation, the learning index layer includes multiple position prediction functions. The learning index layer uses a preset position prediction function to predict the key, and the first storage location corresponding to the predicted key includes: Determine a target position prediction function corresponding to the indexed data based on the value of the key of the indexed data; The target position prediction function is used to predict the value of the key of the indexed data to obtain the first storage position corresponding to the key of the indexed data.
[0008] In one possible implementation, the process of constructing the position prediction function includes: Segmenting the key-value pair storage locations of the stored data based on the keys of the stored data in the database to obtain a plurality of key-value pair storage location segments; Linear fitting is performed on the keys of the stored data and the key-value pair storage positions of the stored data in each key-value pair storage position segment to obtain multiple position prediction functions.
[0009] In one possible implementation, segmenting the key-value pair storage locations of the stored data based on the keys of the stored data in the database to obtain a plurality of key-value pair storage location segments includes: Calculating a slope between a starting key-value pair storage position of the key-value pair storage position segment and other key-value pair storage positions in the key-value pair storage position segment; The key-value pair storage position whose difference between the slope and the preset slope threshold is greater than the preset difference threshold is used as the key-value pair storage position segmentation point, and the key-value pair storage position segment is segmented based on the key-value pair storage position segmentation point.
[0010] In one possible implementation, the first storage location conflicts with a read operation or a write operation of the indexed data, including: When the indexing operation of the indexed data is a data write operation, the first storage location conflicts with the write operation of the indexed data because the first storage location is already occupied; When the indexing operation of the indexed data is a data read operation, the first storage location conflicts with the read operation of the indexed data because the first storage location is occupied and the key of the data stored in the first storage location is different from the key of the indexed data.
[0011] In one possible implementation, adaptively searching the key at the adaptive radix tree layer to determine the second storage location corresponding to the key includes: Based on the prefix of the key of the indexed data, prefix matching retrieval is performed layer by layer starting from the root node of the adaptive radix tree until a node in the adaptive radix tree that is the same as the prefix of the key of the indexed data is determined, and a second storage location is determined based on the node.
[0012] In one possible implementation, the read operation or write operation of the indexed data includes: When the indexing operation of the indexed data is a data read operation, extracting a true value of the data stored in the first storage location or the second storage location; When the indexing operation of the indexed data is a data writing operation, the data true value of the indexed data is written into the first storage location or the second storage location.
[0013] In a second aspect, the present invention further provides a data reading and writing device applicable to the data reading and writing method in any of the aforementioned embodiments, comprising: A storage location prediction module is used to obtain the key of the indexed data, predict the key using a preset location prediction function in the learning index layer, and predict the first storage location corresponding to the key; a first data reading and writing module, configured to perform a read operation or a write operation on the indexed data at the first storage location when the read operation or the write operation on the indexed data does not conflict with the first storage location; The second data read and write module is used to adaptively search the key in the adaptive radix tree layer when the first storage location conflicts with the read operation or write operation of the indexed data, determine the second storage location corresponding to the key, and perform a read operation or a write operation on the indexed data at the second storage location.
[0014] In a third aspect, the present invention further provides an electronic device comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is configured to execute the program stored in the memory to implement the steps in the data reading and writing method described in any one of the above embodiments.
[0015] In a fourth aspect, the present invention further provides an electronic device for storing computer-readable programs or instructions, which, when executed by a processor, can implement the steps in the data reading and writing method described in any of the above embodiments.
[0016] The beneficial effects of the present invention are as follows: the data reading and writing method provided by the present invention is applicable to a hybrid indexing architecture including a learning indexing layer and an adaptive radix tree layer. Through the design of the indexing architecture of the self-learning indexing layer and the adaptive radix tree layer, the characteristics of the two indexing structures can be better utilized, and both data reading and data writing have higher efficiency. Specifically, according to the key of the indexed data, a preset position prediction function is used in the self-learning indexing layer to predict the key and predict the first storage location corresponding to the key. When the first storage location does not conflict with the read operation or write operation of the indexed data, the indexed data is read or written at the first storage location. The self-learning indexing layer predicts the key of the indexed data, and the first storage location corresponding to the key of the indexed data can be effectively determined, thereby improving the efficiency of data reading. When the first storage location conflicts with the read operation or write operation of the indexed data, the adaptive radix tree layer performs an adaptive search on the key to determine the second storage location corresponding to the key; and the indexed data is read or written at the second storage location. The adaptive radix tree layer searches for the indexed data that the learning indexing layer cannot find, thereby improving the efficiency of data writing. By combining the features of the learning index layer and the adaptive radix tree layer, the efficiency of data reading and writing is improved at the same time, thereby improving the data reading and writing efficiency of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 A flowchart of a data reading and writing method provided by an embodiment of the present invention; Figure 2 A data index structure diagram provided by an embodiment of the present invention; Figure 3 A schematic flow chart of a first storage location determination method provided by an embodiment of the present invention; Figure 4 A schematic diagram of a flow chart of a method for constructing a position prediction function provided by an embodiment of the present invention; Figure 5 A schematic diagram of a flow chart of a data segmentation method provided in an embodiment of the present invention; Figure 6 A flow chart of a data conflict determination method provided by an embodiment of the present invention; Figure 7 A schematic diagram of data segmentation provided by an embodiment of the present invention; Figure 8A schematic structural diagram of a data reading and writing device provided by an embodiment of the present invention; Figure 9 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] The preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein the accompanying drawings constitute a part of the present invention and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.
[0020] The terms "first," "second," and so on, used in the embodiments of the present invention are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, technical features designated as "first" or "second" may explicitly or implicitly include at least one such feature.
[0021] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present invention. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute a separate or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0022] A specific embodiment of the present invention, as Figure 1 As shown, a data reading and writing method is disclosed, which is applicable to a hybrid indexing architecture including a learning index layer and an adaptive radix tree layer, including: S101, obtaining the key of the indexed data, using a preset position prediction function to predict the key in the learning index layer, and predicting the first storage position corresponding to the key.
[0023] In an embodiment of the present invention, the data reading and writing method provided is applicable to a hybrid indexing architecture including a learning indexing layer and an adaptive radix tree layer, such as Figure 2 To better illustrate the present invention, a new indexing architecture is provided, comprising a learning index layer and an adaptive radix tree layer. The learning index layer uses a machine learning model to fit a cumulative function curve to the data and determines the data location through model prediction. Compared to traditional index structures, the learning index has higher space utilization and better read performance. As a traditional tree-based index structure, the adaptive radix tree extracts and stores common prefixes of keys to achieve space compression, and performs well under write loads.
[0024] In an embodiment of the present invention, indexed data refers to data associated with a database, such as data that needs to be read from a database, or data that needs to be stored in a database, and the corresponding indexing operation is a data reading operation or a data writing operation. For indexed data, when the corresponding indexing operation is a data reading operation, the indexed data should include a key, and the data storage location is searched in the database through the key of the data, and the true value of the data stored in the location is read. When the indexing operation corresponding to the indexed data is a data writing operation, the indexed data should include the key and true value of the data, and the data storage location is searched in the database through the key of the data, and the true value of the indexed data is stored in the location. Therefore, in the data reading operation or writing operation of the present invention, it is necessary to first obtain the key of the indexed data, and then determine the key-value pair storage location corresponding to the indexed data based on the key of the indexed data. Specifically, the key can be predicted by using a preset position prediction function through the learning index layer, and the first storage location corresponding to the predicted key is predicted. The first storage location is used to store the true value of the indexed data. The specific method for determining the first storage location will be described in detail later in the present invention.
[0025] S102 : When the first storage location does not conflict with the read operation or write operation of the indexed data, perform a read operation or a write operation on the indexed data at the first storage location.
[0026] In an embodiment of the present invention, the learning index layer can quickly find the first storage location corresponding to the indexed data. When the first storage location satisfies the read operation or write operation of the indexed data, the true value of the indexed data is directly read or written at the first storage location.
[0027] S103, when the first storage location conflicts with the read operation or write operation of the indexed data, adaptively search the key in the adaptive radix tree layer to determine the second storage location corresponding to the key; and perform a read operation or a write operation on the indexed data in the second storage location.
[0028] In an embodiment of the present invention, the first storage location may not be able to satisfy a read operation or a write operation of the indexed data. For example, for a data write operation, the first storage location may already be occupied, or for a data read operation, the data stored in the first storage location may have a different key than the indexed data. Therefore, it is necessary to use an adaptive radix tree layer to adaptively search the key, and then determine the second storage location corresponding to the key of the indexed data, and then perform a read operation or a write operation on the indexed data at the second storage location. The specific method for determining the second storage location will be described in detail later in the present invention.
[0029] The data reading and writing method provided by the present invention is applicable to a hybrid indexing architecture including a learning indexing layer and an adaptive radix tree layer. Through the design of the indexing architecture of the self-learning indexing layer and the adaptive radix tree layer, the characteristics of the two indexing structures can be better utilized, and both data reading and data writing have higher efficiency. Specifically, based on the key of the indexed data, a preset position prediction function is used in the self-learning indexing layer to predict the key and predict the first storage location corresponding to the key. When the first storage location does not conflict with the read operation or write operation of the indexed data, the indexed data is read or written at the first storage location. The self-learning indexing layer predicts the key of the indexed data, and the first storage location corresponding to the key of the indexed data can be effectively determined, thereby improving the efficiency of data reading. When the first storage location conflicts with the read operation or write operation of the indexed data, the adaptive radix tree layer performs an adaptive search on the key to determine the second storage location corresponding to the key; and the indexed data is read or written at the second storage location. The adaptive radix tree layer is used to search for the indexed data that the learning indexing layer cannot find, thereby improving the efficiency of data writing. By combining the features of the learning index layer and the adaptive radix tree layer, the efficiency of data reading and writing is improved at the same time, thereby improving the data reading and writing efficiency of the database.
[0030] In some possible embodiments of the present invention, Figure 3 As shown, the learning index layer includes multiple position prediction functions. The learning index layer uses a preset position prediction function to predict the key, and the first storage position corresponding to the predicted key includes: S301, determining a target position prediction function corresponding to the indexed data based on the key value of the indexed data; S302: Use a target position prediction function to predict the value of the key of the indexed data to obtain a first storage position corresponding to the key of the indexed data.
[0031] In an embodiment of the present invention, the position prediction function can predict the storage location of the key-value pair corresponding to the indexed data based on the key of the indexed data. Due to the huge amount of data stored in the database, one position prediction function may not be able to accurately predict the storage location of all data. Therefore, it is necessary to construct multiple position prediction functions to perform position prediction on different data. The method for constructing multiple position prediction functions will be described in detail later in the present invention.
[0032] In an embodiment of the present invention, after constructing multiple position prediction functions, the target position prediction function corresponding to the key of the indexed data can be determined according to the value of the key of the indexed data. Specifically, each position prediction function is used to predict the position of a certain segment of data. For example, the key value of the data stored in the database is 1~100, which is divided into two position prediction functions. The first position prediction function is used to predict the key-value pair storage position of the data with a key value of 1~50, and the second position prediction function is used to predict the key-value pair storage position of the data with a key value of 50~100. Therefore, the target position prediction function corresponding to the indexed data can be determined according to the value of the key of the indexed data. Of course, the specific range of the value of the key of the data stored in the database, the number of position prediction functions, and the range of the key value corresponding to each position prediction function can all be determined according to actual conditions.
[0033] In an embodiment of the present invention, after determining the target position prediction function, the target position prediction function may be used to predict the value of the key of the indexed data to obtain the first storage location corresponding to the key of the indexed data. Optionally, the target position prediction function may be a linear function, where the input is the value of the key of the indexed data and the output is the key-value pair storage location corresponding to the value of the key of the indexed data.
[0034] The embodiment of the present invention predicts the value of the key of the indexed data by learning the position prediction function in the index layer, and can quickly determine the storage location of the key-value pair corresponding to the indexed data, which facilitates subsequent data reading or writing operations.
[0035] In some possible embodiments of the present invention, Figure 4 As shown in Figure 2, the construction process of the position prediction function includes: S401, segmenting the key-value pair storage locations of the stored data based on the keys of the stored data in the database to obtain a plurality of key-value pair storage location segments; S402 , performing linear fitting on the keys of the stored data and the key-value pair storage positions of the stored data in each key-value pair storage position segment to obtain a plurality of position prediction functions.
[0036] In an embodiment of the present invention, before constructing a position prediction function, it is necessary to first segment the data stored in the database. The basis for data segmentation is the storage position of the data in the database. The key-value pair storage position of the stored data is segmented based on the key of the stored data in the database to obtain multiple key-value pair storage position segments. Then, linear fitting is performed on the key of the stored data and the key-value pair storage position of the stored data in each key-value pair storage position segment to obtain multiple position prediction functions. In the linear fitting, the function input is the value of the key of the stored data, and the function output is the key-value pair storage position of the stored data. The specific linear fitting method can adopt existing methods such as the least squares method, which will not be described in detail in the present invention.
[0037] The embodiment of the present invention segments the key-value pair storage locations of the stored data based on the keys of the stored data in the database, and linearly fits the keys of the stored data and the key-value pair storage locations of the stored data in each key-value pair storage location segment according to the segmentation results to obtain multiple position prediction functions, which can effectively ensure the accuracy of the prediction of the keys of the indexed data by each position prediction function.
[0038] In some possible embodiments of the present invention, Figure 5 As shown, after the key-value pair storage locations of the stored data are segmented based on the keys of the stored data in the database to obtain multiple key-value pair storage location segments, the following steps are included: S501, calculating the slope between the starting key-value pair storage position of the key-value pair storage position segment and the other key-value pair storage positions in the key-value pair storage position segment; S502 : Using a key-value pair storage location whose slope has a difference with a preset slope threshold greater than the preset difference threshold as a key-value pair storage location segmentation point, and segmenting the key-value pair storage location segments based on the key-value pair storage location segmentation point.
[0039] In an embodiment of the present invention, in order to ensure the accuracy of the segmentation of the data position segment, the division of the data position segment can be updated while constructing the position prediction function. Specifically, an error_bound parameter is pre-set to indicate when the data needs to be segmented. cur_position represents the current data point sequence number, N represents the number of data points currently remaining, the upper and lower bound linear functions both pass through the starting data point of the current segment, upper_slope and lower_slope respectively represent the slopes corresponding to the upper and lower bound linear functions, new_slope represents the slope of the linear function formed by the current data point and the starting data point of the current segment, upper_error and lower_error respectively represent the difference between the actual position of the current data point and the upper and lower bound predicted positions. Initialize cur_position to 0, upper_slope and lower_slope to the slope values of the linear function formed by the first two data points of the current segment. After completing the initialization operation, an attempt is made to add a new data point and calculate the corresponding new_slope. The calculated new_slope is then compared with both upper_slope and lower_slope. If new_slope is greater than upper_slope, upper_slope is updated to the current new_slope; if new_slope is less than lower_slope, lower_slope is updated to the current lower_slope. After completing the slope update, the difference between the predicted value and the actual position of the current data point is calculated using the upper and lower bound linear functions. If the larger of these two differences is greater than the error_bound parameter, a segmentation operation is triggered, saving the currently added data point in the same segment and returning the current data point's sequence number as the return value. The segmentation algorithm is then re-applied to the remaining data until all data points are segmented, ultimately obtaining the start and end information for multiple segments.
[0040] The embodiments of the present invention can segment data more accurately, thereby ensuring the accuracy of the position prediction function.
[0041] In some possible embodiments of the present invention, Figure 6 As shown, the first storage location conflicts with a read operation or a write operation of the indexed data, including: S601, when the indexing operation of the indexed data is a data writing operation, the first storage location conflicts with the writing operation of the indexed data because the first storage location is occupied; S602, when the indexing operation of the indexed data is a data read operation, the first storage location conflicts with the read operation of the indexed data because the first storage location is occupied, and the key of the data stored in the first storage location is different from the key of the indexed data.
[0042] In the embodiment of the present invention, for a write operation, the input is the key key and the true value val to be written, and the output is whether the write operation is successful. Figure 2 As shown in , first, search in the model starting value array in the learning index layer to find the GPL model corresponding to the key. Then, use the linear function in the GPL model to predict the key position. Then, as Figure 7 As shown, a bitmap is checked to determine whether the location is occupied by data, where 1 indicates occupied and 0 indicates unoccupied. The data entry is the serial number of the storage location assigned to the data at that location. Within each key-value pair storage location segment, the data entries are arranged in ascending order. If the location is unoccupied, the data is written directly to the corresponding location and a success message is returned. Otherwise, the data is attempted to be written to the lower adaptive radix tree and a success message is returned. For read operations, the input is the key to be queried, and the output is the true value val corresponding to the key. val is initially empty. First, the GPL model corresponding to the key is searched within the model starting value array in the learned index layer. Next, a linear function within the GPL model is used to predict the key location. The bitmap is then checked to determine whether the location is occupied by data. If so, the value val is returned directly. Otherwise, the data stored at the location matches the key. If so, the data is copied to val and returned. If not, a prefix matching search is performed layer by layer, starting from the root node of the lower adaptive radix tree, until the query is complete. The query result is copied to val and returned.
[0043] Specifically, performing adaptive retrieval on the key at the adaptive radix tree layer to determine the second storage location corresponding to the key includes: Based on the prefix of the key of the indexed data, prefix matching retrieval is performed layer by layer starting from the root node of the adaptive radix tree until a node in the adaptive radix tree that is the same as the prefix of the key of the indexed data is determined, and a second storage location is determined based on the node.
[0044] In the embodiment of the present invention, Figure 2As shown, the adaptive radix tree has multiple nodes, each used to store a prefix of a key. The root node is used to store a common prefix. Space compression is achieved by extracting and saving the common prefix of the key. When it is necessary to find the storage location of the data based on the key, prefix matching retrieval is performed layer by layer starting from the root node of the adaptive radix tree based on the prefix of the key of the indexed data until a node in the adaptive radix tree with the same prefix as the key of the indexed data is determined, and a second storage location is determined based on the node.
[0045] The data reading and writing method provided by the present invention, for read operations, first performs model positioning and data position prediction in the upper-level learning index. If the predicted position is not occupied, it directly returns that the data does not exist; if the predicted position is occupied and matches the query key, it directly returns the corresponding data value; if the predicted position is occupied but does not match the query key, it continues to search in the lower-level adaptive radix tree. For write operations, model positioning and data prediction are also performed in the upper-level learning index. If the predicted position is not occupied, the data is directly written to the position; if the predicted position is occupied, the data is written to the lower-level adaptive radix tree. Among them, the read operation or write operation of the indexed data includes: when the index operation of the indexed data is a data read operation, reading the key-value pair stored in the first storage location or the second storage location; when the index operation of the indexed data is a data write operation, writing the key-value pair of the indexed data to the first storage location or the second storage location, which can effectively improve the read and write efficiency of the database.
[0046] In order to better implement the data reading and writing method in the embodiment of the present invention, based on the data reading and writing method, correspondingly, Figure 8 As shown, an embodiment of the present invention further provides a data reading and writing device, and the data reading and writing device 800 includes: The storage location prediction module 801 is used to obtain the key of the indexed data, predict the key using a preset location prediction function in the learning index layer, and predict the first storage location corresponding to the key; A first data reading and writing module 802 is configured to perform a read operation or a write operation on the indexed data at the first storage location when the read operation or the write operation on the indexed data does not conflict with the first storage location; The second data read and write module 803 is used to adaptively search the key in the adaptive radix tree layer to determine the second storage location corresponding to the key when the first storage location conflicts with the read operation or write operation of the indexed data; and perform a read operation or a write operation on the indexed data at the second storage location.
[0047] The data reading and writing device 800 provided in the above embodiment can implement the technical solution described in the above data reading and writing method embodiment. The specific implementation principles of the above modules or units can be found in the corresponding content in the above data reading and writing method embodiment, which will not be repeated here.
[0048] like Figure 9 As shown, the present invention also provides an electronic device 900. The electronic device 900 includes a processor 901, a memory 902 and a display 903. Figure 9 Only some of the components of the electronic device 900 are shown, but it should be understood that implementation of all of the shown components is not required, and more or fewer components may be implemented instead.
[0049] In some embodiments, the processor 901 may be a central processing unit (CPU), a microprocessor, or other data processing chip, configured to execute program codes stored in the memory 902 or process data, such as the data reading and writing method of the present invention.
[0050] In some embodiments, the processor 901 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 901 may be local or remote. In some embodiments, the processor 901 may be implemented on a cloud platform. In some embodiments, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, multiple clouds, or any combination thereof.
[0051] In some embodiments, the memory 902 may be an internal storage unit of the electronic device 900, such as a hard disk or memory of the electronic device 900. In other embodiments, the memory 902 may also be an external storage device of the electronic device 900, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 900.
[0052] Furthermore, the memory 902 may include both an internal storage unit of the electronic device 900 and an external storage device. The memory 902 is used to store application software installed in the electronic device 900 and various data.
[0053] In some embodiments, the display 903 can be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen. The display 903 is used to display information about the electronic device 900 and to display a visual user interface. Components 901-903 of the electronic device 900 communicate with each other via a system bus.
[0054] In some embodiments, when the processor 901 executes the data reading and writing program in the memory 902, the following steps may be implemented: Obtain the key of the indexed data, predict the key using a preset position prediction function in the learning index layer, and predict the first storage location corresponding to the key; When the first storage location does not conflict with a read operation or a write operation on the indexed data, performing a read operation or a write operation on the indexed data at the first storage location; When the first storage location conflicts with the read or write operation of the indexed data, the key is adaptively retrieved in the adaptive radix tree layer to determine the second storage location corresponding to the key; and the indexed data is read or written at the second storage location.
[0055] It should be understood that, when the processor 901 executes the data reading and writing program in the memory 902 , in addition to the above functions, it can also implement other functions. For details, please refer to the description of the corresponding method embodiment above.
[0056] Furthermore, the embodiment of the present invention does not specifically limit the type of the electronic device 900 mentioned. The electronic device 900 may be a portable electronic device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, or a laptop computer. Exemplary embodiments of portable electronic devices include but are not limited to portable electronic devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable electronic devices may also be other portable electronic devices, such as a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments of the present invention, the electronic device 900 may not be a portable electronic device, but a desktop computer with a touch-sensitive surface (e.g., a touch panel).
[0057] Accordingly, an embodiment of the present invention also provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps or functions in the data reading and writing methods provided in the above-mentioned method embodiments can be implemented.
[0058] Those skilled in the art will appreciate that all or part of the process steps of the above-described embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, such as a magnetic disk, an optical disk, a read-only memory, or a random access memory.
[0059] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with this technical field within the technical scope disclosed by the present invention should be covered by the scope of protection of the present invention.
Claims
1. A data reading and writing method, characterized in that: Applicable to hybrid indexing architectures that include a learned index layer and an adaptive radix tree layer, including: Obtaining a key of the indexed data, predicting the key using a preset position prediction function in the learning index layer, and predicting a first storage location corresponding to the key; When the first storage location does not conflict with a read operation or a write operation on the indexed data, performing a read operation or a write operation on the indexed data at the first storage location; When the first storage location conflicts with a read operation or a write operation on the indexed data, the key is adaptively retrieved at the adaptive radix tree layer to determine a second storage location corresponding to the key; and a read operation or a write operation is performed on the indexed data at the second storage location.
2. The data reading and writing method according to claim 1, wherein: The learning index layer includes a plurality of position prediction functions, and the learning index layer uses a preset position prediction function to predict the key, and predicts the first storage position corresponding to the key, including: Determining a target position prediction function corresponding to the indexed data based on a value of a key of the indexed data; The target position prediction function is used to predict the value of the key of the indexed data to obtain a first storage position corresponding to the key of the indexed data.
3. The data reading and writing method according to claim 2, wherein: The process of constructing the position prediction function includes: Segmenting the key-value pair storage locations of the stored data based on the keys of the stored data in the database to obtain a plurality of key-value pair storage location segments; Linear fitting is performed on the keys of the stored data and the key-value pair storage positions of the stored data in each of the key-value pair storage position segments to obtain multiple position prediction functions.
4. The data reading and writing method according to claim 3, wherein: The method includes: segmenting the key-value pair storage locations of the stored data based on the keys of the stored data in the database to obtain a plurality of key-value pair storage location segments; Calculating a slope between a starting key-value pair storage position of the key-value pair storage position segment and other key-value pair storage positions in the key-value pair storage position segment; The key-value pair storage position whose difference between the slope and the preset slope threshold is greater than the preset difference threshold is used as a key-value pair storage position segmentation point, and the key-value pair storage position segment is segmented based on the key-value pair storage position segmentation point.
5. The data reading and writing method according to claim 1, wherein: The first storage location conflicts with a read operation or a write operation of the indexed data, including: When the indexing operation of the indexed data is a data writing operation, the first storage location conflicts with the writing operation of the indexed data because the first storage location is already occupied; When the indexing operation of the indexed data is a data reading operation, the first storage location conflicts with the reading operation of the indexed data because the first storage location is occupied and the key of the data stored in the first storage location is different from the key of the indexed data.
6. The data reading and writing method according to claim 1, wherein: Adaptively searching the key at the adaptive radix tree layer to determine the second storage location corresponding to the key includes: Based on the prefix of the key of the indexed data, prefix matching retrieval is performed layer by layer starting from the root node of the adaptive radix tree until a node in the adaptive radix tree that is the same as the prefix of the key of the indexed data is determined, and a second storage location is determined based on the node.
7. The data reading and writing method according to claim 1, characterized in that: The read operation or write operation of the indexed data includes: When the indexing operation of the indexed data is a data read operation, reading the key-value pair stored in the first storage location or the second storage location; When the indexing operation of the indexed data is a data writing operation, the key-value pair of the indexed data is written into the first storage location or the second storage location.
8. A data reading and writing device, characterized in that: The data reading and writing method according to any one of claims 1 to 7 comprises: A storage location prediction module is used to obtain the key of the indexed data, predict the key using a preset location prediction function in the learning index layer, and predict the first storage location corresponding to the key; a first data reading and writing module, configured to perform a read operation or a write operation on the indexed data at the first storage location when the read operation or the write operation on the indexed data does not conflict with the first storage location; The second data read and write module is used to adaptively search the key in the adaptive radix tree layer to determine the second storage location corresponding to the key when the first storage location conflicts with the read operation or write operation of the indexed data; and perform a read operation or a write operation on the indexed data at the second storage location.
9. An electronic device, characterized in that: comprising a memory and a processor, wherein, The memory is used to store programs; The processor is coupled to the memory and is configured to execute the program stored in the memory to implement the steps in the data reading and writing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps of the data reading and writing method described in any one of claims 1 to 7.
Citation Information
Cited By
Key value database read-write optimization method and system based on CSD learning type index
CN121705321A
Key-value database read-write optimization method and system based on CSD learning index
CN121705321B