Learning index query method based on trusted execution environment and electronic device

By separating the storage model parameter layer and the data page layer in a trusted execution environment, and using historical deviation statistics to retrieve data pages in batches, the problems of unreasonable storage distribution of the index structure and frequent cross-boundary switching are solved, thereby improving query efficiency and system performance.

CN123157707APending Publication Date: 2026-11-24TSINGHUA UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611140978.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-29
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

In heterogeneous storage environments, unreasonable storage distribution of index structures and high overhead from frequent cross-boundary environment switching during the query verification phase lead to a decline in system performance.

Method used

The model parameter layer is stored in plaintext in the protected memory of the trusted execution environment, while the data page layer is stored in ciphertext in a storage layer outside the trusted execution environment. The model parameter layer is used to infer the query key within the trusted execution environment to determine the candidate data page range, and historical deviation statistics are used to predict the data page location. The ciphertext data pages are retrieved in batches for decryption and search, reducing cross-boundary calls.

Benefits of technology

Maintaining the index structure securely and compactly within limited memory capacity reduces cross-boundary interaction overhead, improves query performance, and lowers the cost of environment switching and encrypted decryption overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157707A_ABST
    Figure CN123157707A_ABST
Patent Text Reader

Abstract

This application discloses a learning index query method and electronic device based on a trusted execution environment. The learning index includes a protected memory model parameter layer stored in plaintext within the trusted execution environment and a data page layer stored in encrypted form at a storage level outside the environment. During a query, the predicted position is obtained by inferring the query key layer by layer within the environment based on the model parameter layer. The candidate data page range is determined based on the predicted position, error parameters, and the number of records per page. Then, the predicted page and the prefetch page are determined from the historical deviation statistics maintained within the environment. The encrypted versions of both are retrieved in a single cross-boundary call. The predicted page is decrypted first for searching, and if no match is found, the prefetch page is decrypted, until the data record is located. The statistics are updated according to the deviation of the actual position from the predicted position, so that the model inference does not generate cross-boundary calls. The data pages required for the last mile verification are merged into a single batch retrieval and decrypted as needed, reducing the number of cross-boundary calls and decryption overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of fully encrypted database technology, and in particular to a learning-based index query method and electronic device based on a trusted execution environment. Background Technology

[0002] With the rapid development of cloud-native technologies, more and more enterprises and organizations are choosing to host their computing and data storage in the cloud. Storing private data in the cloud can lead to data breaches in untrusted environments, making fully encrypted database technology a real-world necessity. This technology ensures that sensitive data remains encrypted throughout the entire transmission and computation process, and is a crucial infrastructure for protecting cloud data privacy.

[0003] Introducing a Trusted Execution Environment (TEE) is an effective technical approach for building efficient, fully secure databases. This environment provides hardware-level isolation zones, ensuring the confidentiality and integrity of sensitive data. However, the application of this technology also faces limitations and challenges in its underlying architecture. Protected memory resources are very limited, and an untrusted operating system restricts direct system calls within the environment, necessitating cross-boundary switching to a Rich Execution Environment (REE) for external interaction. This cross-environment switching incurs extremely high computational costs.

[0004] One existing solution is based on a traditional tree-structured index architecture, which sets up buffer pools in both internal and external environments to reduce external storage access. However, in scenarios with frequent updates, the large number of tree nodes can easily exhaust protected memory, leading to a decrease in buffer hit rate and an increase in cross-environment switching, resulting in a serious degrade in system performance.

[0005] Another existing approach uses machine learning models to fit data mapping relationships and queries data through a two-stage pattern of model inference and record-level verification. However, in heterogeneous storage environments, its verification strategy of probing page by page along the error window causes a linear accumulation of cross-boundary call counts, resulting in significant cross-boundary interaction system overhead.

[0006] In summary, how to optimize the storage distribution of index structures to adapt to capacity constraints in heterogeneous storage environments, and how to reduce the overhead of frequent cross-boundary environment switching during the query verification phase, are the technical challenges that urgently need to be solved in this field. Summary of the Invention

[0007] This application proposes a learning-based index query scheme based on a trusted execution environment, which can solve the technical problems of unreasonable storage distribution of index structure in heterogeneous storage environment and high overhead of frequent cross-boundary environment switching during query verification stage.

[0008] According to one embodiment of this application, a learning index query method based on a trusted execution environment is proposed. The learning index includes a model parameter layer and a data page layer. The model parameter layer represents the mapping relationship from key to position, and the data page layer includes multiple data pages. The data pages are used to store data records in order of key size. The method includes: The model parameter layer is stored in plaintext in the protected memory of the trusted execution environment, and the data page layer is stored in ciphertext at a storage level outside the trusted execution environment. In response to a query request carrying a query key, the query key is inferred layer by layer based on the model parameter layer within the trusted execution environment to obtain the predicted position of the query key in the data page layer; Based on the predicted location, the predetermined error parameters, and the number of data records that a single data page can hold, the candidate data page range for the query key is determined; Based on the historical deviation statistics maintained within the trusted execution environment, a predicted page and at least one prefetched page are determined from the candidate data page interval. The historical deviation statistics characterize the deviation of the actual position of a data record in a historical query from the predicted position. The encrypted text of the predicted page and the prefetched page is obtained in batches through cross-boundary calls; Within the trusted execution environment, the prediction page is first decrypted and the query key is searched in the decrypted prediction page. If the query key is not found in the prediction page, the prefetch page is decrypted and the search continues until the data record corresponding to the query key is located. The historical deviation statistics are updated based on the deviation relationship between the actual position of the located data record in the data page layer and the predicted position.

[0009] According to one embodiment of this application, an electronic device is provided, the device including a memory and a processor, the memory being used to store computer instructions executable on the processor, and the processor being used to implement the method as described in any of the preceding claims when executing the computer instructions.

[0010] The learning-based index query scheme proposed in this application, based on a trusted execution environment, maintains the index structure securely and compactly within limited memory capacity by storing the model parameter layer in plaintext within the protected memory of the trusted execution environment and storing the data page layer in encrypted form in an external storage layer. This allows the model inference process to be completed entirely within the environment, eliminating the overhead of cross-boundary interactions in the early stages of inference. Furthermore, by using historical deviation statistics maintained within the environment, predicted pages and prefetched pages are determined from the calculated candidate data page intervals, enabling directional prediction of the location of the actual data record. Based on this, relevant encrypted data pages are retrieved in batches via cross-boundary calls. The predicted pages are decrypted within the environment first, and the prefetched pages are decrypted only if a match is missed. Simultaneously, the statistical information is continuously updated based on the actual location deviation relationship. This merges the multiple cross-boundary calls previously required for page-by-page probing into a single batch retrieval operation, significantly reducing the high cost of environment switching and unnecessary encrypted decryption overhead, thereby improving overall index query performance.

[0011] Other features and advantages of the technical solution proposed in this application are described below. Attached Figure Description

[0012] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this specification and, together with the description, serve to explain the principles of this specification.

[0013] Figure 1 A flowchart illustrating a learning-based index query method based on a trusted execution environment, provided as an embodiment of this application; Figure 2 A schematic diagram of the system architecture of a learning index query system based on a trusted execution environment, provided as an exemplary embodiment of this application; Figure 3 A schematic diagram of the last-mile adaptive prefetching and bias update process provided for an exemplary embodiment of this application; Figure 4 A schematic diagram illustrating an example of a query process provided in an exemplary embodiment of this application; Figure 5 This is a schematic diagram of the hardware structure of an electronic device provided in at least one embodiment of this application. Detailed Implementation

[0014] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0015] This application splits the learning index into two parts: a model parameter layer and a data page layer, and places them separately. The model parameter layer resides in the protected memory of the trusted execution environment in plaintext form, while the data page layer is placed in a storage layer outside the trusted execution environment in encrypted form, so that model inference during queries does not generate cross-boundary calls. At the same time, the bias statistics of historical queries are maintained in the trusted execution environment to predict the direction or range of the actual position relative to the predicted position. The predicted page and the prefetched page are merged into a single cross-boundary call for batch retrieval and decryption as needed, so as to solve the problem of limited protected memory capacity and the cumulative number of cross-boundary calls caused by page-by-page probing in the last mile verification.

[0016] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a learning-based index query method based on a trusted execution environment, provided in one embodiment of this application. The method of this embodiment can be applied to fully encrypted databases, such as encrypted database tables hosted in the cloud. The index keys of this table can be fixed-length unsigned integers, such as 8-byte unsigned integers. The learning-based index uses a machine learning model to fit the mapping relationship between data keys and storage locations, replacing the large internal nodes in traditional tree-structured indexes with compact model parameters. Given a query key, the model first calculates the approximate position of the key in the ordered data, and then searches for and locates the actual record within an error window near that position.

[0017] In this embodiment, the learning index includes a model parameter layer and a data page layer. The model parameter layer represents the mapping relationship from key to position, and the data page layer includes multiple data pages, which are used to store data records in order of key size.

[0018] Figure 1 The method shown includes the following steps S1 to S7.

