Method and system for streaming statistical analysis of a persisted result set cache

By generating cache fingerprints based on query semantics, user permissions, and source data version identifiers, and combining streaming computing subchains and hybrid storage mechanisms, the granularity and consistency issues of cache reuse in existing technologies are solved. This enables cache reuse across tasks, sessions, and users, reduces memory usage and database access pressure, and improves query response speed and system stability.

CN123157797APending Publication Date: 2026-11-24BEIJING JOIN CHEER SOFTWARE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611319174.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-28
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing technologies have significant shortcomings in terms of cache reuse granularity, secondary statistical analysis, memory control of large result sets, and cache invalidation mechanisms. They cannot effectively support cache reuse across tasks, sessions, and users, and also suffer from cache consistency issues and high operation and maintenance costs.

Method used

By generating unique cache fingerprints based on query semantics, user permissions, and source data version identifiers, streaming statistical analysis of persistent result set caching is achieved. Statistical calculations are performed using streaming statistical computing subchains, and hybrid storage of hot data layers in memory and cold data layers on disk is combined to support cache reuse across tasks, sessions, and users. An adaptive hierarchical streaming computing model controls memory usage, and automatic cache invalidation is achieved using cache fingerprints and source data version identifiers.

Benefits of technology

It significantly improves cache reuse rate, reduces database access frequency and memory usage, improves query response speed and system stability, increases cache reuse rate by more than 70%, reduces data source access frequency by more than 60%, reduces peak memory usage by more than 90%, and achieves millisecond-level statistical query response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157797A_ABST
    Figure CN123157797A_ABST
Patent Text Reader

Abstract

This invention provides a streaming statistical analysis method and system for persistent result set caching. The method includes: generating a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request; querying the cache index table according to the cache fingerprint to determine whether a corresponding valid persistent result set cache exists; in response to a valid cache hit, querying the statistics cache, and directly returning the statistical result if a hit occurs; if the statistics cache misses, streaming the corresponding detailed result set from the persistent result set cache, performing streaming statistical calculation through the streaming statistical calculation subchain to obtain and return the statistical result, and simultaneously writing the statistical result to the statistics cache; in response to a valid cache miss, performing a detailed data query on the source database, performing streaming statistical calculation through the streaming statistical calculation subchain to obtain and return the statistical result, and asynchronously writing the detailed result set in blocks to the persistent result set cache and updating the cache index table.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of software development and big data query and analysis technology, and in particular to a streaming statistical analysis method and system for persistent result set caching. Background Technology

[0002] As enterprises deepen their digital transformation, scenarios such as Business Intelligence (BI) data analysis, data visualization, and report generation place increasingly higher demands on the query and analysis capabilities of databases. Users typically need to repeatedly perform multi-dimensional statistics, secondary filtering analysis, and multi-indicator calculations based on raw detailed data. To improve query efficiency, various query result caching solutions have emerged in existing technologies.

[0003] A typical existing solution is a memory caching approach, such as caching query results in the application process's memory based on a local HashMap or in-process caching components (e.g., Redis, Memcached). This approach accelerates repeated access by caching the results of frequently accessed queries, and the cache lifecycle is typically tied to the task, session, or service process. However, because the result set resides entirely in the process memory, this approach can only store frequently accessed data, has a short cache lifecycle, its data volume is limited by memory capacity, and it suffers from cache loss upon service restart, making it unsuitable for persistent storage of large result sets.

[0004] Another existing solution is persistent caching, which persists cached data to disk to address the high latency of remote storage access. For example, Azure Synapse Analytics provides result set caching; once enabled, a dedicated SQL pool automatically caches query results in the user database for reuse. In multi-cluster computing systems, query results can also be cached in cloud storage and reused after a cluster restart. However, this type of solution caches data blocks or query result sets in the underlying storage, without being aware of the upper-level query semantics and statistical calculation logic. It can only solve the problem of accelerating repeated queries and cannot support secondary statistical analysis and reuse of query result sets, nor does it have the capabilities of streaming statistics or multi-data source syntax masking.

[0005] Regarding cache reuse granularity, existing query caches are mostly managed by task ID or session ID, supporting only the reuse of results within the same session or task. When different tasks or different users perform statistical analysis based on the same query conditions, the system cannot reuse existing caches. Although some systems support cross-user cache sharing, they typically only perform simple permission matching checks; if permissions are inconsistent, each caches independently, resulting in a low cache reuse rate.

[0006] Regarding cache invalidation mechanisms, existing solutions mostly employ passive invalidation strategies such as fixed cache lifetime (TTL) expiration or Least Recently Used (LRU) algorithm-based eviction. While TTL is simple to implement, consistency between cached objects and source data cannot be maintained when the source data changes within the TTL period. Shortening the TTL significantly reduces cache hit rate, failing to balance consistency and performance. Another approach attempts to achieve proactive invalidation based on database binary log / change data capture (binlog / CDC) change detection, but this requires deploying additional change detection components, faces difficulties in adapting to multiple data sources, and incurs high operational costs.

[0007] In secondary statistical analysis, existing technologies require users to regenerate SQL queries to access the source database for each type of operation when performing secondary operations such as sorting, filtering, grouping, and aggregation calculations (e.g., maximum, minimum, average, variance, median, mode, percentile, and deduplication). This not only significantly increases database load but also presents a serious multi-data source adaptation problem—the syntax of advanced statistical functions differs greatly between different databases (e.g., MySQL, Oracle, ClickHouse, PostgreSQL), requiring separate adaptation of all statistical algorithms for each new data source, resulting in extremely high development and maintenance costs.

[0008] In terms of large result set statistics, existing solutions for statistical analysis of result sets in the millions or tens of millions often use a full-load method to perform aggregation calculations. Memory usage increases linearly with the data volume, which can easily trigger service memory overflow and lead to system crashes. Some solutions attempt to avoid full loading through streaming reads, but there is still a lack of adaptive memory control strategies for statistical computing scenarios.

[0009] In summary, existing technologies have significant shortcomings in terms of cache reuse granularity, secondary statistical analysis, memory control of large result sets, and cache invalidation mechanisms. There is an urgent need for a technical solution that can solve the above problems simultaneously. Summary of the Invention

[0010] In view of this, the present invention provides a streaming statistical analysis method and system for persistent result set caching to solve at least one of the problems mentioned above.

[0011] To achieve the above objectives, the present invention adopts the following solution: According to a first aspect of the present invention, a streaming statistical analysis method based on a persistent result set cache is provided. The method includes: generating a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in a user query request; querying a cache index table according to the cache fingerprint to determine whether a corresponding valid persistent result set cache exists; in response to a valid cache hit, querying a statistical cache, and if a hit occurs, directly returning the statistical result; if the statistical cache misses, streaming the corresponding detailed result set from the persistent result set cache, performing streaming statistical calculations on the detailed result set through a streaming statistical calculation subchain to obtain and return the statistical result, and simultaneously writing the statistical result to the statistical cache; in response to a valid cache miss, performing a detailed data query on the source database, and performing streaming statistical calculations on the detailed result set returned by the query through the streaming statistical calculation subchain to obtain and return the statistical result, and simultaneously asynchronously writing the detailed result set in blocks to the persistent result set cache and updating the cache index table.

[0012] In some embodiments of this application, the method described above generates a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request. This includes: obtaining the query columns, filtering conditions, and sorting conditions from the user query request, and assembling them into a detailed query statement; standardizing and normalizing the detailed query statement to obtain a standardized query statement; sorting each query parameter in the user query request by key name in a fixed order, and concatenating all sorted key-value pairs sequentially to obtain a sorted parameter set; extracting the data permission context from the user query request, and saving the data permission context as an independent element when it is not included in the sorted parameter set; obtaining the current data version number of all source data tables involved in the user query; and combining the standardized query statement, the sorted parameter set, the current data version number, and the data permission context not included in the sorted parameter set, and performing a hash operation to generate the cache fingerprint.

[0013] In some embodiments of this application, the above method standardizes and normalizes the detailed query statement to obtain a standardized query statement, including: removing redundant spaces and line breaks from the detailed query statement and unifying keywords to lowercase or uppercase; replacing parameters in the detailed query statement with placeholders; unifying table aliases in the detailed query statement to preset standard aliases, and normalizing the sorting direction in the sorting conditions to a preset standard sorting direction; and extracting the value set of multi-valued parameters from the SQL statement and replacing it with placeholders, so that the detailed query statement retains only the query structure.

[0014] In some embodiments of this application, the method described above for obtaining the current data version number of all source data tables involved in the user query includes: taking the maximum value of the last update time of the source data tables within the range of non-multi-value parameters in the user query as the data version number of the corresponding source data table; when the query involves multiple source data tables, taking the maximum value of the data version number of each source data table as the current data version number; the query result of the data version number has a short-term cache with a configurable duration, and repeated queries within the cache duration directly return results from the short-term cache to avoid accessing the source database.

[0015] In some embodiments of this application, the streaming statistical subchain in the above method is composed of several operators spliced ​​together in execution order. The operators are selected from a built-in operator library, which includes filtering operators, aggregation operators, advanced statistical operators, and processing operators. The streaming computing subchain adopts a streaming mode of reading, computing, and outputting simultaneously, processing data block by block, with a single memory usage that is stable at the size of a single data block.

[0016] In some embodiments of this application, the above method further includes the step of determining the estimated data volume: in response to a valid cache hit, reading the data volume of the corresponding persistent result set cache from the cache index table as the estimated data volume; in response to a valid cache miss, performing a counting query on the detailed query statement to obtain the exact number of rows as the estimated data volume; when the counting query times out or the source database does not support it, processing is performed at the maximum data volume level.