[0019] Step S1: Store the model parameter layer in plaintext in the protected memory of the trusted execution environment, and store the data page layer in ciphertext at a storage level outside the trusted execution environment.

[0020] A Trusted Execution Environment (TEE) is an isolated execution region provided by processor hardware. The code and data within it are protected at the hardware level, and privileged software such as the operating system cannot access information in plaintext. The protected memory capacity of a TEE is relatively limited, typically in the hundreds of megabytes. This memory resource is shared by database instances running on the same platform.

[0021] In the TEE threat model, the operating system is considered an untrusted part, and system calls cannot be directly initiated within the TEE. When executing a system call, a switch to a Rich Execution Environment (REE) is required before returning to the TEE. This function call interface between the TEE and REE is called a cross-boundary call, which can be implemented as a call initiated from the TEE to the REE and a call returning from the REE to the TEE. Each cross-boundary call involves context saving and security checks, incurring higher overhead than a regular function call, requiring two to three orders of magnitude more CPU clock cycles than a regular system call.

[0022] Based on the aforementioned capacity and call overhead characteristics, this application proposes placing the two layers of the learning index separately. The entire content of the model parameter layer can be written into the protected memory of the TEE and reside there permanently, stored in plaintext form, serving as the data source for the model inference stage. The model parameter layer is compact, allowing the location information of a large number of data records to be expressed with a small number of parameters, and its total volume can be controlled within the available capacity of the protected memory.

[0023] The data page layer can store key-value pairs arranged in an ordered manner, or key-record identifier pairs, with each data page accommodating a fixed number of data records. Since the data page layer is much larger than the model parameter layer, it is stored in encrypted form at a storage level outside the trusted execution environment. This storage level can be the REE's memory, or a storage medium outside the REE's memory with a lower access speed but larger capacity.

[0024] The encryption and integrity tag generation of data pages, as well as the decryption and integrity verification of ciphertext data pages, can all be completed within the TEE. Integrity tags are generated simultaneously when data pages are written to storage levels outside the TEE. When ciphertext data pages retrieved from external sources are decrypted, integrity verification is performed based on the integrity tags; if the verification fails, the query is terminated. Data pages written to storage levels outside the TEE always remain in ciphertext state. Data page decryption and integrity verification can be completed in the same process.

[0025] With the above placement method, the model inference phase of the query process can be completed entirely within the TEE without generating cross-boundary calls; cross-boundary calls only occur during the data page retrieval phase. Simultaneously, larger data page layers do not occupy protected memory, overcoming the constraint of limited protected memory capacity on index size.

[0026] Step S2: In response to a query request carrying a query key, the query key is inferred layer by layer based on the model parameter layer within the trusted execution environment to obtain the predicted position of the query key in the data page layer.

[0027] The predicted location refers to the estimated position of the data record corresponding to the query key in the ordered data, calculated by the model parameter layer. The actual storage location of this data record is called the true location. There is often a deviation between the true location and the predicted location. The inference in this step only reads the model parameter layer resident in protected memory and does not access the data page layer, so it can be completed entirely within the TEE without generating cross-boundary calls.

[0028] In some implementations, the model parameter layer includes multiple segments recursively organized hierarchically, wherein leaf layer segments index data pages in the data page layer using the error parameter, inner layer segments index the next layer's segment set using a fixed error parameter smaller than the error parameter, and so on upwards layer by layer until a unique root layer segment is formed; each segment includes a start key, a slope, and an intercept; the step of inferring the query key layer by layer based on the model parameter layer within the trusted execution environment to obtain the predicted position of the query key in the data page layer includes: using the root layer segment as the current segment, according to the formula... Calculate the position of the query key in the next layer and round down, where, For the query key, The starting key for the current segment. The slope of the current segment. The intercept of the current segment. The calculated position is used as the center in the next layer, and the fixed error parameter is used as the half-width to determine the candidate segment set. The segment to which the query key belongs is searched within the candidate segment set. The calculation and search are repeated with the searched segment as the new current segment until the leaf layer is reached. The position of the leaf layer segment calculated for the query key according to the formula is used as the predicted position.

[0029] The error parameter is the maximum permissible error specified when constructing the learned index. For any key, the absolute value of the difference between the predicted position and the true position given by the model does not exceed the error parameter. The segmentation refers to a continuous interval obtained by dividing the ordered data sequence of keys, where the mapping relationship from key to position is approximated by a linear function, and the approximation error does not exceed the corresponding error parameter.

[0030] The hierarchical organization of the model parameter layers is as follows. Leaf layer segments directly face the data page layer; their start key, slope, and intercept are fitted using the aforementioned error parameters, and the position calculated accordingly is the predicted position. Internal layer segments do not point to data records but to the segment set of the next layer. The fixed error parameter used for fitting these segments is smaller than the aforementioned error parameter, and the two do not share values. This fixed error parameter can be a value much smaller than the aforementioned error parameter, such as 4 or 8. From the leaf layer upwards, the number of segments in each layer decreases sequentially until a certain layer contains only one segment; this segment is the root layer segment.

[0031] During inference, the process can proceed layer by layer downwards from the root layer segment. After calculating the position in the current layer using the above formula and rounding it down, the rounded result gives the estimated index of the query key in the next layer. Since the fitting error of the internal layer segments does not exceed the fixed error parameter, the segment to which the query key actually belongs must fall within a set of candidate segments centered at this index and with the fixed error parameter as half-width. Searching within this set determines the segment to which the query key belongs; a binary search can be used for this search. The above calculation and search are repeated until the leaf layer is reached, and the position calculated for the leaf layer segment using the same formula is taken as the predicted position.

[0032] When using fitting methods other than linear, the parameter fields included in the segment can be defined analogously based on the selected model. When using a hierarchical nested learning index, such as multi-order model cascading, the segmentation described in this embodiment can be understood as sub-models of each order, and the construction and query process can be implemented analogously based on the algorithm of the selected model.

[0033] By adopting the above recursive organization method, the model parameter layer can cover all data records with a small number of levels. Each segment only saves three parameters: the start key, the slope, and the intercept, further compressing the volume occupied by the model parameter layer in the protected memory.

[0034] Step S3: Based on the predicted position, the pre-determined error parameters, and the number of data records that a single data page can hold, determine the candidate data page range for the query key.

[0035] Since there is a deviation between the predicted position and the actual position not exceeding the error parameter, the data record corresponding to the query key falls within a range of one error parameter width before and after the predicted position. The candidate data page interval is the range of data page numbers that may accommodate the data record corresponding to the query key, calculated according to the predicted position and the error parameter, thereby converting the range from the granularity of data records to the granularity of data pages. The input to this step can be the predicted position, the error parameter, and the number of data records that a single data page can accommodate; the output can be a continuous range of data page numbers. The data record corresponding to the query key must fall within the data pages contained in this interval.

[0036] The error parameter in the above steps can be predetermined during the index batch loading stage. The value of this parameter affects two aspects: increasing the value allows each segment to cover more data records, reducing the number of segments and decreasing the size of the model parameter layer. Simultaneously, the candidate data page range widens, increasing the number of data pages that need to be searched; decreasing the value has the opposite effect. In a TEE scenario, the parameter value must balance the cost of ensuring the model parameter layer can be completely placed in protected memory and the cost of locating data records.

[0037] In some implementations, the error parameter is predetermined as follows: Based on the number of data pages spanned by the preset candidate data page interval and the number of data records accommodated in a single data page, a lower and upper bound for the candidate error parameter value are determined; multiple candidate error parameter values ​​are generated between the lower and upper bounds according to a preset increasing rule; prefitting is performed on the input data or sampled data of the input data using each candidate error parameter value, and the volume of the model parameter layer corresponding to each candidate error parameter value is recorded; the candidate error parameter value that simultaneously satisfies the following two conditions and has the smallest value is determined as the error parameter: the rate at which the volume of the model parameter layer decreases as the candidate error parameter value increases satisfies a preset convergence condition; and the volume of the model parameter layer corresponding to the candidate error parameter value is not greater than the preset upper limit of the capacity available for storing the model parameter layer in the protected memory.

[0038] The lower and upper bounds of the candidate error parameter values ​​can be inferred from the number of data pages spanned by the acceptable candidate data page interval. For example, if the acceptable interval spans 1 to 16 pages, the lower and upper bounds of the candidate values ​​can be obtained by converting this number of pages with the number of data records contained in a single data page. The preset increment rule can adopt exponential increment, such as incrementing by integer powers of 2, so that the candidate values ​​cover several orders of magnitude; it can also adopt linear enumeration, or perform a coarse-grained scan first and then a fine-grained scan within the interval of interest.

[0039] Perform prefitting once for each candidate value and record the volume of the generated model parameter layer. This yields a discrete curve with the error parameter on the horizontal axis and the volume of the model parameter layer on the vertical axis. Within a small range of error parameters, this curve typically decreases rapidly. However, as the error parameter increases to a value determined by the data distribution complexity, the rate of decrease slows down, and further increasing the error parameter no longer provides significant benefits in compressing the model parameter layer volume. When the input data volume is large, prefitting can be performed only on sampled data to reduce evaluation overhead.