[0017] In some embodiments of this application, when the streaming statistical computing subchain performs streaming statistical computing in the above method, an adaptive hierarchical streaming computing model is used to control memory usage based on the estimated data volume. Specifically, this includes: when the estimated data volume is less than a first threshold, a full-memory direct computing strategy is adopted to load the data into memory at once to complete all statistical computing; when the estimated data volume is greater than or equal to the first threshold and less than a second threshold, a batch streaming computing strategy is adopted to load data sequentially with a fixed batch size to perform statistical computing; when the estimated data volume is greater than or equal to the second threshold, hash sharding is performed according to the grouping dimension value to split the full data into several independent shards, and a global aggregation variable is created to store the final statistical results; each shard is read sequentially into memory, local aggregation computing is performed on the current shard to generate the intermediate result of the shard; the intermediate result is incrementally merged with the current value of the global aggregation variable to update the global aggregation variable, and the memory of the current shard is released immediately after the merging is completed; the process is repeated until all shards are processed.

[0018] In some embodiments of this application, the persistent result set cache in the above method adopts a hybrid storage of a memory hot data layer and a disk cold data layer. The memory hot data layer uses the LRU algorithm to manage the access frequency of the cached result set. When the access frequency decreases, it is automatically migrated to the disk cold data layer for persistent storage. The data in the disk cold data layer is not lost after the service restarts.

[0019] In some embodiments of this application, the detailed result set in the above method is divided into data blocks with a fixed number of rows in both the hot data layer in memory and the cold data layer on disk, and each block is stored independently. The streaming read is performed sequentially according to the data blocks.

[0020] In some embodiments of this application, the statistical cache in the above method uses the combination of the cache fingerprint and the statistical configuration of the current query as the cache key, and different statistical indicators derived from the same detailed result set are cached independently; when the detailed result set becomes invalid due to a change in the corresponding current data version number, all statistical caches mounted under the detailed result set become invalid.

[0021] In some embodiments of this application, the above method further includes: periodically scanning the cache index table, determining whether the corresponding cache has expired based on the current data version number, and if expired, asynchronously cleaning up the corresponding storage space in the persistent result set cache.

[0022] According to a second aspect of the present invention, a streaming statistical analysis system based on a persistent result set cache is provided. The system includes: a fingerprint generation unit, configured to generate a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in a user query request; a judgment unit, configured to query a cache index table based on the cache fingerprint to determine whether a corresponding valid persistent result set cache exists; a first processing unit, configured to, in response to a valid cache hit, query a statistical cache, and if a hit occurs, directly return the statistical result; if the statistical cache misses, stream the corresponding detailed result set from the persistent result set cache, perform streaming statistical calculation on the detailed result set through a streaming statistical calculation subchain, obtain the statistical result, and return it, while simultaneously writing the statistical result to the statistical cache; and a second processing unit, configured to, in response to a valid cache miss, perform a detailed data query on the source database, perform streaming statistical calculation on the detailed result set returned by the query through the streaming statistical calculation subchain, obtain the statistical result, and return it, while simultaneously writing the detailed result set in blocks asynchronously to the persistent result set cache and updating the cache index table.

[0023] According to a third aspect of the present invention, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method.

[0024] According to a fourth aspect of the present invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.

[0025] According to a fifth aspect of the present invention, a computer program product is provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the above-described method.

[0026] The streaming statistical analysis method and system for persistent result set caching proposed in this application achieves cross-task, cross-session, and cross-user persistent result set cache reuse through a multi-dimensional cache fingerprint generation mechanism at the query semantic level. This eliminates the need for repeated accesses to the source database for statistical queries with the same semantics, improving cache reuse rate by over 70%. Simultaneously, by constructing a streaming statistical computation sub-chain, secondary statistical analysis is executed directly based on the materialized detailed result set without returning to the source, reducing data source access times by over 60%. Furthermore, all statistical algorithms are uniformly implemented at the operator chain layer, reducing the adaptation cost for statistical functions of new data sources by over 90%. Building upon this, this application also utilizes a block storage and streaming read mechanism, combined with an adaptive hierarchical streaming computation model for cache misses, to minimize the memory usage and total memory consumption of statistical computation. Data volume decoupling reduces peak memory usage for large result set statistics by over 90%, completely eliminating the risk of memory overflow. Furthermore, by incorporating source data version identifiers into cache fingerprints, changes in the version number when source data changes automatically invalidate the corresponding cache fingerprint, eliminating the need for fixed TTL expiration or binlog / CDC change detection components. This ensures strong consistency between the cache and source data while maintaining a high cache hit rate. Additionally, through a priority hit mechanism in the second-level statistical cache, already calculated statistical indicators can be directly returned without repeated operator chain calculations, achieving millisecond-level response speeds for repeated adjustments of statistical indicators. Ultimately, this significantly reduces database load and multi-data source adaptation costs, comprehensively enhances system stability, and substantially improves the response speed and user experience of statistical queries. Attached Figure Description

[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 This is a flowchart illustrating a streaming statistical analysis method based on persistent result set caching provided in an embodiment of this application; Figure 2This is a schematic diagram of the process for generating a unique cache fingerprint provided in an embodiment of this application; Figure 3 This is a flowchart of the standardization and normalization process provided in the embodiments of this application; Figure 4 This is a schematic diagram of the process for controlling memory usage using an adaptive hierarchical streaming computing model, provided in an embodiment of this application. Figure 5 This is a schematic diagram of the process for asynchronously cleaning up the storage space corresponding to the persistent result set cache provided in the embodiments of this application; Figure 6 This is a schematic diagram of the structure of a streaming statistical analysis system based on persistent result set caching provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0028] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0029] It should be noted that in the embodiments of this application, the term "comprising" and any variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0030] Furthermore, the terms “first”, “second”, etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated.

[0031] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0032] like Figure 1 The diagram shown is a flowchart of a streaming statistical analysis method based on persistent result set caching provided in an embodiment of this application. The method includes the following steps: Step S101: Generate a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request.

[0033] In this step, the system first receives a statistical query request submitted by the user. This request carries the semantic information of the query the user needs, including the data columns to be queried, filter conditions, sorting conditions, etc. Simultaneously, the system also obtains the current user's identity information to determine the user's data permission scope.

[0034] In this embodiment of the application, "query semantics" refers to the set of information used to uniquely characterize the logical meaning of the current statistical query. For example, query semantics may include, but is not limited to: the data table involved in the query, query columns, filtering conditions (such as time range, numerical range, etc.), sorting conditions, grouping conditions, etc. This query semantics directly determines the content and structure of the detailed result set returned by the query.

[0035] "User permissions" refer to the scope of access rights that the user currently initiating the query request has at the data level. This ensures that users with different permission levels access the data they are authorized to view. For example, user permissions may include, but are not limited to: the user's organization or department, the range of row-level permissions they can access, the range of column-level permissions they can access, and role-based permission levels.

[0036] The "Source Data Version Identifier" is information used to characterize the data version status of the source data table involved in the current query. For example, the Source Data Version Identifier is determined based on the data change status of the source data table, and is updated whenever the data stored in the source data table changes.

[0037] In this step, the three types of information—query semantics, user permissions, and source data version identifier—are combined and hashed to generate a fixed-length string as a cache fingerprint. This cache fingerprint is the sole basis for subsequent determination of whether a reusable cache exists.

[0038] Step S102: Query the cache index table based on the cache fingerprint to determine whether there is a corresponding valid persistent result set cache.

[0039] In this step, the system maintains a cache index table. This cache index table is used to record the metadata information of all stored persistent result sets cached. It resides entirely in the system memory and supports microsecond-level cache hit determination. It includes at least the following fields: cache fingerprint, corresponding persistent storage address, cache generation time, associated source data table identifier, and cache validity status identifier.

[0040] After the cache fingerprint is generated in step S101, the system uses the cache fingerprint as the query key to search the cache index table. If a record that completely matches the cache fingerprint is found in the cache index table, and the cache indicated by the record is in a valid state, it is determined that a corresponding valid persistent result set cache exists; otherwise, if there is no matching record in the cache index table, or if the matching record indicates that the cache has expired, it is determined that a corresponding valid persistent result set cache does not exist.

[0041] It should be noted that the "persistent result set cache" in this application embodiment refers to a cache form that persistently stores the detailed result set returned by the query in a non-volatile storage medium. Its lifecycle is independent of the user session and task execution cycle. The cached data is not lost after the service restarts and supports cross-task, cross-session, and cross-user reuse.

[0042] Step S103: In response to a valid cache hit, query the statistics cache. If a hit occurs, return the statistical result directly. If the statistics cache is not hit, stream the corresponding detailed result set from the persistent result set cache, perform streaming statistical calculation on the detailed result set through the streaming statistical calculation subchain, obtain the statistical result and return it, and write the statistical result to the statistics cache.

[0043] This step is executed when the result of step S102 indicates a valid cache hit.

[0044] First, the system queries the statistics cache based on the statistical configuration required by the current query (e.g., the user requests statistical calculations such as summation, average, median, and mode for a certain field). The statistics cache is a second-level cache, independent of the detailed result set cache, used to store calculated statistical results and avoid repeated statistical calculations.

[0045] Specifically, the statistics cache stores data using a combination of the cache fingerprint and the statistical configuration as the key. The system combines the cache fingerprint generated in step S101 with the currently queried statistical configuration and then searches the statistics cache. If a matching statistics cache entry is found, the system directly reads the statistical result stored in that entry and returns it to the user, ending the process.

[0046] If a statistics cache miss occurs, meaning there is no valid entry in the statistics cache that matches the current cache fingerprint and statistics configuration combination, the system reads the detailed result set corresponding to that cache fingerprint from the persistent result set cache. Specifically, the reading method is streaming, meaning the data is read into memory in batches and continuously according to the storage order of the detailed result set in persistent storage, rather than loading the entire detailed result set into memory at once.

[0047] While or after streaming the detailed result set, the system can perform streaming statistical calculations on the result set through a pre-built streaming statistical calculation subchain. The streaming statistical calculation subchain is composed of multiple statistical calculation subchains concatenated in execution order, each corresponding to a specific statistical calculation function. For example, the streaming statistical calculation subchain may include, but is not limited to: filtering operators, aggregation operators (summation, counting, maximum, minimum, average, etc.), advanced statistical calculation subchains (median, mode, percentiles, etc.), and processing operators (grouping, sorting), etc.

[0048] Streaming statistical computing employs a "read-while-compute-output" execution mode. This means that as the detailed result set is streamed, each operator processes the read data sequentially, without waiting for the full data load to complete before computation begins. This significantly reduces memory usage and improves computational efficiency. This streaming statistical computing subchain directly performs statistical calculations based on the materialized detailed result set, without requiring a return to the source database.

[0049] After the streaming statistical calculation subchain is completed, the statistical results are output. The system returns the statistical results to the user and writes them to the statistical cache so that subsequent queries with the same statistical configuration can directly retrieve and return the results from the statistical cache, avoiding repeated execution of the operator chain calculation.

[0050] Step S104: In response to a missed valid cache, a detailed data query is performed on the source database, and streaming statistical calculations are performed on the detailed result set returned by the query through the streaming statistical calculation subchain to obtain statistical results and return them. At the same time, the detailed result set is asynchronously written in blocks to the persistent result set cache and the cache index table is updated.

[0051] This step is executed when the result of step S102 is that no valid cache was hit.

[0052] First, the system generates a query statement (such as an SQL statement) to retrieve detailed data based on the query semantics in the user's query request, and sends this query statement to the source database to execute the detailed data query. The source database responds to the query statement and returns the corresponding detailed result set.

[0053] The system receives the detailed result set returned by the source database and performs streaming statistical calculations on the detailed result set through a streaming statistical calculation sub-chain. This streaming statistical calculation process is the same as the calculation process when the statistical cache is not hit in step S103, that is, it adopts a "read-calculate-output-while-reading" streaming mode. The concatenated streaming statistical calculation sub-chain sequentially performs statistical calculations such as filtering, grouping, aggregation, and sorting on the detailed data to obtain statistical results. The streaming statistical calculation sub-chain directly performs calculations based on the detailed result set returned from the source database query, and the statistical results are returned to the user after output.

[0054] Meanwhile, the system asynchronously writes the detailed result sets returned by the source database to the persistent result set cache in chunks. The write operation is performed asynchronously in the background and does not block the return of statistical results. After the detailed result sets are written to the persistent result set cache, the system updates the cache index table, adds a new record to the cache index table, records the cache fingerprint, storage address, associated source data table identifier, and other metadata information of the detailed result set, and marks its status as valid.

[0055] Through the above asynchronous write mechanism, statistical results are returned to the user first, and the persistent storage operation of detailed result sets is performed in the background, without increasing the user's waiting time and ensuring query response speed.

[0056] It should be noted that the "block asynchronous write" described in this application embodiment specifically includes: the system divides the detailed result set into multiple data blocks according to a preset number of rows (e.g., every 10,000 rows is one block); each data block is independently written to the persistent storage medium; the write operation is executed asynchronously by the background thread pool, and the main thread returns the statistical results immediately after triggering the write operation without waiting for the write to complete; when all data blocks have been written, the system updates the cache index table and marks the corresponding cache entries as valid.

[0057] Through the above steps, the streaming statistical analysis method based on persistent result set caching provided in this application embodiment realizes query semantic-level cache fingerprint generation, cross-task and cross-user reuse of persistent result sets, streaming statistical calculation, and asynchronous persistence of detailed result sets, effectively improving cache reuse rate and query response speed, and reducing database access pressure.

[0058] In some embodiments of this application, such as Figure 2 As shown, in step S101 above, a unique cache fingerprint is generated based on the query semantics, user permissions, and source data version identifier in the user query request, including: Step S201: Obtain the query columns, filtering conditions, and sorting conditions from the user's query request, and assemble them into a detailed query statement.

[0059] In this step, the system parses the statistical query request submitted by the user and extracts three types of information: query columns, filtering conditions, and sorting conditions.

[0060] Specifically, query columns refer to the data fields that users need to query and display. For example, when a user queries sales details, query columns may include fields such as sales date, product name, and sales amount. Filtering conditions refer to the restrictions imposed by the user on the data range, such as time range restrictions (e.g., the first quarter of 202X) or numerical range restrictions (e.g., amounts greater than 10,000). Filtering conditions are used to select a subset of data from the source data table that meets the user's needs. Sorting conditions refer to the user's specifications for how the query results are arranged, such as sorting by sales amount in descending order or by date in ascending order.

[0061] The system combines the above query columns, filtering conditions, and sorting conditions to generate a complete detailed query statement. This detailed query statement is used to retrieve all detailed records that meet the conditions from the source data table, similar to a SELECT statement in standard Structured Query Language (SQL). The query target of the detailed query statement is the detailed-level data records, not the statistical summary results; that is, each record corresponds to one row of data in the source data table.

[0062] It should be noted that the statistical field configuration does not participate in the assembly of the detailed query statement. The statistical field configuration is used to specify what statistical calculations the user needs to perform (such as summation, average, median, etc.). It only plays a role in the subsequent statistical calculation stage and does not affect the scope and content of the detailed data query.

[0063] Step S202: Standardize and normalize the detailed query statement to obtain a standardized query statement.

[0064] In this step, the system standardizes and normalizes the detailed query statements assembled in step S201 to eliminate formal differences in the semantics of the same query caused by different writing styles and formats.

[0065] Through the standardization and normalization processes described above, detailed query statements that originally had different syntax but the same semantics were normalized into the same standardized query statement structure. For example, queries with the same semantics, regardless of whether uppercase or lowercase keywords are used, or regardless of different table aliases, are all processed to generate the same standardized query statement.

[0066] Step S203: Sort the key names of each query parameter in the user query request in a fixed order, and concatenate all the sorted key-value pairs in sequence to obtain the sorted parameter set.

[0067] In this step, the system extracts all query parameters from the user's query request. Query parameters are the specific parameter values ​​carried in the detailed query statement, such as time range values, monetary thresholds, and multi-value lists. The system sorts the query parameters according to a fixed order of parameter names. This fixed order is a system-preset sorting rule, such as ascending alphabetical order of parameter names, ensuring that the sorted results remain consistent regardless of the order in which the user enters the query parameters.

[0068] For query parameters containing multiple values ​​(i.e., multi-valued parameters, such as multiple organization codes passed in the form of an IN list), the system first sorts the set of values ​​for the parameter and then deduplicates the sorted set of values ​​to eliminate differences caused by different order of values ​​or duplicate values. The deduplicated set of values ​​serves as the canonical value for the multi-valued parameter.

[0069] Finally, the system concatenates all sorted key-value pairs (parameter name and parameter value) into a single string in sorted order, resulting in a sorted parameter set. This sorted parameter set eliminates the impact of differences in the order of parameter input on fingerprint generation, ensuring that queries with the same semantics generate the same cached fingerprint.

[0070] Step S204: Extract the data permission context from the user query request. When the data permission context is not included in the sorted parameter set, save the data permission context as an independent element.

[0071] The data permission context here represents the user's access permission boundaries at the data level, ensuring that users with different permission levels can only access data within their authorized scope. For example, the data permission context may include, but is not limited to: the set of codes for the user's organization or department, the user's row-level permission scope, the user's column-level permission scope, and the user's role-based permission level.

[0072] The system determines whether the aforementioned data permission context is already included in the sorted parameter set generated in step S203. In some scenarios, a user's data permissions are directly reflected in the query parameters of the query request. For example, the user's set of visible units is explicitly passed as a filter condition parameter, in which case the permission information is already covered by the sorted parameter set. In other scenarios, a user's data permissions may not be reflected in the form of query parameters, such as role-based row-level or column-level permissions. These permissions are authenticated by the system in the background and are not passed through query parameters.

[0073] If the data permission context is already included in the sorted parameter set, the system does not need to perform any additional processing on it, as the sorted parameter set implicitly contains the permission information. If the data permission context is not included in the sorted parameter set, the system saves the data permission context as an independent element for subsequent cache fingerprint generation.

[0074] Through the above mechanism, even if users with different data permissions execute the same detailed query, different cache fingerprints will be generated due to the difference in permission context, thereby achieving permission isolation at the cache level and preventing low-privilege users from reading the data range of high-privilege users.

[0075] Step S205: Obtain the current data version number of all source data tables involved in the user query.

[0076] In this step, the system identifies all source data tables involved in the current user's query and obtains the data version numbers of these source data tables at the current moment.

[0077] A data version number is a unique identifier for the data state of a source table at a given moment. Whenever data in the source table changes (e.g., new data is inserted, existing data is modified, or data is deleted), this data version number is updated accordingly to reflect the latest data state.

[0078] The system obtains the current data version number of each source data table involved in the user's query. If the query involves only one source data table, the current data version number of that table is directly obtained as the current data version number of the query. If the query involves multiple source data tables, the current data version number of each table is obtained separately, and then all data version numbers are aggregated to obtain a unique current data version number.

[0079] By obtaining the current data version number of the source data table, the system can incorporate the data version factor into the subsequent cache fingerprint generation, thereby ensuring that the corresponding cache fingerprint changes when the source data changes, causing the cache to automatically become invalid.

[0080] Step S206: Combine the standardized query statement, the sorted parameter set, the current data version number, and the data permission context not included in the sorted parameter set, and perform a hash operation to generate the cache fingerprint.

[0081] In this step, the system combines the standardized query statement generated in step S202, the sorted parameter set generated in step S203, the current data version number obtained in step S205, and the data permission context (if it exists) saved as an independent element in step S204 to form a combined string.

[0082] Of the four elements mentioned above, the standardized query statement represents the semantic structure of the query, the sorted parameter set represents the specific parameter values ​​of the query, the current data version number represents the state of the source data, and the data permission context represents the user's data access boundaries. Together, these four elements completely define all the logical information of the current query.