[0040] The determination of the error parameter is subject to two conditions: a convergence condition requiring that the value falls within a segment where the rate of descent of the aforementioned curve has slowed down, and a capacity condition requiring that the volume of the model parameter layer corresponding to this value does not exceed the preset upper limit of the protected memory's capacity for storing the model parameter layer. This upper limit is denoted as... The volume of the model parameter layer is pre-defined by the deployer. The volume of the parameter layer monotonically decreases as the error parameter increases, and all candidate values ​​after the convergence point fall within a relatively flat volume range. Therefore, the convergence condition and the capacity condition can usually be satisfied simultaneously; the volume corresponding to the convergence point is still greater than... At this point, larger error parameters can be taken along the candidate sequence until the volume is no greater than [the specified value]. By selecting the minimum value among the candidate values ​​that simultaneously satisfy both conditions, the candidate data page range can be made as narrow as possible while meeting the capacity constraint. The above quantitative evaluation also applies to other construction parameters where there is a similar trade-off between model parameter volume and query cost, such as the hierarchical configuration in a hierarchically nested learned index.

[0041] In some implementations, the values ​​of the plurality of candidate error parameters form an increasing sequence. , The integer is greater than 1; the determination of the preset convergence condition includes: for According to the formula Calculate the criterion value, where, For the first in the increasing sequence The candidate error parameter values ​​are: for The corresponding volume of the model parameter layer, For the first A set of criteria values; when the absolute value of the difference between each criterion value and 1 is not greater than the first preset value, the condition is met for the first time. The serial number of the difference between 1 and the second preset value Using the sequence number as the boundary, the preset convergence condition is determined. The condition is established when all criterion values ​​are greater than the third preset value; the condition is met for the first time. The serial number greater than the fourth preset value Using the sequence number as the boundary, the preset convergence condition is determined. The condition is met if no sequence number satisfies the above criteria. When, it is determined that the preset convergence condition is... The office was established.

[0042] Criterion value It is obtained by multiplying the volume ratio of two adjacent candidate values ​​by the value ratio, and is used to characterize the relative rate at which the volume of the model parameter layer decreases as the error parameter increases.

[0043] When the absolute value of the difference between each criterion value and 1 is not greater than a first preset value, the key distribution of the input data is determined to be a complex distribution. The first preset value can be 0.2. In this case, the value that first satisfies the condition is taken. The serial number of the difference between 1 and the second preset value ,by As the error parameter, the second preset value can be between 0.01 and 0.02, for example, 0.015.

[0044] When all criterion values ​​are greater than the third preset value, the key distribution of the input data is determined to be a simple distribution. The third preset value can be 1.2. In this case, the value that is first satisfied is taken. The serial number greater than the fourth preset value ,by As the error parameter, the fourth preset value can be 0.2.

[0045] In both cases, there is no sequence number that satisfies the above criteria. When the preset convergence condition is determined to be at the end of the sequence... The office was established to This serves as the error parameter.

[0046] In some implementations, the error parameter can be predetermined in the following manner: using the key distribution statistical features of the input data as input features, and using the weighted value of the total volume of the model parameter layer and the search cost within the candidate data page interval as the optimization objective, the error parameter is determined by searching within a candidate value range that ensures the volume of the model parameter layer is not greater than the preset upper limit of the capacity available for storing the model parameter layer in the protected memory through a machine learning model.

[0047] This method, parallel to the aforementioned quantitative evaluation method, can be adopted when the parameter value space is large and the cost of performing prefitting one by one is high, thus avoiding the overhead of evaluating one by one in a large value space. The key distribution statistical features can be the cumulative distribution approximation of the key distribution, quantiles, etc. The optimization objective is the weighted value of the total volume of the model parameter layer and the search cost within the candidate data page interval. The machine learning model can be a regression prediction model or a reinforcement learning model. The search is conducted within the candidate value range that ensures the volume of the model parameter layer does not exceed the capacity upper limit, and the applied capacity condition can be consistent with the aforementioned quantitative evaluation method.

[0048] By determining the error parameters in the above manner, it can be ensured that the volume of the model parameter layer can fall within the available capacity of the protected memory under different data distributions, while avoiding the increase in search cost caused by excessively large error parameter values ​​leading to an excessively wide candidate data page range.

[0049] Step S4: Based on the historical deviation statistics maintained within the trusted execution environment, determine the predicted page and at least one prefetched page from the candidate data page interval. The historical deviation statistics characterize the deviation of the actual position of the data record in the historical query from the predicted position.

[0050] The process of locating the data record corresponding to the query key from the candidate data page range is also known as last-mile verification. This range may span multiple data pages, which are stored in encrypted form at a storage level outside the trusted execution environment. Retrieving any page requires initiating a cross-boundary call. As the process proceeds page by page along this range, the number of cross-boundary calls accumulates with the deviation between the predicted and actual locations.

[0051] According to this embodiment, before initiating data page retrieval, the most likely direction or range of the actual location relative to the predicted location in this query can be predicted based on the historical deviation statistics. The data page where the predicted location is located is the predicted page, and the data pages selected within the candidate data page interval according to the above prediction, excluding the predicted page, are the prefetched pages. The number of prefetched pages can be one or more.

[0052] The historical deviation statistics reside in the protected memory of the trusted execution environment. Reading and updating are performed within this environment, without generating cross-boundary calls. Its specific form is not limited, as long as it can record the deviation pattern between the actual position and the predicted position in historical queries, and can be used to predict the direction or range of data page acquisition.

[0053] Step S5: Obtain the ciphertext of the predicted page and the prefetched page in batches through cross-boundary calls.

[0054] In this embodiment, the predicted page and the prefetched page are combined in a single cross-boundary call, and their ciphertext is retrieved together. Compared to the method of initiating independent calls page by page along the candidate data page interval, the number of cross-boundary calls is reduced from multiple to one, and the number of ciphertext data pages transmitted in a single call is correspondingly increased.

[0055] Step S6: In the trusted execution environment, first decrypt the prediction page and search for the query key in the decrypted prediction page. If the query key is not found in the prediction page, then decrypt the prefetch page and continue searching until the data record corresponding to the query key is located.

[0056] The batch-retrieved encrypted data pages can be decrypted on demand within the trusted execution environment. First, the prediction page is decrypted, and then the query key is searched within the decrypted plaintext data pages. Data records within the data pages are arranged in ascending order of key value, and the search within the page can employ a binary search.

[0057] When the query key is found within the prediction page, the corresponding data record is directly output, and the prefetch page does not need to be decrypted. In this case, the prefetch page only transmits one or more pages of ciphertext without incurring additional decryption overhead. If the query key is not found within the prediction page, the prefetch page is decrypted and the search continues. If the query key is still not found within the prefetch page, it is necessary to continue acquiring and searching for unacquired data pages within the candidate data page range, or determine that the query key does not exist.

[0058] Step S7: Update the historical deviation statistics based on the deviation relationship between the actual position of the located data record in the data page layer and the predicted position.

[0059] Once the data record is located, its true location can be obtained. In this embodiment, the historical deviation statistics are updated according to the deviation relationship between the true location and the predicted location. The updated statistics can be used for the prediction in step S4 in the next query. The update is completed within the trusted execution environment and does not generate cross-boundary calls. The prediction in step S4 is consecutive with the update in this step, so that the selection of the prefetch page gradually conforms to the actual deviation pattern of the data as the query progresses.

[0060] Through steps S4 to S7 of this embodiment, last-mile verification is no longer an independent cross-boundary probe initiated page by page along the candidate data page interval, but a combined operation of batch retrieval and on-demand decryption. What might have previously required multiple independent cross-boundary calls is now merged into a single batch call, reducing the number of cross-boundary calls. Prefetched pages do not require decryption when the predicted page is hit, ensuring that prefetching does not increase the computational overhead of decryption.

[0061] The above describes the processing procedure for point queries. This embodiment can also handle range queries. When the learning index comprises multiple index instances with progressively increasing sizes, and the protected memory of the trusted execution environment maintains an incremental buffer in an ordered structure, range queries can be processed as follows. The data records in the incremental buffer include keys, values, and timestamps, where data records with null values ​​are marked as deleted.

[0062] In some implementations, in response to a range query request carrying a lower bound key and an upper bound key, the following steps are performed for each index instance: inferring the predicted position, determining the candidate data page range, determining and batch acquiring the predicted page and the prefetched page, decrypting and searching, and updating the historical deviation statistics, all using the lower bound key as the query key. This locates the data page to which the lower bound key belongs in the data page layer of the index instance. Starting from the data page located in each index instance, subsequent encrypted data pages are batch acquired through cross-boundary calls and decrypted within the trusted execution environment. Data records with keys not less than the lower bound key and not greater than the upper bound key are filtered within the page until a data record with a key greater than the upper bound key is found. For the data records filtered by each index instance and the data records in the incremental buffer whose keys fall between the lower bound key and the upper bound key, a multi-way merge is performed within the trusted execution environment. For multiple data records with the same key, the data record with the latest timestamp is retained, and data records marked for deletion are removed to obtain the range query result.