[0083] The system performs a hash operation on the combined string to generate a fixed-length hash value as a cache fingerprint. The hash operation can use any applicable hash algorithm, such as MD5, SHA-1, SHA-256, etc., and this application does not impose any specific limitations on it. This cache fingerprint serves as a unique identifier for the current query and is used for subsequent cache hit determination. Queries with the same semantics (including the same query structure, the same parameter values, the same data version, and the same user permissions) will generate the same cache fingerprint, thus hitting the same persistent result set cache, achieving cache reuse across tasks, sessions, and users.

[0084] Through the above steps S201 to S206, this application embodiment realizes the generation of cache fingerprint based on query semantics, user permissions and source data version identifier, providing an accurate and comprehensive unique identifier for subsequent cache hit judgment and cache reuse.

[0085] Furthermore, in some embodiments of this application, such as Figure 3 As shown, the standardization and normalization process in step S202 above may further include: Step S301: Remove extra spaces and extra line breaks from the detailed query statement, and unify the keywords to lowercase or uppercase.

[0086] In this step, the system performs format-level standardization processing on the original detailed query statement assembled in step S201.

[0087] Specifically, the original detailed query statement may contain inconsistent numbers of spaces and line breaks during the assembly process due to factors such as code formatting and concatenation methods. For example, SQL statements generated by different developers or different code modules may contain multiple spaces before and after keywords, and an indefinite number of line breaks between different parts of the statement. The system scans the entire detailed query statement string, compresses multiple consecutive spaces into a single space, and removes all line breaks, making the statement a continuous, compact single-line format.

[0088] At the same time, the system uniformly converts all SQL keywords (such as SELECT, FROM, WHERE, ORDERBY, AND, OR, etc.) in detailed query statements to either lowercase or uppercase. By unifying the case, the system eliminates the differences in statement format caused by different writing styles.

[0089] Through the above processing, detailed query statements with the same semantics, regardless of their original writing style, are presented in a uniform, compact, single-line, and case-consistent standard format, laying the foundation for subsequent processing.

[0090] Step S302: Replace the parameters in the detailed query statement with placeholders.

[0091] In this step, the system replaces the specific parameter values ​​carried in the detailed query statement with uniform placeholders.

[0092] Detailed query statements typically contain specific parameter values ​​passed in by the user's query request, such as the time range value "202XQ1", the amount threshold "10000", and the status value "valid". These specific parameter values ​​will change depending on the user input, but the structure of the query statement itself does not change.

[0093] The system identifies the positions of all parameter values ​​in the detailed query statement and replaces them all with placeholders. For example, it uses "?" as a placeholder to replace all specific parameter values ​​in the query statement with "?". After this processing, queries with different parameter values ​​will all present the same statement format as long as their query structure is the same.

[0094] It should be noted that the difference between step S302 and step S304 is that step S302 deals with single-valued parameters (i.e., a single value), while step S304 specifically deals with multi-valued parameters (i.e., a set of values / a list of values). The two deal with different objects, but together they constitute a complete normalization process for parameter values.

[0095] Step S303: Unify the table aliases in the detailed query statement to preset standard aliases, and normalize the sorting direction in the sorting conditions to preset standard sorting direction.

[0096] In this step, the system normalizes the table aliases and sorting directions in the detailed query statement.

[0097] Specifically, when assembling detailed query statements, different code implementations may assign different aliases to the same source data table. For example, the sales details table might be named "s" in some queries, "sales" in others, and the full name "sales_detail" in still others. Although the table aliases differ, the query semantics remain identical. The system, following preset alias mapping rules, uniformly replaces all table aliases with their corresponding standard aliases, eliminating the differences in statement structure caused by alias differences.

[0098] Simultaneously, the system normalizes the sorting direction in the sorting conditions. Sorting directions typically include ascending (ASC) and descending (DESC). For example, the system unifies all sorting directions to a preset standard sorting direction; for instance, explicit or implicit ascending orders are uniformly expressed as standard ascending order, and descending orders are uniformly expressed as standard descending order, ensuring a unique representation of the same sorting semantics. For sorting conditions where no sorting direction is explicitly specified, the system supplements the normalization according to the default sorting direction.

[0099] Step S304: Extract the set of values ​​of multi-valued parameters from the SQL statement in the detailed query statement and replace them with placeholders so that the detailed query statement retains only the query structure.

[0100] In this step, the system handles multi-valued parameters in the detailed query statement specifically. A multi-valued parameter refers to a set of parameters that contain multiple values. Typically, an IN list in SQL represents a multi-valued parameter, such as "org_code IN ('A001', 'A002', 'A003')". Furthermore, a set of values ​​passed through a temporary table also falls under the category of multi-valued parameters, such as the form "org_code IN (SELECT org_code FROM temp_table)".

[0101] The system completely extracts the value set of multi-valued parameters from the detailed query statement, that is, it replaces the entire value set part with placeholders, retaining only the query structure. For example, "org_code IN ('A001', 'A002', 'A003')" is normalized to "org_code IN (?)"; similarly, "org_code IN (SELECT org_code FROM temp_table)" is also normalized to "org_code IN (?)".

[0102] Through this stripping process, queries with the same semantics are normalized to the same query structure regardless of the number of multi-value parameters, the order in which values ​​are passed, or whether they are passed using an IN list or a temporary table. The value set itself, after being stripped, is separately included in the sorted parameter set for fingerprint generation, thus achieving separate management of the query structure and parameter values.

[0103] It should be noted that the meaning of retaining only the query structure in step S304 is that after the multi-valued parameters are stripped from the detailed query statement, the original statement retains only the logical framework of the query—including the column structure, table structure, condition structure (excluding specific values), sorting structure, etc., while all specific values ​​are replaced by placeholders, so that the query statement returns to a pure structural description and no longer contains any specific data values.

[0104] Combining steps S301 to S304 above, the original detailed query statement undergoes multiple processing steps, including space and line break cleanup, case unification, parameter placeholder replacement, table alias unification, sorting direction normalization, and multi-value parameter stripping, to generate a standardized query statement. This standardized query statement eliminates the differences in the physical syntax of the same semantic query, enabling queries with the same semantics to generate the same fingerprint during subsequent cache fingerprint generation, thereby achieving cache reuse across tasks and sessions.

[0105] In some embodiments of this application, obtaining the current data version number of all source data tables involved in the user query in step S205 includes: taking the maximum value of the last update time of the source data tables within the range of non-multi-value parameters in the user query as the data version number of the corresponding source data table; when the query involves multiple source data tables, taking the maximum value of the data version number of each source data table as the current data version number; the query result of the data version number has a short-term cache with a configurable duration, and repeated queries within the cache duration directly return results from the short-term cache to avoid accessing the source database.

[0106] In this embodiment, the system first determines all source data tables involved in the user's query. Then, for each source data table, according to the non-multi-value parameter range dimension of the user's query, the system obtains the maximum value of the last update time of the source data table within that range, and uses it as the data version number of the source data table.

[0107] Specifically, parameters in user query requests can be divided into two categories: multi-valued parameters and non-multi-valued parameters. Multi-valued parameters refer to a set of parameters with multiple values, such as an organization code set (org_code IN ('A001','A002',...)), where the number of values ​​is uncertain and may be large. Non-multi-valued parameters refer to parameters with a single value or a range of values, such as a time range (period='2024Q1') or a numerical threshold (amount>10000).

[0108] When retrieving the maximum last update time from the source data table, the system only uses non-multi-valued parameters as filtering conditions, without including multi-valued parameters. For example, for the query "SELECT..." When retrieving the data version number using the query "FROM sales WHEREperiod='202XQ1' AND org_code IN ('A001','A002',...,'A100')", the system only uses the non-multi-valued parameter range dimension "period='202XQ1'" and does not include the multi-valued parameter condition "org_code IN(...)".

[0109] The technical significance of this design lies in the fact that the set of values ​​for multi-valued parameters can be extremely large (e.g., thousands of institutional codes). If multi-valued parameters are included in the filtering conditions of version number queries, the MAX aggregation query may degenerate into a temporary table scan due to the excessively large IN list, severely impacting query performance. By removing multi-valued parameter conditions, the system can quickly complete MAX aggregation through an index scan of the period field, ensuring the efficiency of version number acquisition.

[0110] Taking a real-world application scenario as an example, if a user queries sales data for the first quarter of 202X and limits the scope to 100 specific institutions, the system, when retrieving the data version number, only takes the maximum value of the last update time from the sales table using "period='202XQ1'", without considering the institution scope restriction. This is because: if any institution's data changes within the 202XQ1 period, the cache for that period should become invalid, regardless of whether the institution involved in the change is within the current user's institution permission scope. The design philosophy of period-level version management is to control cache invalidation at the time range granularity, rather than at the business dimension such as institution.

[0111] When a user query involves multiple source tables (such as cross-table joins), the system obtains the data version number of each source table, and then takes the maximum value of the data version numbers from all tables as the current data version number for the query.

[0112] For example, if a query involves two source data tables, the sales table and the products table, and the sales table was updated on June 1, 202X at 10:00:00, while the products table was updated on June 1, 202X at 10:30:00, then the system will take the maximum value of the last update time of the two tables, "June 1, 202X at 10:30:00", as the current data version number of the query.

[0113] The mechanism of taking the maximum value from multiple tables ensures that if any source table involved in the query undergoes a data change, the overall current data version number of the query changes, which in turn changes the cache fingerprint generated based on that version number, causing the corresponding cache to automatically expire. This guarantees strong consistency between cached data and all related source tables.

[0114] Furthermore, to optimize performance and avoid impacting the source database with high-frequency queries, this embodiment sets up a short-term cache for the query results of data version numbers. This short-term cache is independent of the aforementioned persistent result set cache and statistics cache, and is specifically used to cache the query results of data version numbers. Its cache duration is a configurable value (e.g., it can be configured to the second or minute level).

[0115] Specifically, when a query accesses the source database to obtain the maximum last update time of a source data table within a certain time range, the system stores the data version number and its corresponding query conditions (source data table identifier, time range, etc.) in a short-term cache. Within the cache duration, if a new query request needs to obtain the data version number of the same source data table within the same time range, the system directly returns the cached version number result from the short-term cache, without needing to access the source database again to execute the MAX aggregation query.

[0116] The duration of this short-term cache can be configured by operations and maintenance personnel based on the business's data consistency requirements. If the business scenario has extremely high consistency requirements, the cache duration can be configured to 0 seconds, meaning that the latest version number is retrieved from the source database in real time each time. If the business scenario has relatively relaxed consistency requirements but higher performance requirements, the cache duration can be configured to a longer value (e.g., 30 seconds, 60 seconds, etc.) to reduce the query pressure on the source database. In some embodiments of this application, the default duration of the short-term cache can be set to 5 seconds or 10 seconds, effectively reducing the load on the source database while ensuring timely updates of the data version number.

[0117] It's important to note that this short-term cache only caches the data version number query results, not the detailed result set or statistical results. Its scope is limited to the version number retrieval stage. Compared to directly caching detailed query results for a long time, this short-term caching mechanism provides a more refined balance between data consistency and query performance: even if the short-term cache returns a slightly older version number, causing the cache fingerprint to not be updated, in the worst case, it will only cause a brief data delay within the cache duration, without causing long-term data inconsistency.

[0118] Through the aforementioned version number acquisition mechanism, this embodiment of the application implements source data-driven cache invalidation control: each add, delete, or modify operation in the source data table is reflected as an update of the last update time field, which in turn is reflected as a change in the data version number. Ultimately, the corresponding cache is automatically invalidated through changes in the cache fingerprint. The entire process does not require the deployment of change detection components such as binlog / CDC, and can be naturally adapted to various relational databases, offering the advantages of low operation and maintenance costs and high data consistency.

[0119] In some embodiments of this application, the above method further includes the step of determining the estimated data volume, specifically as follows: in response to a valid cache hit, the data volume of the corresponding persistent result set cache is read from the cache index table as the estimated data volume; in response to a valid cache miss, a counting query is performed on the detailed query statement to obtain the exact number of rows as the estimated data volume; when the counting query times out or the source database does not support it, it is processed according to the maximum data volume level.

[0120] The estimated data volume is used to select appropriate computation strategies for the subsequent adaptive hierarchical streaming computing model, thereby controlling memory usage during statistical computation. Specifically, the estimated data volume is determined in different ways depending on whether the cache is hit: I. Determining the amount of data in a cache hit scenario.

[0121] When a valid cache is hit by querying the cache index table based on the cache fingerprint, the system directly reads the amount of data cached in the persistent result set corresponding to that cache fingerprint from the cache index table as the estimated data amount.

[0122] Specifically, when writing to the persistent result set cache, the system has already counted the total number of rows in the detailed result set and recorded this data volume information in the entry corresponding to the cache fingerprint in the cache index table. Therefore, when a subsequent query hits the cache, the system does not need to access the source database or scan the data files in persistent storage; it can obtain accurate data volume information simply by querying the cache index table. This process does not involve any disk I / O operations; it is a pure memory read with a response time in the microsecond range, and its impact on query performance is negligible.

[0123] In this way, the amount of data hit in the cache scenario is determined without generating additional database query overhead, and the data volume information is completely consistent with the actual cached detailed result set.

[0124] II. Determining the amount of data in cache miss scenarios.

[0125] When the cache fingerprint query to the cache index table fails to find a valid cache, the system needs to query the source database for detailed data. At this point, the system has not yet obtained the actual detailed result set and cannot determine the data volume through the index table. Therefore, the system performs a counting query on the detailed query statement assembled in step S201 to obtain the exact number of rows that meet the query conditions as the estimated data volume.

[0126] For example, if the detailed query statement is a SELECT statement in SQL, the system executes the corresponding COUNT query. For instance, it converts "SELECT org_code, amount FROM sales WHERE period = '2024Q1' AND amount> 10000" into "SELECT COUNT( The query "FROM sales WHERE period = '2024Q1' AND amount> 10000" sends a COUNT query to the source database and retrieves the returned count value, which is then used as the estimated data volume. This COUNT query returns only one value, resulting in minimal data transfer and typically high execution efficiency, especially when the fields involved in the query conditions have indexes.

[0127] However, in certain scenarios, COUNT queries may encounter execution timeouts or be unsupported by the source database. For example, when query conditions are extremely complex (e.g., involving multi-table joins, subqueries, or complex function calculations), the COUNT query itself may need to scan a large amount of data, resulting in a long execution time that could exceed the system's preset timeout threshold. Furthermore, some data sources (such as certain NoSQL databases or streaming data sources) may not support the standard COUNT syntax.

[0128] To address the aforementioned anomalies, the system employs a timeout control mechanism and a degradation strategy. When the execution time of a COUNT query exceeds a preset timeout threshold, the system terminates the COUNT query and processes it according to the maximum data volume level. Similarly, if the source database does not support the COUNT query syntax, the system also processes it according to the maximum data volume level. Processing according to the maximum data volume level means that the system treats the estimated data volume as a large data volume exceeding all preset thresholds. The subsequent adaptive hierarchical streaming computing model will directly adopt computing strategies oriented towards large data volumes (such as hash sharding plus local aggregation plus incremental merging strategies) to ensure memory safety.

[0129] Through the dual protection mechanism of COUNT query plus timeout degradation, the system can obtain the estimated data volume to support the selection of subsequent calculation strategies in the case of cache miss. At the same time, in abnormal situations, degradation processing ensures the stability and reliability of the system and avoids query failure or long waiting time caused by COUNT query timeout.

[0130] It should be noted that the step of determining the estimated data volume is completed before the statistical calculation is performed in the streaming statistical computing subchain. The determined estimated data volume value is used to guide the selection of subsequent calculation strategies, but the estimated data volume itself does not participate in the statistical calculation process and does not affect the correctness of the statistical calculation results. Those skilled in the art will understand that even if there is a deviation between the estimated data volume and the actual data volume, the adaptive hierarchical streaming computing model can still ensure the correct execution of statistical calculations—when the data volume estimate is too low, the calculation strategy may not be conservative enough, but the calculation results are still correct (only memory usage may exceed expectations, but the system still processes it according to the maximum data volume level); when the data volume estimate is too high, the system may choose a more conservative calculation strategy, resulting in a slight decrease in performance, but the correctness of the calculation results and the memory safety of the system are not affected.

[0131] Through the aforementioned mechanism for determining the estimated data volume, the embodiments of this application can accurately obtain the data volume information of the query under different caching states, providing a reliable data foundation for the selection of computing strategies for the subsequent adaptive hierarchical streaming computing model.

[0132] Furthermore, in some embodiments of this application, such as Figure 4 As shown, when the above-mentioned streaming statistical computing subchain performs streaming statistical computation, it uses an adaptive hierarchical streaming computing model to control memory usage based on the estimated data volume. This adaptive hierarchical streaming computing model automatically selects an appropriate computing strategy based on different levels of the estimated data volume, so as to control memory usage within a constant range while ensuring computational performance. Specifically, it includes: Step S401: When the estimated data volume is less than the first threshold, a full-memory direct calculation strategy is adopted to load the data into memory at once to complete all statistical calculations.

[0133] The system first determines the relationship between the estimated data volume and a first threshold. The first threshold is a preset lower limit for the data volume, used to define the boundary between small and medium data volumes. For example, this first threshold can be set to 100,000 records. When the estimated data volume is less than this first threshold, the system determines that the current query data volume is relatively small and adopts a full-memory direct calculation strategy.

[0134] Specifically, under the full-in-memory direct computation strategy, the system loads the entire detailed result set into memory at once, and then the streaming statistical computation subchain performs all statistical calculations on the complete dataset in memory. Due to the relatively small data volume, the memory space required for full loading is limited, thus not putting pressure on system memory. At the same time, one-time loading minimizes disk I / O operations and scheduling overhead, achieving the lowest possible query latency. This strategy prioritizes query response speed and is suitable for lightweight, fast query scenarios with small datasets.

[0135] Step S402: When the estimated data volume is greater than or equal to the first threshold and less than the second threshold, a batch streaming computing strategy is adopted to load data sequentially with a fixed batch size and perform statistical calculations.

[0136] In this step, when the estimated data volume is greater than or equal to the first threshold and less than the second threshold, the system determines that the current query data volume is of medium scale and adopts a batch streaming computing strategy. The second threshold is a preset upper limit threshold for data volume, used to define the boundary between medium and large data volumes, and its value is greater than the first threshold. For example, the second threshold can be set to 1 million records.

[0137] Specifically, under the batch streaming computing strategy, the system divides the detailed result set into multiple batches according to a fixed batch size. This fixed batch size can be pre-configured by the system, for example, loading 10,000 or 50,000 records per batch. The system sequentially loads the data of each batch into memory, and the streaming statistical computing subchain performs statistical calculations on the batch data to generate intermediate calculation results for that batch. After completing the calculation of each batch, the system merges the intermediate results of that batch with the cumulative results of the previous batches, then releases the memory occupied by the current batch, and loads the next batch of data to continue the calculation until all batches have been processed.

[0138] The key feature of this strategy is that only one batch of data resides in memory at a time, and memory usage is independent of the total data volume, depending solely on the batch size setting. By properly configuring the batch size, the system can minimize batch switching overhead while ensuring memory safety, achieving a good balance between query performance and memory usage. Compared to the all-in-memory direct computation strategy, the batch streaming computation strategy sacrifices some computational speed (due to the additional overhead of batch loading and merging intermediate results), but significantly reduces the memory capacity requirements, enabling it to safely handle medium-sized datasets.