[0063] The location process for range queries is the same as for point queries, using the lower bound key as the query key to execute steps S2 to S7. The difference is that the goal is not to retrieve a single data record, but to determine the data page to which the lower bound key belongs. This process also involves determining and batch acquiring the predicted page and the prefetched page. After location is completed, the historical deviation statistics are updated according to the deviation relationship. Range queries and point queries share the same historical deviation statistics and do not need to be maintained separately for each query type.

[0064] Starting from the located data page, subsequent encrypted data pages can be retrieved in batches via cross-boundary calls. After decryption within the trusted execution environment, the data records within the page are filtered, retaining those with keys no less than the lower bound key and no greater than the upper bound key. The scan on that index instance ends when a data record with a key greater than the upper bound key appears within the page.

[0065] The data records filtered by each index instance, and the data records in the incremental buffer whose keys fall between the lower and upper bound keys, can be merged using a multi-way merge within the trusted execution environment. When multiple data records exist for the same key, the record with the latest timestamp is retained. If this record is marked for deletion, the key is removed from the results. The merged result is the range query result.

[0066] The positioning stage of range queries reuses the inference and adaptive prefetching process of point queries, both of which use batch retrieval and on-demand decryption, and there is no need to maintain a separate set of historical deviation statistics for range queries.

[0067] Please refer to Figure 2 , Figure 2This is a schematic diagram of the system architecture of a learning index query system based on a trusted execution environment (TEE) provided as an exemplary embodiment of this application. The TEE, REE, and external storage constitute a three-layer collaborative structure. The TEE manages confidential computation and index state; the REE handles memory caching and cross-boundary interaction of encrypted data pages; and the external storage is used for persistent storage of large-volume encrypted data pages. Each module is deployed in layers according to the sensitivity of the data it processes and its computational overhead.

[0068] The protected memory of TEE can deploy a model parameter storage module, a model inference module, an incremental buffer module, a historical deviation statistics module, an encryption / decryption and integrity verification module, and an index building module.

[0069] The model parameter storage module stores all model parameter layers in plaintext format and resides permanently in protected memory, serving as the data source for the model inference phase.

[0070] The model inference module can receive query keys, read parameters from the model parameter storage module, infer prediction positions layer by layer downwards starting from the root layer segment, and determine candidate data page intervals. This module operates entirely within the TEE (Time-of-Effect) and does not generate cross-boundary calls.

[0071] The incremental buffer module resides in protected memory and organizes the most recent insertion, modification, and deletion records in an ordered structure. During a query, the system first searches within this module, and a flush is triggered when its volume reaches a preset threshold.

[0072] The historical deviation statistics module is used to maintain statistical information on the deviation between the actual location and the predicted location in historical queries. This module can update the statistical information after each query and provide a basis for predicting the direction or range in subsequent queries.

[0073] The encryption / decryption and integrity verification module can decrypt and verify the ciphertext data pages retrieved from the REE side, and encrypt the plaintext data pages to be written to the REE side and generate integrity tags.

[0074] The index building module is used for building, flushing, and tiered merging of index instances.

[0075] The REE can deploy a data page caching module and a cross-boundary interface module in its memory. The data page caching module caches data pages of a portion of the index instances in encrypted form, reducing access to external storage. The cross-boundary interface module can receive data page retrieval requests from the TEE and return the specified encrypted data pages to the TEE. This module can also receive encrypted data pages written from the TEE, completing the corresponding cache write or handover for persistence.

[0076] A data page persistence module can be deployed in external storage to store the data pages of large index instances in encrypted form.

[0077] This section describes the interaction methods of each module. During query execution, the model inference module only accesses the incremental buffer module, model parameter storage module, and historical deviation statistics module within the TEE; no cross-boundary calls occur at this stage. When candidate data pages are needed, the model inference module determines the predicted page and pre-fetched page based on the predictions provided by the historical deviation statistics module. The encryption / decryption and integrity verification module, via the cross-boundary interface module, requests the ciphertext of the aforementioned data pages in batches from the data page caching module or data page persistence module. After the retrieved ciphertext is decrypted as needed, the last-mile verification is completed within the TEE, and the historical deviation statistics module is called back to update the statistical information.

[0078] When the incremental buffer module triggers a flush or an index instance triggers a merge, the index building module generates a new index instance. The index building module writes the model parameter layer of the new instance to the model parameter storage module, and after encrypting the data pages of the new instance through the encryption / decryption and integrity verification module, writes them out to the REE side or external storage through the cross-boundary interface module.

[0079] In some implementations, the learning index includes multiple index instances with progressively increasing sizes, each index instance including the model parameter layer and the data page layer; the storage layers outside the trusted execution environment are at least two layers with progressively decreasing access rates and progressively increasing storage capacities; storing the model parameter layer in plaintext in the protected memory of the trusted execution environment and storing the data page layer in ciphertext in the storage layers outside the trusted execution environment includes: storing the model parameter layers of each index instance in plaintext in the protected memory of the trusted execution environment; storing the data page layers of each index instance in ciphertext in the at least two layers with progressively decreasing access rates, in ascending order of size; wherein, the at least two layers include the memory of the rich execution environment and the storage medium outside the memory of the rich execution environment, the data page layers of index instances with a size smaller than a preset size threshold are stored in ciphertext in the memory of the rich execution environment, and the data page layers of index instances with a size not less than the preset size threshold are stored in ciphertext in the storage medium outside the memory of the rich execution environment.

[0080] The index instance refers to a self-contained learning index, which includes a model parameter layer and a data page layer, and can independently locate data records from the query key. The multiple index instances can be tiered by capacity, with the capacity of adjacent levels increasing at a fixed ratio. Smaller levels contain data written more recently and with newer versions.

[0081] The model parameter layer of each index instance is written to the model parameter storage module in plaintext and resides in protected memory. The model parameter layer of a single index instance is compact, and the total size of the model parameter layers of multiple index instances is still limited within the available capacity of the protected memory.

[0082] The data page layers of each index instance are distributed according to its size. For index instances whose size is smaller than the preset size threshold, their data page layers are stored in encrypted form in the REE memory where the data page cache module resides. For index instances whose size is not smaller than the threshold, their data page layers are stored in encrypted form in the external storage where the data page persistence module resides. According to this rule, for each index instance from smallest to largest size, its data page layers fall sequentially at levels from highest to lowest access speed and from smallest to largest storage capacity.

[0083] The aforementioned at least two layers can be further expanded. When the deployment scenario involves lower-level storage media such as remote object storage, it can be expanded to a four-layer structure of protected memory for the TEE, memory for the REE, local disk, and remote object storage. Alternatively, the external storage can be directly replaced with remote object storage, retaining a three-layer structure. The index instances carried by each layer are still allocated incrementally according to size and version. Smaller and newer instances are placed in layers with higher access rates, while larger and older instances are placed in layers with lower access rates but larger capacity. This expansion does not change the principle that the model parameter layer resides entirely in protected memory, while the data page layer is placed in encrypted form outside of this memory. The only difference lies in the physical medium where the data page layer is located.

[0084] By adopting the above-mentioned hierarchical placement, the data pages of smaller index instances can be retrieved directly from REE memory, reducing access to external storage; the data pages of larger index instances are placed in external storage with larger capacity, so that the amount of data that the index can carry is no longer limited by the capacity of REE memory.

[0085] The index instance construction process performed by the index building module is as follows.

[0086] In some implementations, the model parameter layer and the data page layer are pre-constructed as follows: For the key-ordered input data, a piecewise fitting is performed on the key-to-position mapping relationship using the error parameter to generate a leaf layer segment set. Each segment includes a starting key and a fitting parameter, and the prediction error of the data record in each segment of the leaf layer segment set does not exceed the error parameter. The piecewise fitting is repeated using the starting key of each segment in the leaf layer segment set as new ordered data, generating inner layer segments layer by layer until the fitting result contains only one segment, thus obtaining the root layer segment. The generated layer segments are written as the model parameter layer in plaintext to the protected memory of the trusted execution environment. The input data is divided into data pages according to the number of data records that a single data page can hold, encrypted, and then written out to a storage level outside the trusted execution environment.

[0087] The process begins with the leaf layer. For the ordered input data, piecewise fitting is performed. A linear function is used to approximate the mapping relationship from key to position segment by segment, ensuring that the difference between the predicted and actual positions of any data record within each segment does not exceed the stated error parameter, thus obtaining a set of leaf layer segments. The piecewise fitting can be performed as follows: starting from the first record of the current segment, subsequent records are included one by one, while maintaining a feasible slope interval that ensures the prediction error of all included records does not exceed the stated error parameter. This interval narrows accordingly with each included record. When a record makes the interval empty (i.e., no slope can satisfy the error requirement for that record), the current segment ends, and that record is used as the starting record for a new segment to continue fitting. At the end of each segment, its starting key, slope, and intercept are recorded. This method completes the leaf layer fitting by scanning the input data sequentially once; the time required is proportional to the amount of input data. The number of data records B that a single data page can hold is calculated by converting the capacity of the data page into the size of a single data record. For example, if the data page size is 4KB and a single data record is 16 bytes consisting of an 8-byte key and an 8-byte record identifier, then B can be 256.