[0139] Step S403: When the estimated data volume is greater than or equal to the second threshold, perform hash sharding according to the grouping dimension value, split the full data into several independent shards, and create a global aggregation variable to store the final statistical results; sequentially read each shard into memory, perform local aggregation calculation on the current shard, and generate the intermediate result of the shard; incrementally merge the intermediate result with the current value of the global aggregation variable to update the global aggregation variable, and immediately release the memory of the current shard after merging; repeat the process until all shards are processed.

[0140] In this step, when the estimated data volume is greater than or equal to the second threshold, the system determines that the current query data volume is large-scale (e.g., millions, tens of millions or even hundreds of millions of records), and adopts a calculation strategy of hash sharding plus local aggregation plus incremental merging to keep memory usage within a safe range.

[0141] Specifically, the computational strategy includes the following sub-steps: (1) Hash Sharding. The system performs hash sharding on the full data according to the grouping dimension value. For example, if the grouping dimension of the statistical query is the organization code (org_code), the system performs a hash operation on the organization code of each record, and distributes the full data into several independent shards according to the hash value. Each shard corresponds to a specific range of hash values. The goal of hash sharding is to ensure that all records with the same grouping dimension value are assigned to the same shard, thereby ensuring that each shard can perform local aggregation calculations independently.

[0142] (2) Create a global aggregation variable. The system creates a global aggregation variable in memory to store the final statistical results. Before processing begins, this global aggregation variable is initialized to its initial state (e.g., each statistical value is zero or null), and is subsequently updated gradually as each slice is processed.

[0143] (3) Read individual shards into memory sequentially. The system reads shards one by one in sequence, loading the data of only one shard into memory at a time. For each shard, the system performs local aggregation calculations on the data within that shard to generate intermediate results for that shard. Local aggregation refers to performing aggregation calculations within a shard according to the grouping dimension. Since records with the same grouping dimension have been hashed to the same shard, aggregation of the key-value range covered by that shard can be completed independently within that shard.

[0144] (4) Incremental merging and memory release. The system incrementally merges the intermediate results of the current fragment with the current value of the global aggregation variable to update the global aggregation variable. After the merge is completed, the intermediate results of the current fragment have fulfilled their purpose, and the system immediately releases the memory space occupied by the fragment before loading the next fragment. By releasing fragment memory in a timely manner, the system ensures that only the data volume of one fragment always resides in memory.

[0145] (5) Loop processing. The system loops through steps (3) and (4) above, processing all shards in sequence until all shards have been processed. After all shards have been processed, the final statistical result is stored in the global aggregation variable.

[0146] The technical advantage of this strategy lies in splitting a large dataset into multiple independent and processable smaller shards using hash sharding. Through a pipelined processing flow of "sequential loading, local computation, incremental merging, and immediate release," memory usage is stabilized at the size of a single shard, completely decoupling it from the total data volume. For example, for a dataset of 5 million records, if it is split into 10 shards using hash sharding, with each shard containing approximately 500,000 records, the peak memory usage is only that of a single shard containing 500,000 records, about one-tenth of the full-load solution, resulting in a memory reduction of over 90%.

[0147] The computational strategies at the three levels (S401, S402, and S403) described above constitute a complete adaptive hierarchical streaming computing model. This model automatically adapts different computational strategies based on the data volume: small data volumes prioritize speed, medium data volumes balance performance and memory usage, and large data volumes prioritize memory safety. The collaborative efforts of these three levels enable the system to stably complete statistical calculations regardless of the data volume, completely eliminating the risk of memory overflow in large result set statistical scenarios.

[0148] In some embodiments of this application, the above-mentioned persistent result set cache adopts a hybrid storage of a memory hot data layer and a disk cold data layer. The memory hot data layer uses the LRU algorithm to manage the access frequency of the cached result set. When the access frequency decreases, it is automatically migrated to the disk cold data layer for persistent storage. The data in the disk cold data layer is not lost after the service restarts.

[0149] Specifically, the persistent result set cache is divided into two storage layers from bottom to top: a disk cold data layer and a memory hot data layer.

[0150] The hot memory data layer is a high-speed cache area located in system memory (RAM) used to store the most frequently accessed detailed result sets. Due to the extremely fast read and write speeds of memory, detailed result sets stored in the hot memory data layer can be read with latency in the microsecond to millisecond range, thus providing extremely fast response times for high-frequency queries. However, memory capacity is relatively limited and costly, and it cannot accommodate all cached detailed result sets.

[0151] To address the aforementioned issues, the memory-based hot data layer employs the Least Recently Used (LRU) algorithm to manage the access frequency of cached result sets. Specifically, the system maintains an access record for each detailed result set in the memory-based hot data layer, recording its most recently accessed timestamp and cumulative access frequency. When a new detailed result set needs to be written to the memory-based hot data layer but the current memory space is full, the LRU algorithm automatically identifies and evicts the least recently used detailed result set, selecting the cached entry that has not been accessed for the longest time and removing it from the memory-based hot data layer to free up the memory space occupied by it, making room for the new cached entry. Through the LRU algorithm's frequency management, the memory-based hot data layer always retains the most frequently accessed hot data, maximizing the query acceleration benefits of limited hardware memory resources.

[0152] The aforementioned disk cold data layer is a persistent storage area based on solid-state drives (SSDs) or other non-volatile storage media, used to store detailed result sets that are migrated from the memory hot data layer and have a lower access frequency. Compared to the memory hot data layer, the disk cold data layer has a slower access speed (millisecond-level latency), but its storage capacity is much larger than memory, capable of storing terabyte-level result sets, and its storage cost is relatively low.

[0153] In this embodiment, when the access frequency of a specific result set in the memory hot data layer drops below a preset threshold, the system automatically migrates the result set from the memory hot data layer to the disk cold data layer for persistent storage. The migration operation is performed asynchronously in the background and does not block ongoing query requests. After the migration is complete, the original memory space of the result set is released, and the physical storage location information corresponding to the cache fingerprint in the cache index table is updated to the new address in the disk cold data layer. If a subsequent query request accesses the result set, the system retrieves its disk storage address from the cache index table, streams it from the disk cold data layer, and returns it. Simultaneously, the access frequency of the result set is updated. If the access frequency subsequently increases again, the system can re-promote it to the memory hot data layer.

[0154] Data in the aforementioned disk cold data layer is not lost after a service restart. Specifically, when detailed result sets are written to the disk cold data layer, they are persisted to disk in the file system as files or other persistent formats. When the system service restarts due to upgrades, failures, or other reasons, the detailed result set files already persistently stored in the disk cold data layer are unaffected. After the system restarts, the storage directory of the disk cold data layer can be scanned, and the cache index table can be rebuilt, ensuring that the cached data remains available after the service recovers without needing to re-query the source database to populate the cache. This mechanism ensures the effectiveness of the persistent result set cache across sessions and across service lifecycles.

[0155] Through the collaborative work of the above two-level storage of hot memory data layer and cold disk data layer, persistent result set caching can provide millisecond-level memory read response for high-frequency queries, break through memory capacity limitations to achieve persistent storage of TB-level large result sets, and also have the reliability guarantee that the data will not be lost when the service is restarted.

[0156] Furthermore, in some embodiments of this application, the above-mentioned detailed result set is divided into data blocks with a fixed number of rows in both the hot data layer in memory and the cold data layer on disk, and each block is stored independently. The streaming read is performed sequentially according to the data blocks.

[0157] Specifically, whether the detailed result set is stored in the hot data layer in memory or the cold data layer on disk, it is organized and managed using data blocks as the basic storage unit. When writing the detailed result set, the system divides the complete detailed result set into multiple data blocks according to a preset fixed number of rows. Each data block contains a fixed number of data records, and the data blocks are stored independently and decoupled from each other.

[0158] For example, the system can be configured to divide every 10,000 records into a data block. If a detailed result set contains 250,000 records, the result set is divided into 25 data blocks, each containing 10,000 records. The last data block may have fewer rows than a preset fixed number (e.g., when the total number of rows is not divisible by the fixed number of rows), and the system will still store it as an independent data block.

[0159] The aforementioned data block partitioning operation is performed when the detailed result set is first written to the persistent result set cache. It should be noted that when the detailed result set is subsequently migrated from the hot memory data layer to the cold disk data layer due to reduced access frequency, its data block partitioning method remains unchanged, and there is no need to re-partition. That is, once the data blocks are partitioned, the block structure remains consistent throughout the migration process at the storage level.

[0160] Each data block has an independent storage identifier or storage address when stored. In the memory hot data layer, each data block occupies an independent memory area; in the disk cold data layer, each data block is stored as an independent file or an independent storage segment. Through block-level independent storage, the system can flexibly load, evict, migrate, or clean up individual data blocks without operating on the entire result set, significantly improving the granularity and efficiency of cache management.

[0161] Building upon the aforementioned block-based storage, the streaming statistical computation subchain reads detailed result sets from the persistent result set cache block by block. Specifically, the system first retrieves the storage metadata information of the detailed result set from the cache index table, including the total number of data blocks and the storage address or identifier of each data block. Then, the system reads the data blocks into memory one by one according to their logical order (i.e., the order in which the data is arranged in the original result set). For each data block read, the streaming statistical computation subchain performs statistical calculations on the records within that data block; after processing the data block, the system releases the memory it occupies and then reads the next data block, until all data blocks have been processed.

[0162] Through the block-based streaming mechanism described above, the system maintains only one data block in memory at any given time. Memory usage is independent of the total data volume of the detailed result set, depending only on the size of a single data block. For example, regardless of whether the detailed result set contains 1 million or 10 million records, if each data block contains 10,000 rows, the memory usage during streaming will always be approximately the memory space occupied by 10,000 rows. Therefore, this embodiment fundamentally eliminates the risk of memory overflow in statistical calculations of large result sets, enabling the system to stably handle statistical analysis tasks of any data volume.

[0163] Furthermore, since data blocks adopt a unified block structure and storage format in the memory hot data layer and the disk cold data layer, the streaming computing subchain does not need to be aware of whether the data is actually stored in memory or on disk. It can transparently access the data in the two storage layers through a unified block read interface, thus completely shielding the upper-layer computing engine from the differences in storage layers.

[0164] In some embodiments of this application, the above-mentioned statistical cache uses the combination of the cache fingerprint and the statistical configuration of the current query as the cache key, and different statistical indicators derived from the same detailed result set are cached independently; when the detailed result set becomes invalid due to a change in the corresponding current data version number, all statistical caches mounted under the detailed result set become invalid.

[0165] Specifically, the statistics cache is a second-level cache independent of the persistent result set cache. It is used to store the calculated statistical results and avoid duplicate calculations of the same statistical configuration.

[0166] The cache key for the statistical caching consists of two parts: the first part is the cache fingerprint generated in step S101, used to uniquely identify the detailed result set on which the statistical measure is based; the second part is the statistical configuration of the current query, used to uniquely identify the specific statistical calculation method. The statistical configuration includes, but is not limited to: statistical indicator type (e.g., summation, average, median, mode, percentile, deduplication count, etc.), grouping dimension (e.g., grouping by organization code, grouping by product category, grouping by time dimension, etc.), statistical range (e.g., statistics on all records or statistics on subsets that meet specific conditions), and statistical parameters (e.g., specific percentile values ​​of percentiles, etc.).

[0167] The system combines the cache fingerprint with the statistical configuration to generate a statistical cache key. This combination method can be concatenation, hashing, or any other applicable method, as long as it ensures that different combinations of cache fingerprints and statistical configurations correspond to a unique statistical cache key.

[0168] A single detailed result set can derive multiple different statistical indicators, each stored and managed independently in the statistical cache. For example, for the same sales detail result set, a user can sequentially request four different statistical indicators: sum, average, median, and mode. The system generates independent statistical cache entries for each of these four statistical configurations, and each entry independently stores its corresponding statistical calculation result. Updating or evicting one statistical indicator's cache will not affect the cache status of other statistical indicators.

[0169] The technical advantage of the aforementioned independent caching mechanism is that when a user adjusts statistical indicators multiple times (e.g., switching from summation to average and then to median), the caches of each statistical indicator do not interfere with each other. When the user switches back to a previously calculated statistical indicator, the system directly returns the result from the statistical cache without re-executing the operator chain calculation.

[0170] There is a cascading failure relationship between the statistics cache and the persistent result set cache. When a detailed result set becomes invalid due to a change in the source data version number, all statistics caches attached to that detailed result set also become invalid.

[0171] Specifically, when the system detects a change in the current data version number corresponding to a persistent result set cache (i.e., the source data table has undergone add, delete, or modify operations after the cache was generated), the detailed result set is marked as invalid. Simultaneously, the system automatically marks all statistical cache entries associated with this detailed result set as invalid. This cascading invalidation mechanism can be implemented in ways including, but not limited to: embedding a corresponding cache fingerprint into the cache key of the statistical cache; periodically scanning the statistical cache; and when the system finds that a detailed result set corresponding to a certain cache fingerprint has become invalid, simultaneously cleaning up all statistical cache entries containing that cache fingerprint; or, the system proactively triggers a cleanup event when a detailed result set becomes invalid, deleting all statistical cache entries prefixed with or containing that cache fingerprint.

[0172] The aforementioned cascading failure mechanism ensures that the statistics cache will not return statistical results calculated based on expired detailed data, fundamentally guaranteeing the consistency between the statistical results and the source data. Furthermore, this mechanism eliminates the need to maintain separate version information or failure logic for the statistics cache, directly reusing versioned failure checks of the detailed result set, thus reducing the complexity of system implementation.

[0173] In some embodiments of this application, such as Figure 5 As shown, in addition to steps S101 to S104, step S105 is also included: periodically scanning the cache index table, determining whether the corresponding cache has expired based on the current data version number, and if expired, asynchronously cleaning up the corresponding storage space in the persistent result set cache.

[0174] Specifically, in this embodiment, the system is equipped with a background cache cleanup thread. This thread is triggered to execute according to a preset time period (e.g., every 10 minutes or 30 minutes), or it is triggered to execute by the scheduler when system resources are relatively idle. When the cache cleanup thread is triggered, the system scans all cache records in the cache index table and checks the validity status of each cache entry one by one.

[0175] The validity of the cache is determined by the current data version number. Specifically, during the scanning process, for each cache record in the cache index table, the system reads the actual data version number of the source data table associated with that record at the current moment (the acquisition method is the same as in step S205), and compares this actual data version number with the data version number stored in the cache record at the time of its creation. If the two match, it means that since the cache was created, the associated source data table has not undergone data changes, and the cache is still a valid cache and is retained. If the two do not match, the cache is determined to be invalid, and the data reflected in its corresponding detailed result set is no longer the latest state of the source data table and should no longer be used in subsequent queries.

[0176] When a cache entry is determined to be invalid, the system performs a cache cleanup operation. Specifically, the system updates the status flag of the cache entry in the cache index table to "invalid," preventing the cache hit determination in subsequent step S102 from hitting that cache. Simultaneously, the system initiates an asynchronous cleanup task to delete the persistent storage space corresponding to the cache entry, including releasing the corresponding memory area from the hot data layer in memory and deleting the corresponding storage file from the cold data layer on disk. Asynchronous cleanup means that the cleanup operation is performed in a background thread, without blocking any ongoing user query requests or statistical calculation tasks. The system main thread returns immediately after triggering the cleanup operation to continue processing the next scan task or responding to a new query request.

[0177] It should be noted that the cache cleanup mechanism in this embodiment works in conjunction with the aforementioned versioned invalidation mechanism to form a complete cache lifecycle management scheme. Steps S101 to S104 implement query-driven lazy invalidation, meaning that when the cache has expired but there are no new queries accessing it, the expired cache still occupies storage space but will not be considered a cache hit. Step S105 adds a background active scanning and cleanup mechanism to periodically remove expired cache from physical storage and reclaim storage resources. The two complement each other: lazy invalidation ensures strong consistency between the cache and the source data, while background cleanup ensures the sustainable use of storage space and avoids the waste of storage resources caused by the continuous accumulation of expired cache.

[0178] Through the aforementioned background cache cleanup mechanism, this embodiment of the application achieves adaptive management of persistent result set cache storage space, which can maintain the effective utilization of storage space without manual intervention, further reducing the system's operation and maintenance costs.

[0179] As described above, the streaming statistical analysis method based on persistent result set caching provided in this application achieves cross-task, cross-session, and cross-user persistent result set cache reuse through a multi-dimensional cache fingerprint generation mechanism at the query semantic level. This eliminates the need for repeated access to the source database for statistical queries with the same semantics, improving cache reuse rate by over 70%. Simultaneously, by constructing a streaming statistical computation sub-chain, secondary statistical analysis is executed directly based on the materialized detailed result set without returning to the source, reducing data source access times by over 60%. Furthermore, all statistical algorithms are uniformly implemented at the operator chain layer, reducing the adaptation cost of statistical functions for new data sources by over 90%. Building upon this, this application also utilizes a block storage and streaming read mechanism, combined with an adaptive hierarchical streaming computation model for cache misses, to minimize the memory usage of statistical computation. By decoupling from the total data volume, the peak memory usage for large result set statistics is reduced by more than 90%, completely eliminating the risk of memory overflow. On the other hand, this application incorporates the source data version identifier into the cache fingerprint. When the source data changes, the version number changes, causing the corresponding cache fingerprint to automatically expire. This eliminates the need to rely on fixed TTL expiration or binlog / CDC change detection components, ensuring strong consistency between the cache and the source data while maintaining a high cache hit rate. Furthermore, through the priority hit mechanism of the statistical secondary cache, calculated statistical indicators can be directly returned without repeating operator chain calculations, achieving millisecond-level response speed for repeated adjustments of statistical indicators. Ultimately, this significantly reduces database load and multi-data source adaptation costs, comprehensively enhances system stability, and significantly improves the response speed and user experience of statistical queries.

[0180] like Figure 6 The diagram shown is a schematic representation of a streaming statistical analysis system based on a persistent result set cache, according to an embodiment of this application. The system includes: The fingerprint generation unit 610 is used to generate a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request; The judgment unit 620 is used to query the cache index table based on the cache fingerprint to determine whether there is a corresponding valid persistent result set cache. The first processing unit 630 is used to query the statistics cache in response to a valid cache hit. If the statistics cache is hit, the statistical result is returned directly. If the statistics cache is not hit, the corresponding detailed result set is read from the persistent result set cache in a streaming manner. The streaming statistical calculation subchain is used to perform streaming statistical calculation on the detailed result set to obtain the statistical result and return it. At the same time, the statistical result is written to the statistics cache. The second processing unit 640 is used to perform a detailed data query on the source database in response to a missed valid cache, and to perform streaming statistical calculations on the detailed result set returned by the query through the streaming statistical calculation subchain to obtain statistical results and return them. At the same time, the detailed result set is asynchronously written into the persistent result set cache in blocks and the cache index table is updated.

[0181] Detailed descriptions of each of the above units can be found in the relevant descriptions of the foregoing method embodiments, and will not be repeated here. Furthermore, the beneficial effects of the streaming statistical analysis system based on persistent result set caching provided in this embodiment can also be found in the corresponding descriptions of the foregoing method embodiments.

[0182] Figure 7 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Figure 7 The illustrated electronic device is a general-purpose data processing apparatus, comprising a general-purpose computer hardware architecture, including at least a processor 801 and a memory 802. The processor 801 and memory 802 are connected via a bus 803. The memory 802 is adapted to store one or more instructions or programs executable by the processor 801. These instructions or programs are executed by the processor 801 to implement the steps in the aforementioned streaming statistical analysis method based on a persistent result set cache.