[0088] After the leaf layer is generated, the starting key of each segment of the leaf layer is taken as a new set of ordered data, and the above segmented fitting is repeated on it to obtain the inner layer segments. The error parameter used for the inner layer fitting is a fixed error parameter smaller than the above error parameter. This process is repeated layer by layer upwards, with the number of segments in each layer decreasing sequentially, until the fitting result of a certain layer contains only one segment, which is the root layer segment. At this point, all the layer segments together constitute the model parameter layer.

[0089] Each segment is written to the model parameter storage module in plaintext as a model parameter layer. The input data is divided into multiple data pages according to the number of data records that a single data page can hold. Each data page is encrypted by the encryption / decryption and integrity verification module and then written to the REE side or external storage through the cross-boundary interface module, forming the data page layer of this index instance.

[0090] In some embodiments, this application further includes: maintaining an incremental buffer in an ordered structure in the protected memory of the trusted execution environment, wherein the incremental buffer and the data records in the data page layer both include a key, a value, and a timestamp, wherein data records with a null value identifier are data records marked as deleted; in response to a query request carrying the query key, first searching for the query key in the incremental buffer, and when the query key is found in the incremental buffer, outputting the data record corresponding to the query key and ending the processing of this query request; when the query key is not found in the incremental buffer, performing the inference of the predicted position, the determination of the candidate data page interval, the determination and batch acquisition of the predicted page and the prefetch page, and the decryption and search sequentially on each of the multiple index instances in ascending order of size, until the query key is found or all the multiple index instances have been processed.

[0091] The incremental buffer is maintained in an ordered structure by the incremental buffer module and resides in protected memory. Its data records use the same fields as those in the data page layer, including key, value, and timestamp. In other words, data records in the data page layer also include key, value, and timestamp, where data records with a null value are marked as deleted. The timestamp is used to distinguish between older and newer versions when multiple data records exist for the same key, and serves as the basis for retaining the latest version and removing records marked as deleted during key comparison in the subsequent index instance merging phase. A data record with a null value indicates that the record corresponding to that key has been deleted. In addition to key, value, and timestamp, the data record may also include other fields, such as an operation type field that identifies the write operation type corresponding to this record.

[0092] Because the incremental buffer carries the most recently written data, resides in protected memory, and does not generate cross-boundary calls during lookups, the query key is first searched in the incremental buffer during a query. If found in the incremental buffer, it is considered the latest version of the key, and the corresponding data record can be directly output, ending the query without accessing individual index instances.

[0093] If the query key is not found in the incremental buffer, the index instances are processed sequentially in ascending order of size. Smaller instances have newer versions, and prioritizing their processing ensures the query ends as soon as a newer version is found. For each index instance, the following steps are performed sequentially: inference of the predicted position, determination of candidate data page ranges, determination of predicted and prefetched pages, batch retrieval, and decryption and search. When the query key is found in an index instance, the latest version of that key is obtained, and the query ends. If the key is not found after processing all index instances, it is determined that the query key does not exist. To reduce unnecessary access to index instances that do not contain the target key, a member judgment structure can be configured for each index instance to determine whether the key might exist in the instance before inference. For instances determined not to exist, their data page retrieval is skipped.

[0094] According to this implementation, the incremental buffer written to protected memory receives the latest data writes and enables queries to hit the nearest index. The processing of multiple index instances in ascending order of size allows queries to end earlier when a newer version is hit, significantly reducing access to data page layers located outside the trusted execution environment.

[0095] In addition to performing the batch builds described above, the index building module is also configured for incremental data flushing and hierarchical merging of index instances.

[0096] In some embodiments, this application further includes: in response to an insert request, a modification request, or a deletion request, appending data records to the incremental buffer in the form of an append insertion, wherein the value of the data record appended in the deletion request is the null identifier, and the appending is completed within the trusted execution environment; when the volume of the incremental buffer reaches a preset write threshold, constructing a minimum-sized index instance using the ordered content of the incremental buffer as input data, writing the model parameter layer of the constructed index instance in plaintext to the protected memory of the trusted execution environment, encrypting the data page layer of the constructed index instance and writing it out to a storage level outside the trusted execution environment, and clearing the incremental buffer.

[0097] All write requests—insertion, modification, and deletion—can be processed by appending data records to the incremental buffer, without directly modifying existing index instances. Insertion and modification append data records consisting of a key and a new value; deletion appends data records with the null identifier. For example, if the key of the record to be deleted is... At that time, append a key to the increment buffer. The three types of operations are unified into append operations on the incremental buffer, all completed within the TEE, without generating cross-boundary calls. When the same key is written multiple times, multiple data records for that key can exist in the incremental buffer, distinguished by timestamps, with the latest timestamp used for querying.

[0098] The incremental buffer grows in size as writes occur. When its size reaches a preset flush threshold, a flush is triggered: using the current ordered content of the incremental buffer as input data, a minimal index instance is constructed according to the aforementioned pre-construction method. Its model parameter layer is written to the model parameter storage module, and its data page layer is encrypted and written to a storage level outside the trusted execution environment. Subsequently, the incremental buffer is cleared to accommodate subsequent writes. The instance generated by the flush is the smallest and most up-to-date, and can be accessed first when subsequent queries are processed in ascending order of size.

[0099] In some implementations, this application further includes: when another index instance already exists at the scale level to which the constructed index instance belongs, obtaining the encrypted data pages of the two index instances in batches through cross-boundary calls and decrypting them within the trusted execution environment; performing multi-way merging on the decrypted data records; retaining the data record with the latest timestamp among multiple data records with the same key and removing data records marked for deletion; constructing an index instance at the next scale level based on the merging result, the constructed index instance at the next scale level using the error parameters of the merged index instance; before the construction of the index instance at the next scale level is completed, routing the query request to the merged index instance for execution; and after the construction of the index instance at the next scale level is completed and online, releasing the resources occupied by the model parameter layer of the merged index instance in the protected memory.

[0100] A merge is triggered when another index instance already exists at the same size level as the newly created index instance. The size level of an index instance refers to the tier to which its capacity belongs; the capacity of adjacent size levels increases according to the aforementioned proportional factor. Size level and the storage tier where the data page resides are two different concepts and do not have a one-to-one correspondence. During the merge, the encrypted data pages of the two index instances are retrieved in batches via the cross-boundary interface module. These are then decrypted within the TEE by the encryption / decryption and integrity verification module. A multi-way merge is performed on the decrypted data records. In the multi-way merge, if multiple data records exist for the same key, the record with the latest timestamp is retained. If this record is marked for deletion, the key is removed. The merge result is used as input data to construct the index instance for the next size level.

[0101] The newly constructed index instance at the next scale level uses the error parameters of the merged instance, eliminating the need to re-perform the aforementioned quantitative evaluation of the error parameters on the merged data, thus saving the overhead of re-evaluation.

[0102] During the merge process, the merged index instances remain online. Until the next scale-level index instance is built, query requests are still routed to the merged index instances for execution, and the query results are unaffected by the merge process. Only after the next scale-level index instance is built and online are the resources occupied by the model parameter layers of the two merged index instances in protected memory released. If another instance already exists at the scale level to which the merge result belongs, a merge can be triggered at the next higher level, forming a multi-level cascading effect.

[0103] In this way, insertion, modification and deletion are all completed by appending within the TEE, without needing to modify the external data page layer in real time; the incremental buffer is flushed to the smallest index instance according to the threshold, and the same level instances are then merged into larger-scale instances; during the merging period, the old instance takes over the query, and the old instance resources are released after the new instance comes online, so that the index remains queryable under continuous writing, while the resources occupied by the model parameter layer in the protected memory are controlled within a reasonable range.

[0104] Please refer to Figure 3 , Figure 3 This is a schematic diagram of a last-mile adaptive prefetching and bias update process provided for an exemplary embodiment of this application.

[0105] As shown in the figure, the model parameter layer first obtains the predicted position of the query key through layer-by-layer inference, and then calculates the candidate data page interval from the predicted position. Next, the candidate data page interval of the query key can be determined based on the predicted position, the pre-determined error parameters, and the number of data records that a single data page can hold.

[0106] In some implementations, determining the candidate data page range for the query key may include: according to a formula Determine the candidate data page range, wherein, For the predicted location, The error parameter is... The number of data records that can be contained in a single data page, where ⌊⌋ indicates rounding down.

[0107] As mentioned earlier, the actual location falls within the predicted location. Centered on, with error parameters Half-width recording granularity range Within. Divide the upper and lower bounds of this interval by... Rounded down, this can be converted into the data page number range shown in the formula above. This range is the output of the step in the diagram that determines the candidate data page range, and is used to subsequently determine the range between the predicted page and the prefetched page.

[0108] Historical deviation statistics can be used in different forms.

[0109] In some implementations, the historical deviation statistics include an integer direction counter stored in the protected memory of the trusted execution environment, the initial value of which is zero; determining the predicted page and at least one prefetch page from the candidate data page interval includes: using the data page where the predicted position is located as the predicted page; using the right neighbor page of the predicted page as the prefetch page when the integer direction counter is greater than zero; using the left neighbor page of the predicted page as the prefetch page when the integer direction counter is less than zero; and using both the left and right neighbor pages of the predicted page as the prefetch page when the integer direction counter is equal to zero; wherein, when the prefetch page determined according to the above rules exceeds the candidate data page interval, the data page adjacent to the predicted page within the candidate data page interval is used as the prefetch page; updating the historical deviation statistics includes: incrementing the integer direction counter by one when the actual position is greater than the predicted position; decrementing the integer direction counter by one when the actual position is less than the predicted position; and keeping the integer direction counter unchanged when the actual position is equal to the predicted position.

[0110] This method uses an integer direction counter to record the cumulative trend of the actual position's bias towards the predicted position in historical queries. The counter is stored in protected memory and initialized to zero. When determining the prediction page and the prefetch page, the data page containing the predicted position is first used as the prediction page. If the counter is greater than zero, it indicates that the actual position in historical queries is mostly biased to the right of the predicted position, so the right neighbor of the prediction page is used as the prefetch page; if the counter is less than zero, it indicates that it is mostly biased to the left, so the left neighbor is used as the prefetch page; if the counter is equal to zero, there is no obvious bias, so both the left and right neighbor pages are used as prefetch pages. If the prefetch page selected according to this rule exceeds the candidate data page interval, the data page adjacent to the prediction page within the candidate data page interval is used as the prefetch page, ensuring that the prefetch page always falls within the candidate data page interval.

[0111] After locating a data record, the counter is updated according to the relationship between the actual location and the predicted location: increment by one if the actual location is greater than the predicted location, decrement by one if the actual location is less than the predicted location, and remain unchanged if they are equal. The updated counter is used to predict the prefetch direction for the next query. If the candidate data page interval contains only one predicted page, prefetching is not initiated, and this query still only generates one cross-boundary call. This form only occupies the protected memory space of one integer variable, and its relative overall index size is negligible. Its prediction of the prefetch direction gradually aligns with the actual deviation trend of the data as the query progresses.

[0112] In some implementations, the historical deviation statistics include the mean deviation of the actual location of a data record from its predicted location in historical queries. with standard deviation The step of determining the prediction page and at least one prefetch page from the candidate data page interval includes: according to... Determine the range of pre-fetched locations, where The predicted position is defined as follows: the upper and lower bounds of the predicted position range are divided by the number of data records that a single data page can hold, and then rounded down to obtain the predicted page interval; the intersection of the predicted page interval and the candidate data page interval is taken, and the data page where the predicted position is located is taken as the predicted page, and the data pages in the intersection other than the predicted page are taken as the predicted pages; if there are no data pages other than the predicted page in the intersection, the data page in the candidate data page interval that is adjacent to the predicted page is taken as the predicted page.

[0113] This form uses the mean of the deviation with standard deviation Describes the distribution of the deviation between the actual location and the predicted location in historical queries. When determining the page to be fetched, the predicted location is used. Add the mean Centered on, with standard deviation The half-width value yields the prefetch location range for the recording granularity. Divide the upper and lower bounds of this range by the number of data records a single data page can hold, and round down to the nearest integer to convert it into a prefetch page interval. Take the intersection of this prefetch page interval and the candidate data page interval. The data page containing the predicted position is taken as the predicted page, and the data pages in the intersection other than the predicted pages are taken as prefetch pages. When the system initially has no historical query records or the historical deviation is constant... and Both can be zero, degenerating the prefetch location range to a single predicted location, with no other data pages besides the predicted page in the intersection. In this case, the data page adjacent to the predicted page within the candidate data page interval is taken as the prefetch page. Compared to the previous form that only predicts the left and right directions, this form predicts the direction and magnitude of the offset based on the mean and standard deviation of the deviation. When the deviation is large and the true location spans multiple data pages, the prefetch page can cover the more likely location to be hit.

[0114] and A sliding window representing the deviations of the most recent queries can be maintained in protected memory, estimated from the samples within the window. After each query, the deviation sample between the actual position and the predicted position is added to the sliding window, the oldest sample is discarded, and the calculation is recalculated based on the samples within the window. and This serves as an update to the historical deviation statistics.

[0115] In addition to the two forms mentioned above, historical deviation statistics can also be presented in other forms such as cumulative deviation mean and time decay histograms, all of which are maintained and updated within protected memory. Historical deviation statistics can be maintained as a single set for the entire index, or multiple sets can be maintained for each partition, allowing different partitions to be prefetched according to their local deviation patterns.

[0116] In some embodiments, this application further includes: when the query key is not found in the prefetch page and the query key is greater than the smallest key in the decrypted data page but less than the largest key in the decrypted data page, determining that the query key does not exist in the data page layer; when the query key is not found in the prefetch page and the query key is less than the smallest key in the decrypted data page or greater than the largest key in the decrypted data page, determining the side of the query key relative to the decrypted data page according to the size relationship between the query key and the smallest and largest keys in the decrypted data page, and sequentially initiating subsequent cross-boundary calls towards the boundary of the candidate data page interval corresponding to that side, obtaining the ciphertext data page that has not yet been obtained in the candidate data page interval, and decrypting it in the trusted execution environment and continuing to search for the query key until the query key is found or the boundary of that side is reached; when the query key is still not found after reaching the boundary of that side, determining that the query key does not exist in the data page layer.

[0117] Figure 3 The processing path for a match is shown. Further explanation is provided here for cases where a match is not found after first decrypting the prediction page and searching, and then decrypting the prefetched page as needed. When both the prediction page and the prefetched page have been decrypted and searched but the query key is still not found, two different cases can be handled based on the relationship between the query key and the keys in the decrypted data pages. When the direction counter is zero, the prediction page and its two adjacent pages retrieved in a batch are contiguous in the key space. When the query key is greater than the smallest key in the decrypted data page but less than the largest key, it indicates that the query key falls within a covered and contiguous key range but has not appeared. Based on the ordered key sequence of the data page layer, it can be directly determined that the query key does not exist in the current index instance, and no further cross-boundary calls are initiated. If the query key is less than the smallest key in the decrypted data page, or greater than the largest key, it indicates that the actual location may lie in a data page that has not yet been retrieved on one side of the decrypted data page. This side can be determined based on the relationship between the query key and the smallest / largest key. Subsequent cross-boundary calls are then initiated sequentially towards the boundary of the candidate data page interval from that side, retrieving the unretrieved ciphertext data pages within the candidate data page interval page by page. After decryption, the search continues until the query key is found or the boundary of that side is reached. If the query key is not found even after reaching the boundary of that side, it can be determined that the query key does not exist in the data page layer. The smallest and largest keys in the decrypted data page used for the above comparison are the keys of the first and last data records of that page.

[0118] This processing provides a supplementary path when prefetching fails. In practice, most queries can be hit within the prediction page or prefetch page, eliminating the need for subsequent cross-boundary calls. Fetching continues to one side only when the prediction deviation is small and the actual position exceeds the already fetched data page.

[0119] Please refer to Figure 4 , Figure 4 This is a schematic diagram illustrating an example of a query process provided in an exemplary embodiment of this application. The following is in conjunction with... Figure 4 The complete processing procedure of this embodiment will be illustrated using a typical scenario.

[0120] This example continues the scenario of the encrypted database table mentioned earlier. The number of data records that a single data page can hold. We can choose an example value that is easy to convert, such as the one used in this example. That is, each data page stores two data records. Error parameter This can be predetermined through quantitative evaluation; in this example, we take... A learning index can use multiple index instances of progressively increasing size, with the capacity of adjacent levels increasing proportionally to a factor. You can choose an example value, such as... When the incremental buffer reaches the flush threshold, it is flushed to the smallest index instance, which can be set to an example value based on the available capacity of the protected memory.

[0121] Query request carrying query key Processing begins within the trusted execution environment.

[0122] First search in the incremental buffer In this example, the incremental buffer did not match the key, so the query proceeded to the index instance. Multiple index instances were processed sequentially in ascending order of size. The following explanation uses the processing of one index instance as an example.

[0123] The query then proceeds to the model inference phase. This phase reads the model parameter layer resident in protected memory, inferring layer by layer downwards from the root layer. The entire process is completed within a trusted execution environment, without generating cross-boundary calls. (See reference...) Figure 4 The root layer segment is (7, 0.025, 0), with a starting bond of 7, a slope of 0.025, and an intercept of 0. According to the formula... Substitute Calculate the position of this layer The integer part is rounded down to 1, pointing to the segment with index 1 in the next layer. The next layer determines the candidate segment set centered on the rounded position and using the fixed error parameter of the inner layer as the half-width, and then searches within it to determine the segment. The section to which it belongs. (See reference.) Figure 4The next layer, centered on index 1 and using the fixed error parameter of the inner layer as half-width, forms a candidate segment set. This set includes two segments: index 0 and index 1. The segment at index 1 (127, 0.123, 13) has a starting key of 127 that is already large. Therefore, we backtrack to index 0 within the candidate segment set to determine the segment to which it belongs (7, 0.091, 0).