[0183] The processor 801 described above can be a standalone microprocessor or a collection of one or more microprocessors. Thus, the processor 801 executes commands stored in the memory 802, thereby performing the method flow of the embodiments of the present invention as described above to process data and control other devices. The bus 803 connects the aforementioned components together, and also connects these components to the display controller 804, the display device, and the input / output (I / O) device 805. The input / output (I / O) device 805 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output (I / O) device 805 is connected to the system via an input / output (I / O) controller 806.

[0184] The memory 802 can store software components, such as an operating system, a communication module, an interaction module, and application programs. Each of the modules and application programs described above corresponds to a set of executable program instructions that perform one or more functions and the methods described in the embodiments of the invention.

[0185] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the above-described streaming statistical analysis method based on persistent result set caching.

[0186] This invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the above-described streaming statistical analysis method based on persistent result set caching.

[0187] The streaming statistical analysis method and system based on persistent result set caching provided in this application achieve cross-task, cross-session, and cross-user persistent result set cache reuse through a multi-dimensional cache fingerprint generation mechanism at the query semantic level. This eliminates the need for repeated access to the source database for statistical queries with the same semantics, improving cache reuse rate by over 70%. Simultaneously, by constructing a streaming statistical computation sub-chain, secondary statistical analysis can be executed directly based on the materialized detailed result set without returning to the source, reducing data source access times by over 60%. Furthermore, all statistical algorithms are uniformly implemented at the operator chain layer, reducing the adaptation cost of statistical functions for new data sources by over 90%. Building upon this, this application also utilizes a block storage and streaming read mechanism, combined with an adaptive hierarchical streaming computation model for cache misses, to reduce the memory consumption of statistical computation. The total data volume is decoupled, reducing peak memory usage for large result set statistics by over 90% and completely eliminating the risk of memory overflow. On the other hand, this application incorporates the source data version identifier into the cache fingerprint. When the source data changes, the version number changes, causing the corresponding cache fingerprint to automatically expire. This eliminates the need to rely on fixed TTL expiration or binlog / CDC change detection components, ensuring strong consistency between the cache and the source data while maintaining a high cache hit rate. Furthermore, through the priority hit mechanism of the statistical secondary cache, calculated statistical indicators can be directly returned without repeating operator chain calculations, achieving millisecond-level response speeds for repeated adjustments of statistical indicators. Ultimately, this significantly reduces database load and multi-data source adaptation costs, comprehensively enhances system stability, and significantly improves the response speed and user experience of statistical queries.

[0188] Preferred embodiments of the invention have been described above with reference to the accompanying drawings. Many features and advantages of these embodiments are apparent from this detailed description, and therefore the claims are intended to cover all such features and advantages of these embodiments that fall within their true spirit and scope. Furthermore, since many modifications and alterations will readily occur to those skilled in the art, the embodiments of the invention are not intended to be limited to the precise structures and operations illustrated and described, but rather to encompass all suitable modifications and equivalents falling within their scope.

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

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

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

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

[0193] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A streaming statistical analysis method based on persistent result set caching, characterized in that, The method includes: A unique cache fingerprint is generated based on the query semantics, user permissions, and source data version identifier in the user query request. Based on the cache fingerprint query, determine whether there is a corresponding valid persistent result set cache. If a valid cache is hit, the statistics cache is queried. If a hit is found, the statistical result is returned directly. If the statistics cache is not hit, the corresponding detailed result set is read from the persistent result set cache in a streaming manner. The streaming statistical calculation subchain is used to perform streaming statistical calculation on the detailed result set to obtain the statistical result and return it. At the same time, the statistical result is written to the statistics cache. In response to a missed cache hit, a detailed data query is performed on the source database, and streaming statistical calculations are performed on the detailed result set returned by the query through the streaming statistical calculation subchain to obtain and return the statistical results. At the same time, the detailed result set is asynchronously written in blocks to the persistent result set cache and the cache index table is updated.

2. The streaming statistical analysis method based on persistent result set caching as described in claim 1, characterized in that, The process of generating a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request includes: Obtain the query columns, filter conditions, and sorting conditions from the user's query request, and assemble them into a detailed query statement; The detailed query statement is standardized and normalized to obtain a standardized query statement; The query parameters in the user query request are sorted in a fixed order by key name, and all sorted key-value pairs are concatenated sequentially to obtain a sorted parameter set. Extract the data permission context from the user query request. When the data permission context is not included in the sorted parameter set, save the data permission context as an independent element. Retrieve the current data version number of all source data tables involved in the user's query; The standardized query statement, the sorted parameter set, the current data version number, and the data permission context not included in the sorted parameter set are combined and hashed to generate the cache fingerprint.

3. The streaming statistical analysis method based on persistent result set caching as described in claim 2, characterized in that, The standardization and normalization of the detailed query statement to obtain a standardized query statement includes: Remove extra spaces and extra line breaks from the detailed query statement, and unify the keywords to lowercase or uppercase. Replace the parameters in the detailed query statement with placeholders; The table aliases in the detailed query statement are unified to preset standard aliases, and the sorting direction in the sorting conditions is normalized to preset standard sorting direction. The set of values ​​for multi-valued parameters in the detailed query statement is extracted from the SQL statement and replaced with placeholders, so that the detailed query statement retains only the query structure.

4. The streaming statistical analysis method based on persistent result set caching as described in claim 2, characterized in that, The step of obtaining the current data version number of all source data tables involved in the user query includes: Based on the range of non-multi-value parameters queried by the user, the maximum value of the last update time of the source data table within the range is taken as the data version number of the corresponding source data table. When the query involves multiple source data tables, the maximum value of the data version numbers of each source data table is taken as the current data version number. The query results for the data version number have a short-term cache with a configurable duration. Repeated queries within the cache duration return results directly from the short-term cache to avoid accessing the source database.

5. The streaming statistical analysis method based on persistent result set caching as described in claim 1, characterized in that, The streaming statistics subchain is composed of several operators assembled in execution order. The operators are selected from the built-in operator library, which includes filtering operators, aggregation operators, advanced statistics operators, and processing operators. The streaming computing subchain adopts a streaming mode of reading, computing, and outputting simultaneously, processing data block by block, with a single memory usage that is stable at the size of a single data block.

6. The streaming statistical analysis method based on persistent result set caching as described in claim 2, characterized in that, The method also includes the step of determining the estimated data volume: In response to a valid cache hit, the amount of data in the corresponding persistent result set cache is read from the cache index table as the estimated data amount; In response to a missed valid cache, a counting query is performed on the detailed query statement to obtain the exact number of rows as the estimated data volume. If the counting query times out or the source database does not support it, it is processed according to the maximum data volume level.

7. The streaming statistical analysis method based on persistent result set caching as described in claim 6, characterized in that, When performing streaming statistical calculations, the streaming statistical calculation subchain uses an adaptive hierarchical streaming calculation model to control memory usage based on the estimated data volume, specifically including: When the estimated data volume is less than the first threshold, a full-memory direct calculation strategy is adopted to load the data into memory at once to complete all statistical calculations. When the estimated data volume is greater than or equal to the first threshold and less than the second threshold, a batch streaming computing strategy is adopted to load data sequentially with a fixed batch size and perform statistical calculations. When the estimated data volume is greater than or equal to the second threshold, hash sharding is performed according to the grouping dimension value to split the full data into several independent shards. A global aggregation variable is created to store the final statistical results. Each shard is read into memory in turn, and local aggregation calculation is performed on the current shard to generate the intermediate result of the shard. The intermediate result is incrementally merged with the current value of the global aggregation variable to update the global aggregation variable. The memory of the current shard is released immediately after the merge is completed. The process is repeated until all shards are processed.

8. The streaming statistical analysis method based on persistent result set caching as described in claim 1, characterized in that, The persistent result set cache uses a hybrid storage of a memory hot data layer and a disk cold data layer. The memory hot data layer uses the LRU algorithm to manage the access frequency of cached result sets. When the access frequency decreases, the cached result sets are automatically migrated to the disk cold data layer for persistent storage. The data in the disk cold data layer is not lost after the service restarts.

9. The streaming statistical analysis method based on persistent result set caching as described in claim 8, characterized in that, The detailed result set is divided into data blocks with a fixed number of rows in both the hot data layer in memory and the cold data layer on disk. Each block is stored independently, and the streaming read is performed sequentially according to the data blocks.

10. The streaming statistical analysis method based on persistent result set caching as described in claim 1, characterized in that, The statistical cache uses the combination of the cache fingerprint and the statistical configuration of the current query as the cache key. Different statistical indicators derived from the same detailed result set are cached independently. When the detailed result set becomes invalid due to a change in the corresponding current data version number, all statistical caches attached to the detailed result set become invalid as well.

11. The streaming statistical analysis method based on persistent result set caching as described in claim 2, characterized in that, The method further includes: The cache index table is periodically scanned, and the corresponding cache is determined to be invalid based on the current data version number. If invalid, the corresponding storage space in the persistent result set cache is asynchronously cleaned up.

12. A streaming statistical analysis system based on persistent result set caching, characterized in that, The system includes: The fingerprint generation unit is used to generate a unique cache fingerprint based on the query semantics, user permissions, and source data version identifier in the user query request; The judgment unit is used to query the cache index table based on the cache fingerprint to determine whether there is a corresponding valid persistent result set cache. The first processing unit is used to query the statistics cache in response to a valid cache hit. If the statistics cache is hit, the statistical result is returned directly. If the statistics cache is not hit, the corresponding detailed result set is read from the persistent result set cache in a streaming manner. The streaming statistical calculation subchain is used to perform streaming statistical calculation on the detailed result set to obtain the statistical result and return it. At the same time, the statistical result is written to the statistics cache. The second processing unit is used to perform a detailed data query on the source database in response to a missed valid cache, and to perform streaming statistical calculations on the detailed result set returned by the query through the streaming statistical calculation subchain to obtain statistical results and return them. At the same time, the detailed result set is asynchronously written into the persistent result set cache in blocks and the cache index table is updated.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.

14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.

15. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 11.