[0124] Using the segment (7, 0.091, 0) as the leaf layer segment, according to the formula... Calculate the position Round down to 3. Because this layer is a leaf layer, we get... Predicted location . Reference Figure 4 The data record sequence at the bottom, with the data record at number 3 being 43.

[0125] Determining the candidate data page range. According to the formula... Substitute , , The candidate data page range is [⌊1 / 2⌋,⌊5 / 2⌋] = [0,2], meaning the candidate data pages are pages 0, 1, and 2. Page 0 contains records numbered 0 and 1 {7,40}, page 1 contains records numbered 2 and 3 {42,43}, and page 2 contains records numbered 4 and 5 {49,58}.

[0126] Determining the prediction page and the prefetch page. Predicted position 3 falls on page 1, so page 1 is the prediction page. Taking historical deviation statistics in the form of an integer direction counter as an example, assuming the current counter value is greater than zero, it indicates that the actual position in historical queries is mostly biased to the right of the predicted position, so the right adjacent page of the prediction page, i.e., page 2, is taken as the prefetch page. Page 2 falls within the candidate data page interval [0,2], so no adjustment is needed.

[0127] Proceed to batch retrieval. The predicted page 1 and the prefetched page 2 are combined into a single cross-boundary call, retrieving their ciphertexts together. Compared to initiating independent calls page by page from 0 to 2, this only involves a single cross-boundary call.

[0128] Proceed to on-demand decryption and search. First, decrypt the prediction page 1 within the trusted execution environment to obtain plaintext records {42,43}, and then search within it. No results found. Decrypting the prefetched page 2 yields plaintext record {49,58}, from which the following was found. The system locates the corresponding data record and outputs the query results. This query was thus completed within a single cross-boundary call. Page 2 of the prefetched page was decrypted because the predicted page was not found, avoiding the multiple independent cross-boundary calls required to probe page by page along the candidate data page range.

[0129] Next, a deviation callback will be performed. The actual position is sequence number 4, which is greater than the predicted position 3, so the integer direction counter is incremented. The updated counter is used for the next query to predict the prefetched direction on the right side of the prediction page. (Refer to...) Figure 4 The arrow pointing from the prediction page to the data record on the right in the figure indicates the process of the actual position shifting to the right relative to the predicted position and the pre-fetching to the right accordingly.

[0130] The above describes the complete process of a single point query. Here, the write operation and index evolution process are explained together. When performing a delete operation on the table, a data record with a null identifier is appended to the incremental buffer. This appending is completed within the trusted execution environment and does not generate cross-boundary calls. Subsequent queries for this key first hit the delete flag in the incremental buffer, thus determining that the key has been deleted. When the volume of the incremental buffer reaches the flush threshold, a minimum-sized index instance l0 is constructed using its ordered content. The model parameter layer of l0 is written to protected memory, and the data page layer is encrypted before being written out. Subsequent flushing generates another minimum-sized index instance, belonging to the same size level as the existing l0, triggering a merge: the encrypted data pages of both instances are retrieved in batches and decrypted within the trusted execution environment. A multi-way merge is performed, retaining the record with the latest timestamp for the same key and removing records marked as deleted. The merge result is used to construct the next-sized index instance l1, which uses the error parameters of the merged instance. During the merge, queries are still handled by the merged instance. Once L1 is online, the model parameter resources occupied by the merged instance in the protected memory are released.

[0131] As this example demonstrates, a single point query does not generate cross-boundary calls during the model inference phase. In the last-mile verification phase, a single batch cross-boundary call retrieves the predicted and prefetched pages and decrypts them as needed, thus locating the target record. Furthermore, write operations are completed via append-only insertions within protected memory, and the index is maintained in a queryable state through flushing and merging.

[0132] This application addresses the limitations of protected memory capacity and high cross-boundary call overhead in trusted execution environments. It separates the model parameter layer and data page layer of the learning index into storage layers outside the protected memory and outside the environment, respectively. This allows model inference to be completed within the environment without generating cross-boundary calls. Furthermore, it maintains historical query deviation statistics within the environment to predict page retrieval direction or range. The data pages required for last-mile verification are merged into a single batch cross-boundary call and decrypted as needed. While maintaining encrypted storage at the data page layer, this reduces the number of cross-boundary calls and decryption overhead during the query process. This frees the index from being limited by the protected memory capacity, providing a feasible method for performing queries on large-scale encrypted data in trusted execution environments.

[0133] Figure 5 An electronic device provided in at least one embodiment of this application includes a memory and a processor. The memory is used to store computer instructions that can be executed on the processor, and the processor is used to implement the learning-based index query method based on a trusted execution environment as described in any embodiment or implementation of this application when executing the computer instructions.

[0134] At least one embodiment of this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the learning-based index query method based on a trusted execution environment as described in any embodiment or implementation of this application.

[0135] Those skilled in the art will understand that the embodiments of this application can be provided as methods, systems, electronic devices, or computer program products, and can be implemented in a completely hardware, completely software, or a combination of hardware and software. The embodiments in this specification are described in a progressive manner, and identical or similar parts can be referred to mutually.

[0136] The processing flow and logical sequence depicted in the accompanying drawings are not necessarily required to be executed in the specific order or sequence shown. Where there is no conflict, the operation steps may be executed in a different order than that shown in the embodiments, or parallel processing may be used to achieve the desired result. Furthermore, the separation of the various system modules and components described above should not be construed as requiring such separation in all embodiments; the described program components and systems can typically be integrated into a single software or hardware product.

[0137] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit the scope of one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments of this specification should be included within the protection scope of one or more embodiments of this specification.

Claims

1. A learning-based index query method based on a trusted execution environment, characterized in that, The learned index includes a model parameter layer and a data page layer. The model parameter layer represents the mapping relationship from key to position, and the data page layer includes multiple data pages used to store data records in order of key size. The method includes: The model parameter layer is stored in plaintext in the protected memory of the trusted execution environment, and the data page layer is stored in ciphertext at a storage level outside the trusted execution environment. In response to a query request carrying a query key, the query key is inferred layer by layer based on the model parameter layer within the trusted execution environment to obtain the predicted position of the query key in the data page layer; Based on the predicted location, the predetermined error parameters, and the number of data records that a single data page can hold, the candidate data page range for the query key is determined; Based on the historical deviation statistics maintained within the trusted execution environment, a predicted page and at least one prefetched page are determined from the candidate data page interval. The historical deviation statistics characterize the deviation of the actual position of a data record in a historical query from the predicted position. The encrypted text of the predicted page and the prefetched page is obtained in batches through cross-boundary calls; Within the trusted execution environment, the prediction page is first decrypted and the query key is searched in the decrypted prediction page. If the query key is not found in the prediction page, the prefetch page is decrypted and the search continues until the data record corresponding to the query key is located. The historical deviation statistics are updated based on the deviation relationship between the actual position of the located data record in the data page layer and the predicted position.

2. The method according to claim 1, characterized in that, The learning index comprises multiple index instances with progressively increasing size, each index instance including the model parameter layer and the data page layer; the storage layers outside the trusted execution environment consist of at least two layers with progressively decreasing access rates and progressively increasing storage capacities; The model parameter layer is stored in plaintext in the protected memory of the trusted execution environment, and the data page layer is stored in ciphertext at a storage level outside the trusted execution environment, including: The model parameter layers of each index instance are stored in plaintext in the protected memory of the trusted execution environment; In order of increasing size of each index instance, the data page layers of each index instance are stored in encrypted form in at least two levels with decreasing access rates. The at least two levels include the memory of the rich execution environment and the storage medium other than the memory of the rich execution environment. The data page layer of the index instance with a size smaller than a preset size threshold is stored in the memory of the rich execution environment in encrypted form, and the data page layer of the index instance with a size not smaller than the preset size threshold is stored in encrypted form in the storage medium other than the memory of the rich execution environment.

3. The method according to claim 1, characterized in that, The model parameter layer includes multiple segments organized hierarchically and recursively. Leaf layer segments index the data pages in the data page layer with the error parameter, and inner layer segments index the next layer's segment set with a fixed error parameter smaller than the error parameter, and so on upwards until a unique root layer segment is formed. Each segment includes a start key, slope, and intercept. Within the trusted execution environment, the query key is inferred layer by layer based on the model parameter layer to obtain the predicted position of the query key in the data page layer, including: Using the root segment as the current segment, according to the formula Calculate the position of the query key in the next layer and round down, where, For the query key, The starting key for the current segment. The slope of the current segment. The intercept of the current segment. The calculated position; In the next layer, a candidate segment set is determined with the rounded-down position as the center and the fixed error parameter as the half-width. The segment to which the query key belongs is then searched within the candidate segment set. The calculation and search are repeated using the segment determined by the search as the new current segment until the leaf layer is reached. The position of the leaf layer segment calculated according to the formula for the query key is then used as the predicted position.

4. The method according to claim 1, characterized in that, Based on the predicted location, a pre-determined error parameter, and the number of data records that a single data page can hold, the candidate data page range for the query key is determined, including: According to the formula Determine the candidate data page range, wherein, For the predicted location, The error parameter is... The number of data records that can be contained in a single data page, where ⌊⌋ indicates rounding down.

5. The method according to claim 1, characterized in that, The historical deviation statistics include an integer direction counter stored in the protected memory of the trusted execution environment, the initial value of which is zero; Determining a prediction page and at least one prefetch page from the candidate data page interval includes: using the data page where the prediction position is located as the prediction page; using the right neighbor page of the prediction page as the prefetch page when the integer direction counter is greater than zero; using the left neighbor page of the prediction page as the prefetch page when the integer direction counter is less than zero; and using both the left and right neighbor pages of the prediction page as the prefetch page when the integer direction counter is equal to zero; wherein, when the prefetch page determined according to the above rules exceeds the candidate data page interval, the data page adjacent to the prediction page within the candidate data page interval is used as the prefetch page; Updating the historical deviation statistics includes: incrementing the integer direction counter by one when the actual position is greater than the predicted position, decrementing the integer direction counter by one when the actual position is less than the predicted position, and keeping the integer direction counter unchanged when the actual position is equal to the predicted position.

6. The method according to claim 1, characterized in that, The historical deviation statistics include the average deviation of the actual position of data records relative to the predicted position in historical queries. with standard deviation ; Determining the prediction page and at least one prefetch page from the candidate data page range includes: according to Determine the range of pre-fetched locations, where The predicted location; Divide the upper and lower bounds of the prefetch location range by the number of data records that a single data page can hold and round down to obtain the prefetch page range; The intersection of the prefetch page interval and the candidate data page interval is taken, and the data page where the predicted position is located is taken as the predicted page. The data pages in the intersection other than the predicted page are taken as the prefetch pages. If there are no data pages other than the predicted page in the intersection, the data page in the candidate data page interval that is adjacent to the predicted page is taken as the prefetch page.

7. The method according to claim 1, characterized in that, Also includes: If the query key is not found in the prefetch page, and the query key is greater than the smallest key in the decrypted data page but less than the largest key in the decrypted data page, it is determined that the query key does not exist in the data page layer. If the query key is not found in the prefetched page, and the query key is smaller than the smallest key or larger than the largest key in the decrypted data page, the side in which the query key is located relative to the decrypted data page is determined according to the size relationship between the query key and the smallest and largest keys in the decrypted data page. Subsequent cross-boundary calls are then initiated sequentially towards the boundary of the candidate data page interval corresponding to that side to obtain the ciphertext data page that has not yet been obtained in the candidate data page interval. After decryption in the trusted execution environment, the search for the query key continues until the query key is found or the boundary of that side is reached. If the query key is not found upon reaching the side boundary, it is determined that the query key does not exist in the data page layer.

8. The method according to claim 2, characterized in that, Also includes: Incremental buffers are maintained in an ordered structure in the protected memory of the trusted execution environment. Both the incremental buffers and the data records in the data page layer include keys, values, and timestamps, wherein data records with null values ​​are marked as deleted. In response to the query request carrying the query key, the query key is first searched in the incremental buffer. When the query key is found in the incremental buffer, the data record corresponding to the query key is output and the processing of this query request ends. If the query key is not found in the incremental buffer, the following steps are performed sequentially on each of the multiple index instances, in order of increasing size: inferring the predicted position, determining the candidate data page range, determining and batch acquiring the predicted page and the prefetched page, and decrypting and searching, until the query key is found or all multiple index instances have been processed.

9. The method according to claim 8, characterized in that, Also includes: In response to a range query request carrying a lower bound key and an upper bound key, the following steps are performed for each index instance: inferring the predicted position, determining the candidate data page range, determining and batch acquiring the predicted page and the prefetched page, decrypting and searching, and updating the historical deviation statistics, using the lower bound key as the query key, to locate the data page to which the lower bound key belongs in the data page layer of the index instance. Starting from the data page located in each index instance, subsequent encrypted data pages are obtained in batches through cross-boundary calls and decrypted within the trusted execution environment. Data records with keys not less than the lower bound key and not greater than the upper bound key are filtered within the page until a data record with a key greater than the upper bound key appears. The data records filtered from each index instance and the data records in the incremental buffer whose keys fall between the lower bound key and the upper bound key are merged in the trusted execution environment. For multiple data records with the same key, the data record with the latest timestamp is retained and the data records marked as deleted are removed to obtain the range query results.

10. The method according to claim 1, characterized in that, The model parameter layer and the data page layer are pre-constructed in the following manner: For input data with ordered key presses, a piecewise fitting is performed on the mapping relationship between key and position using the error parameter to generate a leaf layer segment set. Each segment includes a starting key and fitting parameters. The prediction error of the data record in each segment of the leaf layer segment set does not exceed the error parameter. Using the starting key of each segment in the leaf layer segment set as new ordered data, the segment fitting is repeatedly performed to generate internal layer segments layer by layer until the fitting result contains only one segment, thus obtaining the root layer segment. The generated segments are written in plaintext to the protected memory of the trusted execution environment as the model parameter layers. The input data is divided into data pages according to the number of data records that a single data page can hold, and then encrypted and written out to a storage layer outside the trusted execution environment.

11. The method according to claim 10, characterized in that, The error parameters are predetermined in the following manner: Based on the number of data pages spanned by the preset candidate data page interval and the number of data records contained in a single data page, the lower and upper bounds of the candidate error parameter values ​​are determined, and multiple candidate error parameter values ​​are generated between the lower and upper bounds according to a preset incrementing rule. Prefitting is performed on the input data or the sampled data of the input data with each candidate error parameter value, and the volume of the model parameter layer corresponding to each candidate error parameter value is recorded; The candidate error parameter value that simultaneously satisfies the following two conditions and has the smallest value among the multiple candidate error parameter values ​​is determined as the error parameter: the rate at which the volume of the model parameter layer decreases as the value of the candidate error parameter increases satisfies a preset convergence condition; The volume of the model parameter layer corresponding to the candidate error parameter value is no greater than the preset upper limit of the capacity available for storing the model parameter layer in the protected memory.

12. The method according to claim 11, characterized in that, The values ​​of the multiple candidate error parameters form an increasing sequence. , The integer is greater than 1; the determination of the preset convergence condition includes: for According to the formula Calculate the criterion value, where, For the first in the increasing sequence The candidate error parameter values ​​are: for The corresponding volume of the model parameter layer, For the first One criterion value; When the absolute value of the difference between each criterion value and 1 is not greater than the first preset value, the condition is met for the first time. The serial number of the difference between 1 and the second preset value Using the sequence number as the boundary, the preset convergence condition is determined. It was established; When all criterion values ​​are greater than the third preset value, the first satisfaction is achieved. The serial number greater than the fourth preset value Using the sequence number as the boundary, the preset convergence condition is determined. It was established; If there is no sequence number that satisfies the above criteria. When, it is determined that the preset convergence condition is... The office was established.

13. The method according to claim 10, characterized in that, The error parameter is predetermined in the following manner: using the key distribution statistical features of the input data as input features, and the weighted value of the total volume of the model parameter layer and the search cost within the candidate data page interval as the optimization objective, the error parameter is determined by searching within the candidate value range of the model parameter layer volume not exceeding the preset upper limit of the capacity available for storing the model parameter layer in the protected memory through a machine learning model.

14. The method according to claim 8, characterized in that, Also includes: In response to an insert request, a modification request, or a deletion request, a data record is appended to the incremental buffer in the form of an append insertion, wherein the value of the data record appended in the deletion request is the null identifier, and the appending is performed within the trusted execution environment; When the volume of the incremental buffer reaches a preset write threshold, the ordered content of the incremental buffer is used as input data to construct the smallest index instance. The model parameter layer of the constructed index instance is written to the protected memory of the trusted execution environment in plaintext. The data page layer of the constructed index instance is encrypted and written to a storage level outside the trusted execution environment, and the incremental buffer is cleared.

15. The method according to claim 14, characterized in that, Also includes: When another index instance already exists at the scale level to which the constructed index instance belongs, the encrypted data pages of the two index instances are obtained in batches through cross-boundary calls and decrypted in the trusted execution environment. The decrypted data records are then merged in multiple ways. For multiple data records with the same key, the data record with the latest timestamp is retained and the data records marked for deletion are removed. The merged results are used to construct the next-level index instance, which uses the error parameters of the merged index instance. Before the index instance at the next scale level is built, the query request is routed to the merged index instance for execution; After the index instance at the next scale level is built and brought online, the resources occupied by the model parameter layer of the merged index instance in the protected memory are released.

16. An electronic device, characterized in that, The device includes a memory and a processor, the memory being used to store computer instructions executable on the processor, and the processor being used to implement the method of any one of claims 1 to 15 when executing the computer instructions.