A query method, device and medium of a time series database
By using pattern-aware compression and on-demand materialization in a multi-granularity aggregation pyramid structure, the problem of insufficient flexibility in aggregation queries in existing time-series databases is solved. This enables dynamic adjustment of query paths to optimize query latency and resource efficiency without affecting write performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HIGHGO SOFTWARE
- Filing Date
- 2026-05-28
- Publication Date
- 2026-06-26
AI Technical Summary
Existing time-series databases lack flexibility when executing aggregate queries, failing to intelligently balance user accuracy requirements with real-time query requirements, resulting in excessive query latency and resource consumption.
A multi-granularity aggregation pyramid structure with pattern-aware compression and on-demand progressive materialization is adopted. Data features are extracted and classified by a time-series pattern detector, and an appropriate compression coding strategy is selected to construct a multi-level time aggregation pyramid. The aggregation summary of high-level nodes is calculated only on demand when a query request is made.
It enables intelligent services that provide low latency and high resource efficiency for diverse aggregate queries without compromising data write performance. It can dynamically adjust the query path based on the query request to optimize query accuracy and latency.
Smart Images

Figure CN122285753A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a query method, device and medium for a time-series database. Background Technology
[0002] Time series data is an ordered collection of data points collected in chronological order, and it is widely used in fields such as IoT monitoring, operations and maintenance monitoring, and financial analysis. Its core characteristics include massive data volume, high write throughput, and queries primarily involving aggregation analysis across time ranges.
[0003] Existing query engines typically employ a simple "hit or rollback" strategy when executing aggregate queries: if the query requirement matches the materialized pre-aggregation granularity, the pre-aggregation result is read directly; otherwise, it must roll back to the path of fully scanning the original data. This binary strategy lacks flexibility and cannot intelligently balance and adaptively select between query accuracy and response latency based on the user's precision requirements (exact or approximate) and the real-time requirements of the query. Summary of the Invention
[0004] This specification provides one or more embodiments of a time-series database query method, device, and medium to solve the technical problems raised in the background art.
[0005] One or more embodiments of this specification employ the following technical solutions: This specification provides one or more embodiments of a time-series database query method, the method comprising: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0006] This specification provides one or more embodiments of a time-series database query device, comprising: At least one processor and bus; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0007] This specification provides one or more embodiments of a non-volatile computer storage medium storing computer-executable instructions, which, when executed by a computer, can perform the following: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0008] The above-described at least one technical solution adopted in the embodiments of this specification can achieve the following beneficial effects: This method fundamentally changes the resource base and decision space of query execution by introducing "pattern-aware compression" and "on-demand progressive materialization of a multi-granularity aggregation pyramid" as the core storage and indexing structure. During data writing, the method not only adaptively compresses data according to time-series patterns to optimize storage, but also simultaneously generates the block-level summaries necessary for building the aggregation index, a process that adds almost no write overhead. The multi-level aggregation pyramid built on this foundation does not pre-compute all high-level aggregation data during writing; instead, it strictly adheres to the "on-demand materialization" principle, meaning that aggregation results at a certain time granularity are only calculated and cached in real-time by merging lower-level summaries when touched by an actual query request. This design breaks down the binary opposition between "full pre-computation" and "no pre-computation," avoiding the blind consumption of storage and computing resources from the source.
[0009] Based on this dynamic and economical index structure, the query engine gains unprecedented flexibility in responding to requests. The engine can intelligently select the optimal solution from multiple predetermined execution paths based on the specific time range, output granularity, and precision requirements specified in the query request, combined with the real-time materialization status of nodes at each level of the pyramid. Optional paths include directly reading the precise materialized results, temporarily merging and calculating the precise results of unmaterialized nodes, using high-level summaries for approximate estimation, or rolling back to scanning the original data. This multi-path adaptive routing mechanism allows the system to proactively and dynamically balance and optimize query precision, latency, and system computational overhead, thereby overcoming the rigidity of the "hit or rollback" strategy in the background technology. Ultimately, it achieves intelligent services that balance low latency and high resource efficiency for diverse aggregation queries without compromising data write performance. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments or prior art of this specification, the drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings: Figure 1 A flowchart illustrating a time-series database query method provided in one or more embodiments of this specification; Figure 2 This is a schematic diagram of the structure of a time-series database query device provided in one or more embodiments of this specification. Detailed Implementation
[0011] This specification provides a method, device, and medium for querying time-series databases.
[0012] Existing time-series databases cannot achieve coordinated optimization between compression ratio, write throughput, and multi-granularity query performance when faced with massive amounts of time-series data with mixed patterns.
[0013] Specifically, current time-series data storage and querying face the following technical challenges: On the one hand, existing time-series databases generally adopt a "one-size-fits-all" fixed compression strategy (such as uniformly using Delta-of-Delta encoding or Gorilla compression), applying the same compression algorithm to all time-series data segments without distinction. However, actual time-series data contains a mixture of various time-series patterns, such as periodic fluctuations, monotonic trends, stationary randomness, and burst pulses. Fixed compression strategies cannot select the optimal encoding scheme for each pattern when facing heterogeneous patterns, resulting in a compression rate significantly lower than the theoretical optimal value and serious waste of storage space. On the other hand, when performing aggregation queries across time ranges (such as hourly averages, daily peaks, weekly trends, etc.), existing time-series databases need to scan the original data points from the underlying storage and calculate the aggregation results in real time. When the query time span is large (such as querying the hourly average of the past year), billions of original data points need to be scanned, causing the query latency to degrade from milliseconds to minutes or even longer, seriously affecting the user experience in monitoring, alarming, and real-time analysis scenarios.
[0014] Furthermore, while existing pre-aggregation solutions can shorten query latency, their full pre-computation strategy—calculating all pre-defined aggregation results at the moment of data writing and persisting them—adds a large amount of aggregation computation overhead to the write path, resulting in a significant reduction in write throughput. This becomes a performance bottleneck in high-speed data ingestion scenarios (such as millions of data points per second for IoT (Internet of Things) sensors). On the other hand, the redundant aggregated data generated by full pre-aggregation further increases storage overhead, and most of the pre-aggregated results are never accessed by queries.
[0015] Time series data refers to an ordered set of data points collected in chronological order, with each data point consisting of a timestamp and one or more metrics. Time series data is widely used in IoT device monitoring (sensor temperature, humidity, pressure, etc.), IT infrastructure operations and maintenance (CPU (Central Processing Unit) utilization, memory usage, network traffic, etc.), financial markets (stock prices, trading volume, etc.), and industrial production (equipment vibration frequency, output, etc.). Its core characteristics include: large data volume (billions to trillions of data points per day), high write frequency (millisecond or even microsecond-level collection intervals), strong temporal locality (recent data is accessed much more frequently than historical data), and queries primarily based on aggregation analysis (mean, maximum, minimum, percentiles, trend change rate, etc.).
[0016] Time-series data compression is one of the core technologies of time-series databases, aiming to reduce storage overhead while maintaining data queryability. Mainstream time-series data compression algorithms include: Delta encoding stores the difference between adjacent data points instead of the original value. It is suitable for slowly changing time-series data, and the compression ratio depends on the distribution range of the difference. Delta-of-Delta encoding (Double-Delta Encoding): Based on Delta encoding, the difference is calculated again to further narrow the encoding range. It is suitable for linearly increasing sequences such as timestamps. Gorilla Compression: A lossless compression scheme for floating-point time-series data. It uses Delta-of-Delta encoding for timestamps and XOR encoding for metrics (only storing the valid bits of the XOR result of adjacent floating-point numbers). It can achieve an average compression ratio of 12 times in monitoring data scenarios. Dictionary encoding: Creates a dictionary mapping for recurring values, replacing the original values with short codes, suitable for low cardinality label columns; RLE (Run-Length Encoding): Encodes consecutively repeating values as a pair of values and the number of repetitions. It is suitable for time series data that are continuously unchanged or change in a stepwise manner.
[0017] LSM (Log-Structured Merge Tree) is a storage engine data structure widely used in high write throughput scenarios. Its core idea is to transform random writes into sequential writes: data is first written to a mutable data structure (MemTable) in memory. When the MemTable reaches its capacity threshold, it is frozen into an immutable ImmutableMemTable and flushed to become an ordered file (SSTable / SST file) on disk. A background thread periodically performs a merging and compaction operation on multiple SST files to reduce the number of files and eliminate expired data.
[0018] Pre-aggregation is a query acceleration strategy that trades space for time. It pre-computes aggregation results at fixed time granularity when data is written and persists them. During queries, the pre-computed results are read directly without scanning the original data. Common implementations of pre-aggregation include materialized views, continuous aggregation, and downsampling.
[0019] Time series decomposition is a classic method in time series analysis, which decomposes the original time series into trend components, seasonal / cyclical components, and residual components. Commonly used decomposition methods include classical decomposition and STL decomposition (Seasonal and Trend decomposition using Loess, based on locally weighted regression).
[0020] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0021] Figure 1 This diagram illustrates a query method for a time-series database provided in one or more embodiments of this specification. This process can be executed by a time-series database query system. Certain input parameters or intermediate results in the process can be manually adjusted to help improve accuracy.
[0022] The method flow steps of the embodiments in this specification are as follows: S101, Receive time-series data stream. When the accumulated data points of the same time series reach the preset size of the analysis window, trigger the time-series pattern detector. Extract multiple statistical features of the data points within the window through the time-series pattern detector, and classify the current data segment into patterns based on the preset priority rule chain, and output the pattern label.
[0023] In the embodiments described in this specification, the system can set a fixed-size analysis window (e.g., 256 data points). When the window is filled with data points from the same time series, a lightweight time series pattern detector is automatically triggered. This detector calculates several key statistical features of the data within the window, including the first-order difference standard deviation reflecting the degree of fluctuation, the maximum autocorrelation coefficient revealing the strength of periodicity, the linear regression slope and goodness of fit reflecting the degree of trend, and the impulse ratio identifying the proportion of outliers. Subsequently, the system can sequentially compare these feature values with the corresponding thresholds according to a preset priority rule chain (impulse type > periodic type > trend type > stationary type) to determine the current data segment as one of the four patterns and output a pattern label.
[0024] The size of the analysis window and the characteristic thresholds for various patterns (such as the thresholds used to determine pulse, periodic, and trend patterns) can be adjusted by the administrator based on the typical characteristics of specific business data (such as collection frequency and fluctuation patterns) to optimize the accuracy of pattern classification.
[0025] S102, based on the pattern label, select the corresponding compression encoding strategy from the preset encoding algorithm library, compress the current data segment, and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored synchronously.
[0026] In the embodiments described in this specification, this step can directly receive the pattern label output by S101. The system internally maintains an encoding algorithm library, in which a specific compression encoding strategy is pre-set for each pattern. Based on the label, the system automatically selects the appropriate strategy to compress the current data segment: differential encoding based on a periodic template is used for periodic data; encoding based on linear regression residuals is used for trending data; standard encoding is used for stationary data; and hybrid encoding separating the baseline and impulses is used for impulsive data. After compression, the data is encapsulated into a pattern-aware data block with a header. Crucially, during the encapsulation process, the system synchronously traverses the original data within this data block, quickly calculates a set of block-level aggregated summaries, and writes them into the block header.
[0027] The pre-defined encoding algorithm library and its specific parameters (such as template extraction methods for periodic encoding and baseline separation criteria for pulse encoding) allow experienced database administrators or tuning experts to customize, optimize, or replace them according to data characteristics in order to achieve the best compression ratio on a specific dataset.
[0028] S103, using the block-level aggregated summary of each of the pattern-aware data blocks as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level.
[0029] In the embodiments described in this specification, this step is the core index construction stage for query acceleration. The system uses the block-level aggregated summaries of all pattern-aware data blocks generated in S02 as the basic material to automatically construct a multi-level temporal aggregation pyramid. The bottom nodes of the pyramid correspond to these block-level summaries. Higher levels of the pyramid represent coarser temporal granularities, and their nodes store aggregated summaries within the corresponding time range. The generation of higher-level nodes adopts an "on-demand materialization" strategy: the system does not pre-calculate all higher-level nodes when writing data; calculation is triggered only when a query request requires an aggregation result at a specific time granularity—by immediately merging the aggregated summaries of multiple child nodes in the next lower level, the summary of that higher-level node is calculated and materialized for direct use by subsequent queries.
[0030] The hierarchical structure of the pyramid (such as the number of layers and the time granularity span of each layer) can be configured. More importantly, the system can introduce "heat-driven" materialized scheduling, where the query frequency statistics period used to determine node heat, the heat threshold for triggering background pre-materialization, and the strategy for eviction of infrequently used nodes to release cache can all be adjusted by the administrator to balance query acceleration and storage resource consumption.
[0031] S104, when receiving a query request, select one of the multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0032] In the embodiments described in this specification, this step is the entry point and scheduling center for the query. When the system receives a query request that clearly specifies the time range, aggregation function, output granularity, and accuracy requirements, the query routing decision-maker begins to work. The decision-maker first analyzes the request to determine the target level in the aggregation pyramid corresponding to the target output granularity. Next, it checks the materialization status (i.e., whether it has been calculated and stored) of the nodes of that level and adjacent levels constructed in S103. Based on the materialization status and the accuracy requirements of the query, the decision-maker automatically selects the optimal path from four predetermined paths for execution: 1) If the target level node has been fully materialized and the data is consistent, it is read directly; 2) If the target level is not fully materialized but its next-level node has been fully materialized, it is calculated by merging on the spot; 3) If the query allows approximate results and the time span is large, it can use coarser-grained materialized nodes for approximate calculation; 4) Otherwise, it falls back to the original data in the decompressed scan mode sensing data block for accurate calculation.
[0033] The path selection strategy of the query routing decision-maker can be configured or weighted, for example, adjusting the leniency of the conditions that trigger approximate inference paths. Furthermore, when executing paths that require scanning the original data, the aggressiveness of its internal data block pruning based on block-level aggregate summaries can also be used as an adjustable parameter to fine-tune the balance between query latency and computational resource consumption.
[0034] It's important to note that this method fundamentally alters the resource base and decision space for query execution by introducing "pattern-aware compression" and "on-demand progressive materialization of a multi-granularity aggregation pyramid" as its core storage and indexing structure. During data writing, the method not only adaptively compresses data based on time-series patterns to optimize storage but also simultaneously generates the block-level summaries necessary for building the aggregation index, a process that adds almost no write overhead. The multi-level aggregation pyramid built upon this foundation does not pre-compute all high-level aggregation data during writing. Instead, it strictly adheres to the "on-demand materialization" principle, meaning that aggregation results at a specific time granularity are only calculated and cached in real-time by merging lower-level summaries when touched by an actual query request. This design breaks down the binary opposition between "full pre-computation" and "no pre-computation," preventing the blind consumption of storage and computing resources from the outset.
[0035] Based on this dynamic and economical index structure, the query engine gains unprecedented flexibility in responding to requests. The engine can intelligently select the optimal solution from multiple predetermined execution paths based on the specific time range, output granularity, and precision requirements specified in the query request, combined with the real-time materialization status of nodes at each level of the pyramid. Optional paths include directly reading the precise materialized results, temporarily merging and calculating the precise results of unmaterialized nodes, using high-level summaries for approximate estimation, or rolling back to scanning the original data. This multi-path adaptive routing mechanism allows the system to proactively and dynamically balance and optimize query precision, latency, and system computational overhead, thereby overcoming the rigidity of the "hit or rollback" strategy in the background technology. Ultimately, it achieves intelligent services that balance low latency and high resource efficiency for diverse aggregation queries without compromising data write performance.
[0036] Furthermore, the pattern labels include: periodic pattern, trend pattern, stable pattern, and pulse pattern. The method flow steps in this embodiment of the specification for classifying the current data segment into patterns and outputting pattern labels based on a preset priority rule chain are as follows: S201, judged in order of priority from high to low.
[0037] In the embodiments described in this specification, this step defines the execution framework for the entire classification decision. After completing feature calculation, the system will strictly follow a fixed order of "pulse type -> periodic type -> trend type -> stationary type" for evaluation. Once the current condition is met, the corresponding pattern label is immediately output, and the judgment of all subsequent conditions is terminated. This design ensures the uniqueness and efficiency of the classification results and implicitly prioritizes decisions when dealing with complex data features (for example, even if a piece of data has periodicity, if its pulse anomaly ratio is high, it will be preferentially identified as pulse type).
[0038] S202, if the pulse ratio exceeds the first threshold, it is determined to be a pulse mode.
[0039] In the embodiments described in this specification, the system first checks the feature value of "pulse ratio". The pulse ratio quantifies the proportion of data points within the current analysis window whose values deviate from the normal fluctuation range (usually defined as exceeding three standard deviations above and below the mean). This step compares this ratio with a preset "first threshold". If it exceeds the threshold, it indicates that the data segment contains a significant proportion of sudden outliers or spikes, and the system immediately classifies it as a "pulse pattern" and ends the classification process.
[0040] S203, otherwise, if the peak value of the autocorrelation coefficient exceeds the second threshold, it is determined to be a periodic pattern.
[0041] In the embodiments described in this specification, if the pulse ratio does not exceed a threshold, the system evaluates the periodicity of the data. It checks whether the "peak value of the autocorrelation coefficient" exceeds a "second threshold." The peak value of the autocorrelation coefficient reflects the maximum similarity between the data and its historical values at different time lags, and is a key indicator for identifying hidden periodic patterns. Exceeding this threshold means that the data exhibits a significant, repeatable fluctuation pattern. If the condition is met, it is classified as a "periodic pattern," and the process terminates.
[0042] S204. Otherwise, if the coefficient of determination of the linear fit exceeds the third threshold and the absolute value of the slope of the linear trend exceeds the fourth threshold, it is determined to be a trend-type pattern.
[0043] In the embodiments of this specification, if neither of the first two types of patterns is identified, the system then assesses whether there is a significant trend in the data. This step involves a combination of conditions and requires two conditions to be met simultaneously: First, the "linear fitting determination coefficient" must exceed the "third threshold." This coefficient indicates how well a straight line can explain the degree of data variation when fitting the window data; a higher value indicates a stronger linear relationship. Second, the "absolute value of the linear trend slope" must exceed the "fourth threshold." This ensures that the identified trend has sufficient strength or rate of change, rather than being a negligible fluctuation. If both conditions are met, the data is determined to be a "trend-type pattern."
[0044] S205, otherwise, it is determined to be a stable mode.
[0045] In the embodiments described in this specification, this step is the default exit point of the rule chain. If the current data segment fails to trigger the judgment conditions of any of the above special modes (pulse, period, trend), the system classifies it as a "stationary mode". This means that no significant abnormal pulses, periodic patterns or clear trends were detected in the data within this window, and its fluctuations mainly manifested as random fluctuations or slow changes around a certain level.
[0046] It should be noted that this rule chain is the core decision logic within the temporal pattern detector (corresponding to main process S101). Its input consists of multiple statistical feature values from the current data segment window after feature extraction. The rule chain executes in a deterministic, either-or priority order, aiming to assign an appropriate pattern label to each data segment. This label serves as the key input to the next stage (main process S102, pattern adaptive compression coding), directly determining which targeted compression strategy the system selects.
[0047] All thresholds in this rule chain (the first, second, third, and fourth thresholds) are key adjustment parameters. Database administrators or domain experts can adjust these thresholds based on the typical behavior of time-series data in specific business scenarios (e.g., requirements for anomaly sensitivity, typical levels of periodicity, and criteria for judging trend significance), thereby optimizing the accuracy and applicability of pattern classification and enabling subsequent compression strategies to more accurately match data characteristics.
[0048] It's important to note that this priority rule chain design provides a deterministic, efficient, and data compression-compliant classification decision logic for complex time-series data segments with multiple features and patterns. Through a progressive judgment of "pulse-type -> periodic-type -> trend-type -> stationary-type," it ensures the logical uniqueness and operability of the classification results, effectively resolving decision conflicts when multiple pattern features are simultaneously present. Its beneficial effect lies in transforming the abstract and complex pattern recognition problem into an automated judgment process based on statistical feature thresholds and with clear priorities. This enables the system to stably and consistently extract the most valuable pattern labels for subsequent compression steps from the raw data, providing reliable and efficient pre-decision support for the core idea of "pattern adaptive compression," thereby ensuring the rationality of the compression strategy selection and the potential for optimizing the final compression efficiency.
[0049] Furthermore, in the process of selecting a corresponding compression encoding strategy from a preset encoding algorithm library based on the pattern label, the method flow steps in this embodiment are as follows: S301, if the pattern label is periodic, then a periodic template differential coding strategy is adopted. The periodic template differential coding strategy includes: extracting a periodic template waveform from the window data according to the detected estimated period length, calculating the difference between each data point in the window and the corresponding phase position value in the template waveform to obtain a residual sequence, and compressing the residual sequence.
[0050] In the embodiments of this specification, this strategy is enabled when the pattern label is "periodic". First, using the period length estimated during the pattern detection phase, a representative periodic waveform is reconstructed from the data in the current analysis window as a "template". Specifically, this is usually the average of the phase positions corresponding to data points of several consecutive complete periods. Then, each original data point in the window is traversed, and the difference between it and the corresponding phase position value in the template is calculated to obtain the "residual sequence". Since the main information of the periodic data (repeating waveforms) has been captured by the template, the numerical range and variation amplitude of this residual sequence are usually much smaller than the original data. Finally, the system applies efficient differential coding and variable-length integer coding to compress this residual sequence. The core idea of this strategy is to separate and eliminate the principal components with strong periodicity in the data, and only encode small fluctuations.
[0051] S302, if the pattern label is trend-type, then a trend regression residual coding strategy is adopted. The trend regression residual coding strategy includes: calculating the regression residual of each data point using the parameters obtained by linear regression of the window data, and compressing the regression residual sequence.
[0052] In the embodiments described in this specification, this strategy is enabled when the pattern label is "trend-type". This strategy utilizes the slope and intercept parameters calculated by linear regression during the pattern detection phase. For each data point within the window, the system uses these parameters to calculate its predicted value based on the linear trend, and then subtracts the predicted value from the original value to obtain the "regression residual". This operation is equivalent to removing the linear trend (long-term drift) from the data, causing the residual sequence to fluctuate around zero. Subsequently, this residual sequence is compressed using XOR encoding suitable for floating-point numbers. Because the numerical distribution of the residuals is more concentrated after detrending, and the variation between adjacent residuals is smaller, this encoding method achieves higher compression efficiency than directly encoding the original value.
[0053] S303, if the mode label is a stable type, then a preset standard encoding strategy is adopted.
[0054] In the embodiments of this specification, the system enables this standard strategy when the pattern label is "stationary". Stationary data itself does not possess strong periodicity, trends, or sudden spikes; the values between adjacent data points are usually quite close. Therefore, directly using a general compression algorithm optimized for stationary random fluctuations can achieve near-optimal results. This strategy typically uses difference encoding for timestamp sequences and XOR-based encoding for metric sequences, thereby effectively eliminating temporal and numerical redundancy.
[0055] S304, if the pattern label is pulse type, then a baseline-pulse separation coding strategy is adopted. The baseline-pulse separation coding strategy includes: separating the window data into a baseline data subsequence and a pulse data subsequence, performing run-length encoding and differential encoding compression on the baseline data subsequence, and storing the pulse position and pulse value in a sparse representation form for the pulse data subsequence.
[0056] In the embodiments described in this specification, this strategy is activated when the pattern label is "pulse type". This strategy first separates the window data: based on preset statistical boundaries (such as three standard deviations above and below the mean), data points are identified and segmented into "baseline data subsequences" (normal fluctuation points) and "pulse data subsequences" (abnormal spikes). For these two subsequences with vastly different characteristics, the most suitable encoding method is adopted for each: for the slowly changing baseline subsequence, which may contain consecutive identical values, a combination of run-length encoding and differential encoding is used for efficient compression; for the sparse, discretely distributed pulse subsequence, its continuous values are not directly stored, but rather sparse representation is used, recording only the positional offset of each pulse point within the window and its specific amplitude, and this information is compactly encoded. This strategy avoids the problem of a few pulse points compressing the entire data segment.
[0057] It is important to note that this method establishes a deterministic mapping mechanism from "pattern recognition" to "policy execution." By matching each identified data pattern (periodic, trending, stationary, impulsive) with a pre-designed, highly targeted dedicated coding strategy, the compression method achieves adaptability to the inherent statistical characteristics of the data. The beneficial effect of this design is that it transforms the compression process from a general, fixed process into a highly customized optimization process based on data feature analysis. For periodic data, the strategy eliminates major fluctuations by extracting and subtracting periodic templates, concentrating information in the residuals; for trending data, it eliminates long-term variation components by subtracting linear trends; and for impulsive data, it separates sparse impulses from the smooth baseline. This targeted approach allows each coding algorithm to operate on data characteristics that best match its design assumptions, thereby maximizing the elimination of redundant information in the data. Therefore, by directly and accurately driving the selection of dedicated coding strategies based on pattern classification results, this scheme optimizes the adaptability and efficiency potential of the compression process as a whole, laying a key technical foundation for achieving higher compression ratios at the storage level.
[0058] Furthermore, the block-level aggregated summary includes at least the minimum, maximum, sum, and quantity of data within the data block.
[0059] It should be noted that this method lays a crucial data foundation for efficient data management, query optimization, and resource scheduling at higher levels by synchronously calculating and solidifying the core statistical summary of each data block during the data compression and encapsulation stage. The minimum and maximum values precisely characterize the value range of the data block. This allows the system to quickly determine whether the entire data block is relevant to the query without reading the specific data within the block when responding to queries or filtering conditions involving numerical ranges. This enables efficient block-level data pruning and avoids unnecessary I / O and decompression calculations. The sum and quantity statistics directly constitute the raw material for any subsequent aggregation calculations (such as calculating the average or variance). When query requests involve summation or averaging operations, the system can directly utilize these pre-calculated intermediate aggregation results to quickly derive aggregate values over a larger time range by merging the summary information of multiple data blocks, without accessing and calculating massive amounts of original data points. Therefore, this design shifts the costly basic statistical calculations that would otherwise be repeated during a query to a one-time data write process. At the cost of minimal storage overhead, the calculation results are persisted in the form of a summary, thus providing indispensable metadata support for performance acceleration and resource saving along the query path.
[0060] Furthermore, in the process of the on-demand materialization strategy, the method flow steps of the embodiments in this specification are as follows: S401, Calculate the query frequency of each time granularity within the past preset time period.
[0061] In the embodiments described in this specification, the system continuously runs a monitoring process in the background. This process maintains a "Query Granularity Access Frequency Statistics Table," the core of which records the number of query requests successfully executed within a recent continuous time period (e.g., the past 24 hours) for each defined time granularity (e.g., 1 minute, 1 hour, 1 day, corresponding to different levels of the aggregation pyramid). Whenever a query is completed, the system parses the "output granularity" required by the query request and increments the count for the corresponding granularity in the statistics table. Simultaneously, the system uses a sliding window approach to manage time, automatically discarding old query records that exceed the preset statistical time period, thereby ensuring that the statistical results reflect recent query load hotspots.
[0062] S402, when the query frequency at a certain time granularity exceeds the popularity threshold, the background asynchronous task actively pre-materializes the unmaterialized nodes at the corresponding granularity level in the aggregation pyramid.
[0063] In the embodiments described in this specification, the heat index determination and pre-materialization scheduling process periodically (or based on events) checks the aforementioned statistical table. It compares the current query frequency for each time granularity with a pre-configured "heat index threshold." When the query frequency for a certain time granularity (e.g., a "1-hour" granularity) exceeds this threshold, the system determines that this granularity is a "hotspot." Subsequently, the system does not immediately process this in the foreground but creates a "background asynchronous task." This task has a clear objective: to traverse the entire hierarchy in the aggregation pyramid corresponding to the "hotspot" time granularity and check the materialization status of all nodes. For all nodes that have not yet been materialized, this background task actively triggers the same computational logic as "on-demand materialization," that is, reading the materialized aggregation summaries from the next-level child nodes of these nodes, generating the aggregation summary of the current node through merging calculations, and persistently storing (materializing) it. This process is completed silently in the system background and does not affect the user's ongoing write and query operations.
[0064] It's important to note that this strategy, extended to a basic on-demand materialization mechanism, introduces a predictive and optimization capability based on historical access patterns. By continuously analyzing query frequencies at various time granularities, it transforms the system from a passive, query-triggered materialization response to a proactive, data-heat-based resource pre-allocation. When the system identifies a query frequency at a particular time granularity that consistently exceeds a set heat threshold, that granularity is designated as a "hotspot," and subsequently, an asynchronous background task proactively pre-materializes the corresponding unmaterialized nodes in the aggregation pyramid. The key to this mechanism lies in its clever creation of a dynamically adaptive middle path between the two extreme strategies of "full pre-computation during writes" (high resource consumption) and "complete on-demand computation during queries" (high latency for initial queries). Its beneficial effect is that the system can utilize idle background computing resources to proactively prepare for high-probability query loads, thereby optimizing the typical response path for high-frequency queries from "triggered computation - waiting for results" to "direct reading - instant return," significantly reducing the latency of hotspot queries. Meanwhile, since the pre-materialization operation is strictly limited to the identified hot spot granularity and is executed asynchronously in the background, it avoids interference with data write throughput and strictly prevents unnecessary materialization overhead from being paid in advance for unpopular data. Ultimately, it achieves a better and more adaptive global balance between system computing resources, storage resources and query latency.
[0065] Furthermore, the method also includes an incremental maintenance step for handling the impact of late data on the constructed pattern-aware data block and the aggregation pyramid. The method flow steps of this embodiment are as follows: S501, when late data with a timestamp earlier than the current write window is received, update the affected pattern-aware data block and its block-level aggregate summary.
[0066] In the embodiments described in this specification, the system continuously monitors the write data stream. When a data point's timestamp indicates that it belongs to a past time period that has already been processed (i.e., the analysis window to which it should belong has been closed, and the corresponding data block may have been flushed to disk), it is identified as "late data." The system first locates the specific pattern-aware data block to which it should belong based on the data point's timestamp and metric identifier. Subsequently, an update operation is performed: either merging the late data point into the data block (if the data block is still in the memory buffer) or creating a dedicated supplementary data block for it (if the original block has been persisted). Next, the system must recalculate the block-level aggregate summary (i.e., minimum, maximum, sum, and count) of the data block to reflect the latest statistical state after incorporating the new data point. This step ensures the correctness of the data source.
[0067] S502, in the aggregate pyramid, the affected nodes are marked as dirty nodes from bottom to top.
[0068] In the embodiments described in this specification, since the aggregate digest of a certain pattern-aware data block at the bottom layer has changed, the states of all upper-level aggregate nodes (in the aggregate pyramid) that directly or indirectly depend on this digest also become invalid. The system initiates a marking process: starting from the bottom layer (Level-0) of the aggregate pyramid, it finds the node corresponding to the recently updated data block and marks it as "dirty," indicating that its data is outdated. Subsequently, it traverses the hierarchical structure of the aggregate pyramid from bottom to top, marking all direct parent nodes (upper layer), grandparent nodes (two layers above), and even the potentially affected root node of the current dirty node as "dirty" nodes layer by layer. This process is efficient and accurate, as it only propagates upwards along the affected paths, avoiding a global scan.
[0069] S503, for materialized dirty nodes, incrementally recalculates their aggregate summary through a background asynchronous task.
[0070] In the embodiments described in this specification, after marking is completed, the system needs to correct dirty data. However, not all marked nodes need to be recalculated immediately. The system adopts an economical strategy: only those dirty nodes that have been "materialized" (i.e., nodes that have been previously calculated and stored, possibly due to being queried or the result of pre-materialization based on popularity) are scheduled for recalculation. The system adds these materialized dirty nodes to a dedicated "incremental recalculation queue." A separate background asynchronous task processes this queue, retrieves the dirty nodes from the queue, reads the latest aggregated summary from the updated next-level child nodes according to their type, re-executes the merge calculation, and overwrites the old materialized value with the new result, thereby clearing the "dirty" mark of the node. This process is performed asynchronously in the background, decoupling from the system's foreground read and write operations in terms of resources and time, minimizing the impact on user experience.
[0071] It's important to note that this incremental maintenance step addresses the common "late data" problem in time-series data applications by designing a precise, efficient, and minimally impactful data consistency guarantee mechanism. Its core benefit lies in its reduction of the traditionally high costs associated with maintaining data consistency. When late data with an earlier timestamp arrives, this step doesn't simply trigger a complete recalculation of the affected pre-aggregated results. Instead, it employs a "targeted update, on-demand recalculation" strategy. First, it accurately updates the affected underlying data blocks and their basic summaries, ensuring the accuracy of the data source. Then, by "marking dirty nodes from the bottom up," it precisely locates all aggregate nodes that have become invalid due to changes in the underlying data within the constructed aggregate pyramid index, strictly limiting the recalculation to these marked nodes. Finally, it executes these "incremental recalculations" through "background asynchronous tasks," effectively decoupling the necessary computational overhead from the system's front-end write and query paths. The synergistic effect of this series of designs ensures that after late data is integrated into the system, all relevant aggregated views are correctly and promptly updated, thus guaranteeing the eventual consistency of query results. Meanwhile, by avoiding global, synchronous recomputation, this mechanism minimizes interference with the system's normal write throughput and real-time query performance, enabling the system to maintain stable high-performance service while processing out-of-order data, thus achieving an effective balance between data accuracy, system availability, and resource efficiency.
[0072] Furthermore, the multiple predetermined execution paths specifically include: The first path involves directly reading the aggregated summary of the target level node when the output granularity of the query request corresponds to a fully materialized aggregate pyramid node with consistent data.
[0073] In the embodiments described in this specification, when a query request arrives, the system first parses its "output granularity" and determines the "target level" that matches that granularity in the aggregation pyramid. Subsequently, the system checks whether all nodes in that target level covering the query time range meet two conditions: 1) they are fully materialized (i.e., the node's aggregate summary has been calculated and persistently stored); 2) the data is consistent (i.e., the node is not marked as "dirty," its data reflects the latest state of all underlying data, and it is not invalidated by late data). If both conditions are met, this path is activated. The system directly reads the aggregate summaries of these target nodes and quickly processes the summaries according to the aggregation function requested by the query (such as calculating the average or maximum value), generating the final result and returning it. This path has the lowest latency because it completely avoids real-time computation and raw data scanning.
[0074] The second approach involves calculating and materializing the aggregate summary of the target-level node in real time when the target-level node is not fully materialized but its next-level node is fully materialized, by merging the aggregate summaries of the corresponding multiple child nodes in the next level.
[0075] In the embodiments of this specification, if the conditions of the first path are not met, mainly because the target-level node is "not fully materialized" (i.e., some nodes have not yet been calculated and stored), but the system checks and finds that the next-level nodes of these unmaterialized nodes have been fully materialized, then this path is enabled. The system will locate the unmaterialized target node and immediately read the aggregated summary of the corresponding multiple child nodes in its next level from storage. Subsequently, through efficient merging calculation (e.g., adding the sums of the child nodes to obtain the sum of the parent node, and taking the minimum value from the mins of the child nodes to obtain the min of the parent node), the aggregated summary of the target node is calculated. The calculation result is used directly to respond to the current query, and is immediately "materialized" and stored in the corresponding node of the aggregation pyramid. This allows subsequent queries of the same granularity to be upgraded to respond quickly via the first path.
[0076] The third approach involves approximating the accuracy requirement of the query request when the query time range exceeds a preset threshold, based on the aggregated summary of materialized nodes at a higher level than the target level in the aggregated pyramid.
[0077] In the embodiments described in this specification, the activation of this path is subject to strict preconditions: 1) the "precision requirement" explicitly specified in the query request is "approximate"; 2) the "time range span" of the query is extremely large, exceeding a preset threshold (meaning that scanning the original data is extremely costly). When the conditions are met, the system will look for a higher level (i.e., a coarser time granularity) in the aggregation pyramid than the target level, and requires that the nodes covering the query range in this higher level are materialized. The system will read these coarser-grained aggregation summaries and then use data extrapolation techniques (e.g., interpolation between coarse-grained aggregation values, or allocation according to time proportions) to extrapolate an approximate result that matches the requested output granularity. This path sacrifices some precision in exchange for an order-of-magnitude reduction in query latency, making it suitable for analysis scenarios with high real-time requirements and acceptable error.
[0078] The fourth path involves decompressing and scanning the original data in the pattern-aware data block for precise calculation.
[0079] In the embodiments described in this specification, when all the aforementioned acceleration paths are unavailable (e.g., the requested aggregation function cannot be directly calculated from the existing summary, the accuracy requirement must be "precise" but the pyramid materialization state does not satisfy the first two paths, or the approximate calculation conditions are not met), the system will fall back to this path. This is the most fundamental but also the most expensive execution method. The system first locates all relevant "pattern-aware data blocks" based on the query's time range. Then, it uses the "block-level aggregation summary" in the data block header for fast filtering, skipping those data blocks that are determined not to contribute to the query results (i.e., block-level pruning). For data blocks that cannot be skipped, the system selects the corresponding decoding algorithm based on the pattern label recorded in its header to decompress the data, recover the original data points, and performs precise scanning and aggregation calculations on these data points to obtain the final result.
[0080] It should be noted that this method predefines four query paths with clear triggering conditions and execution logic, constructing a hierarchical and degenerate intelligent decision-making framework for the system. Its core benefit lies in enabling the query engine to dynamically select the optimal solution from multiple execution paths based on the specific parameters of each query request (such as output granularity and accuracy requirements) and the real-time status of system resources (such as the materialization of aggregation pyramid nodes), thereby achieving an adaptive optimal balance between query latency, computational overhead, and result accuracy. The first path provides an instantaneous response when conditions are perfectly matched; the second path minimizes latency for unprepared queries through immediate computation and materialization, while avoiding permanent redundant storage; the third path, when approximate results are allowed, significantly reduces computational load by utilizing existing aggregated data with coarser granularity to achieve extremely fast response; and the fourth path serves as a final guarantee, ensuring absolute accuracy of the results. These four paths together form a continuous decision space from optimal to minimum, enabling the system to flexibly respond to diverse query scenarios. This avoids the static resource waste of the "full pre-computation" strategy and overcomes the rigid high latency of the "full scan" strategy, achieving intelligent management of globally optimal query performance and system resource utilization.
[0081] Furthermore, when the fourth path is selected to perform the query, the method flow steps of this embodiment are as follows: S601, block-level pruning is performed using the block-level aggregated summary of the pattern-aware data block, skipping the decompression and scanning of pattern-aware data blocks that have no impact on the query results.
[0082] In the embodiments described in this specification, after determining that a fourth path is required, the system does not immediately begin decompressing all relevant pattern-aware data blocks. Instead, it first processes each candidate data block sequentially. For each data block, the system only reads the "block-level aggregation summary" metadata stored in its header (containing the minimum, maximum, sum, and number of data points of the block). Then, the system quickly compares and logically judges this summary information with the query context according to the specific "aggregation function" specified in the current query request to determine whether scanning this data block will affect the final query result. For example: If the query is for the maximum value, and the maximum value recorded in the current data block summary is less than the global maximum value candidate that the system has found when processing previous data blocks, then it can be concluded that scanning this block is unlikely to produce a larger value, and therefore can be skipped.
[0083] If the query is to find the minimum value, and the minimum value recorded in the current data block summary is greater than the currently known global minimum candidate, then the block can be skipped.
[0084] If the query is for summation or averaging, in principle, every data block contributes and cannot be skipped directly. However, under certain special filtering conditions (such as querying "the sum of data points with values greater than 100"), if the block summary shows that its maximum value is still less than 100, then that block can be safely skipped.
[0085] By using this summary-based prediction, the system can exclude a batch of data blocks that do not contribute to the query results from the subsequent processing queue without decompressing the data block content. Only those data blocks that cannot be proven irrelevant by the summary information will enter the actual decompression and full data point scanning process.
[0086] It's important to note that this method introduces a crucial optimization mechanism for the most costly query fallback path (the fourth path), its core value lying in significantly reducing unnecessary resource consumption. When a query must scan the original data because it cannot obtain results directly or indirectly from the aggregation pyramid, traditional methods require full decompression and scanning of all relevant data blocks. This method, however, reads and analyzes the pre-stored block-level aggregation summary (containing statistical information such as minimum and maximum values) in the header of each specific pattern-aware data block before decompressing it. This allows for a quick and pre-emptive determination of whether the data block contains data that contributes to the current query result. For example, when querying the maximum value within a certain time range, if the maximum value recorded in the summary of a data block is lower than the currently found candidate value, it can be concluded that scanning that block will not change the final result. By performing "block-level pruning" based on this logic, the system can accurately skip data blocks that have no impact on the query result, thus avoiding costly decoding operations and full-point scanning of these data blocks. Therefore, this mechanism optimizes the fourth path from a simple, mandatory full rollback operation into an intelligent, selective data access process. While ensuring the absolute accuracy of the query results, it effectively reduces disk I / O load, CPU decompression computation overhead, and memory usage, and systematically improves execution efficiency and resource utilization in the worst-case query scenario.
[0087] The purpose of this invention is to provide an adaptive hierarchical compression and query acceleration method and system based on time-series pattern awareness. By introducing a real-time detection and classification mechanism for time-series patterns into the storage engine layer of the time-series database, adaptively selecting the optimal compression encoding algorithm for each data segment based on the detected time-series patterns, constructing an on-demand progressive materialized multi-granularity aggregation pyramid index, and designing a precision-latency adaptive query routing decision-maker, this invention overcomes the problems of low compression ratio of fixed encoding schemes, reduced write throughput and serious redundant storage of full pre-aggregation schemes, and poor performance of long-span aggregation queries in existing technologies. This achieves synergistic optimization of time-series data in terms of compression ratio, write throughput, and multi-granularity aggregation query performance.
[0088] This invention proposes an adaptive hierarchical compression and query acceleration method and system based on time-series pattern awareness. The core idea is as follows: During the writing of time-series data to the storage engine, a lightweight time-series pattern detector performs real-time pattern classification on the data within the sliding window (identifying it as one of four basic time-series patterns: periodic, trend, stationary, or impulsive). Then, based on the detected pattern type, it automatically selects the optimal combination of encoding algorithms from a pre-set encoding algorithm library for the current data segment. Simultaneously with compression and storage, an "on-demand progressive materialization" multi-granularity aggregation pyramid index is constructed—aggregation results are calculated and cached only at the granularity where the data is first queried; subsequent queries at the same granularity directly hit the cache, and unqueried granularities do not incur computational or storage overhead. Finally, a precision-latency adaptive query routing decision-maker is designed to automatically select the optimal execution strategy from three paths—"precise query of original data," "query of materialized aggregation results," and "approximate estimation based on the aggregation pyramid"—based on the user's query time span, request granularity, and precision requirements.
[0089] The entire system comprises four core modules: a time-series pattern detection and classification module, a pattern-adaptive compression coding module, a progressive multi-granularity aggregation pyramid module, and a precision-latency adaptive query routing module. These four modules work collaboratively within the write and query paths of the time-series database storage engine.
[0090] The methodology and technical steps are detailed below: Step S1: Real-time detection and classification of time-series patterns The S1.1 system receives a continuous stream of time-series data. Each data point contains a timestamp, a metric identifier (metric_id, identifying the time series to which the data point belongs), and one or more metric values. Data points are sequentially entered into the write buffer (implemented based on MemTable) in memory according to their timestamp order.
[0091] S1.2 When the cumulative number of data points with the same metric identifier written to the buffer reaches the size of an analysis window W (the default value of W is set to 256 data points, which can be adjusted according to the acquisition frequency), the time-series pattern detector is triggered to perform pattern classification on the data in the window.
[0092] The S1.3 temporal pattern detector employs the following lightweight statistical feature extraction and rule determination process: Feature extraction: Calculate the following five statistical features for W data points within the window: First-order difference standard deviation (σ_Δ): The standard deviation of the series of differences between adjacent data points, which measures the degree of fluctuation in the data; Peak autocorrelation coefficient (ρ_max): The autocorrelation function (ACF) is calculated for the window data, and the maximum autocorrelation coefficient value in the range of 1 to W / 2 with a lag period is taken to measure the periodicity of the data; Linear trend slope (β): Perform least squares linear regression on the window data and take the absolute value of the slope to measure the degree of trend in the data; Linear fit determination coefficient (R²): The determination coefficient of the linear regression above measures the degree to which the linear trend explains the variation in the data; Pulse ratio (P_ratio): The percentage of data points within a window that exceed the mean ± 3σ (standard deviation), measuring the degree of sudden anomalies.
[0093] Pattern determination rules (determined by priority from high to low, stopping upon a match): Rule R1 – Spike: If P_ratio > θ_spike (default θ_spike = 0.05, meaning more than 5% of the data points are abnormal spikes), it is determined to be a spike. Rule R2 – Periodic: If ρ_max > θ_periodic (default θ_periodic = 0.6), it is considered periodic. Rule R3 – Trend: If R² > θ_trend (default θ_trend = 0.7) and |β| > ε_slope (default ε_slope is 0.1% of the data range), it is considered a trend. Rule R4 – Stationary: If none of the above rules are met, it is considered stationary.
[0094] S1.4 Output the pattern label (pattern_label ∈ {Spike, Periodic, Trend, Stationary}) of the current data segment and the detected feature parameters (such as the estimated period length T_est for periodic data, the slope β and intercept α for trend data, etc.), and pass them to step S2 along with the original data in the window.
[0095] Step S2: Mode Adaptive Compression Coding S2.1 Based on the pattern label output in step S1, select the corresponding optimal compression coding strategy from the coding algorithm library: Periodic data segments: employ a periodic template differential encoding strategy. First, based on the estimated period length T_est detected by S1, extract a template waveform for one period from the window data (take the mean of consecutive T_est data points as the template). Then, for each data point in the window, calculate the difference (residual) between it and the corresponding phase position value in the template; Finally, Delta encoding combined with Varint encoding is applied to the residual sequence for compression. Since the residuals of periodic data are much smaller than the original values, this strategy achieves a significantly higher compression ratio than directly applying Gorilla XOR encoding to the original values.
[0096] Storage format: [Pattern label (1B)] [Period length T_est (2B)] [Template waveform (T_est × value width)] [Delta+Varint encoding of residual sequence] Trend data segment: Employs a trend regression residual encoding strategy. Using the linear regression parameters (slope β and intercept α) obtained from S1, calculate the regression residual for each data point within the window: residual_i = value_i - (α + β × i); The residual sequence is compressed using Gorilla XOR encoding. Because the range of residual values is significantly reduced after detrending and the XOR results of adjacent residuals have fewer significant bits, the compression ratio is better than directly encoding the original values.
[0097] Storage format: [pattern label (1B)] [slope β (8B)] [intercept α (8B)] [XOR encoding of residual sequence] Stationary data segments: employ the Gorilla standard encoding strategy. Timestamps are encoded using Delta-of-Delta encoding, and metrics are encoded using Gorilla XOR encoding. For stationary data, neighboring values change little, and Gorilla encoding itself is close to optimal.
[0098] Storage format: [Mode tag (1B)] [Delta-of-Delta timestamp encoding] [XOR value encoding] Spike data segments: employ a baseline-speculative coding strategy. The window data is separated into two subsequences: baseline data (non-pulse data points) and pulse data (data points exceeding ±3σ). Baseline data is compressed using RLE + Delta encoding (baseline segments typically change slowly, and RLE is highly efficient). Pulse data is stored in a sparse representation: only the pulse position offset (index relative to the start of the segment) and the pulse value are recorded, using Varint encoding.
[0099] Storage format: [Mode label (1B)] [Number of baseline data points (2B)] [Baseline RLE+Delta encoding] [Number of pulses (2B)] [Pulse position Varint encoding] [Raw pulse value encoding] S2.2 The compressed data segment is encapsulated into a Pattern-Aware Block (PA-Block). The header of each PA-Block records the following metadata: Block unique identifier (block_id); Belonging metric identifier (metric_id); Time range (time_min, time_max); Number of data points (point_count); Pattern label; The block-level aggregation summary includes: the minimum value (min), maximum value (max), sum (sum), and count of all data points within the block, which is used to support the underlying construction of the aggregation pyramid.
[0100] S2.3 When the PA-Blocks in memory accumulate to the write threshold, the PA-Block sequence is written to the persistent storage file on the disk (SST file format based on LSM tree) in chronological order, and the sparse index is updated.
[0101] Step S3: Progressive Multi-Granularity Aggregation Pyramid Construction S3.1 Pyramid Structure Definition: The multi-granularity aggregation pyramid is defined as an L-level hierarchical structure, from the bottom layer (Level-0) to the top layer (Level-(L-1)), with each layer corresponding to a time aggregation granularity. The levels and their granularities are defined as follows: Level-0 (bottom layer): corresponds to the aggregation granularity at the PA-Block level (i.e., the time span of an analysis window W; for example, if the sampling interval is 1 second and W=256, then the Level-0 granularity is approximately 4.3 minutes). Level-1: Granularity is M times that of Level-0 (M is the branching factor, with a default value of 8), which is approximately 34 minutes; Level-2: The particle size is M times that of Level-1, which is approximately 4.5 hours; Level-3: The particle size is M times that of Level-2, which is approximately 1.5 days. Level-4 (top layer): The granularity is M times that of Level-3, which is approximately 12 days; Higher levels follow the same pattern, until the entire time range of the data is covered.
[0102] Each node in each layer stores an aggregate summary, containing four basic aggregate values for the data within that time range: min, max, sum, and count. These four basic values can be used to calculate the mean (avg = sum / count), approximate variance, and approximate percentiles online.
[0103] S3.2 Automatic Level-0 Construction (Write Path Synchronization): The aggregate summary of the Level-0 layer is generated synchronously with the creation of the PA-Block in step S2 (i.e., the block_summary field in the PA-Block header), requiring no additional calculation. Therefore, the construction of Level-0 does not increase the overhead of the write path.
[0104] S3.3 High-level on-demand progressive materialization (query path triggered): Aggregate summaries at Level-1 and above are not pre-computed on the write path, but are generated and cached on demand on the query path. The specific strategy is as follows: When the query router (step S4) decides to use aggregated data from a certain level-k to speed up the query, it checks whether the node corresponding to the required time range in that level has been materialized: If materialized: directly read the cached aggregated summary; If not materialized: Read the aggregated summaries of the corresponding M child nodes from the Level-(k-1) layer, and calculate the aggregated value of the Level-k node in O(M) time using the following merging formula: min_k = MIN(min_{k-1,1}, min_{k-1,2}, ..., min_{k-1,M}) max_k = MAX(max_{k-1,1}, max_{k-1,2}, ..., max_{k-1,M}) sum_k = sum_{k-1,1} + sum_{k-1,2} + ... + sum_{k-1,M} count_k = count_{k-1,1} + count_{k-1,2} + ... + count_{k-1,M} After the calculation is completed, the result is cached in the materialized storage of that level so that subsequent queries can directly hit it.
[0105] S3.4 Popularity-Driven Materialized Scheduling: The system maintains a query granularity access frequency statistics table, recording the number of queries for each time granularity in the past N hours (default N=24). When the query frequency for a certain granularity exceeds the popularity threshold θ_hot (default θ_hot = 10 times / hour), a background asynchronous task actively pre-materializes the nodes that have not yet been materialized in that granularity level, upgrading the query for popular granularities from "on-demand computation" to "direct hit". Conversely, when a certain granularity has not been queried for M_cold hours (default M_cold = 72 hours), the materialized cache for that granularity level is released to reclaim storage space.
[0106] S3.5 Late-Arriving Data Handling: When late-arriving data points with timestamps earlier than the current write window are received: Insert the late data point into the corresponding PA-Block (if the PA-Block is still in memory) or create a patch PA-Block (if the PA-Block has been flushed to disk). The affected nodes are marked as "Dirty" from bottom to top along the aggregation pyramid, and only the materialized dirty nodes are added to the incremental recalculation queue; The background asynchronous task processing incremental recalculation queue recalculates the aggregated summary of dirty nodes layer by layer from Level-0 upwards.
[0107] Step S4: Precision-Delay Adaptive Query Routing S4.1 Query Reception and Parsing: The system receives time-series query requests submitted by users. The query request includes the following parameters: The metric identifier (metric_id) or set of metric identifiers to query; The time range to query (time_start, time_end); The requested aggregate function (agg_func ∈ {avg, min, max, sum, count, percentile_p}); The requested output granularity (e.g., "1 hour", "1 day"). Precision requirement (accuracy_level ∈ {exact, approximate}, default is exact).
[0108] S4.2 Query Routing Decision: The query routing decision-maker automatically selects the optimal execution path based on the query parameters. The decision-making process is as follows: Calculate the estimated number of raw data points covered by the query, N_est: Calculate N_est = (time_end - time_start) × sampling frequency based on the sampling frequency of the metric identifier and the query time range.
[0109] Determine the pyramid matching level L_match: Find the highest level in the aggregate pyramid whose granularity is less than or equal to the requested output granularity as the candidate level L_match.
[0110] Path selection rules (based on priority): Path P1 – Direct Pyramid Hit: If all nodes corresponding to the query time range in the L_match level are materialized and have no dirty tags, then the aggregate summary of the L_match level is read directly. The time complexity of this path is O(N_result), where N_result is the number of time buckets in the output results.
[0111] Path P2 – Pyramid Asymptotic Calculation: If there are unmaterialized nodes in the L_match level but the L_match-1 level is fully materialized, then the path is calculated from the lower-level nodes using the merging formula in step S3.3. The additional computational cost for this path is O(M × N_unmaterialized).
[0112] Path P3 – Approximate Estimation (available only when accuracy_level = approximate): If the query time range is extremely large (N_est > 10^9) and the pyramid only contains materialized data at a higher level (coarser granularity) than L_match, then the result at the requested granularity is approximated using linear interpolation with the higher-level aggregated values. This path sacrifices some accuracy in exchange for orders of magnitude lower latency.
[0113] Path P4 – Raw Data Scan: If none of the above paths are available (e.g., a request for percentile aggregation but the pyramid only stores min / max / sum / count, or a precision requirement of exact and the pyramid is incomplete), the process will fall back to reading and decompressing the raw data from PA-Block for precise calculation. During decompression, the corresponding decompression algorithm will be selected based on the mode label in the PA-Block header.
[0114] S4.3 Adaptive Decompression Optimization: When execution path P4 needs to decompress PA-Block, block-level pruning is performed using the block-level aggregation summary in the PA-Block header. If the query only requires min / max / avg aggregation and the answer is already contained in the block_summary of PA-Block (for example, when querying the maximum value, if the max of a certain PA-Block is less than the currently known global maximum value, the decompression of that block can be skipped), then the block_summary can be used directly without decompressing the block, thereby reducing unnecessary disk I / O (input / output) and decompression calculations.
[0115] S4.4 outputs query results and execution path metadata (path number used, pyramid level hit, number of PA-Blocks scanned, etc.) for system monitoring and query granular access frequency statistics.
[0116] For progressive on-demand materialization of multi-granularity aggregation pyramid indexes, this invention differs from existing full pre-aggregation schemes (such as TimescaleDB continuous aggregation) which synchronously calculate all granularity aggregation results on the write path, thus significantly reducing write throughput, and the binary opposition of no pre-aggregation schemes requiring full scanning of the original data. In this invention, an L-layer aggregation pyramid structure is proposed, in which the aggregation summary (min / max / sum / count) of the Level-0 layer is synchronously generated with zero additional overhead during write using the block-level aggregation summary of PA-Block. The aggregation nodes of Level-1 and above are not pre-calculated on the write path, but are generated and cached from the lower-level nodes through O(M) merging calculation when the query is first triggered. Subsequent queries of the same granularity directly hit the cache, thereby reducing the aggregation calculation overhead on the write path from O(L×N) to O(1). Granularity not queried does not generate any calculation and storage overhead.
[0117] For the popularity-driven materialization scheduling and unpopularity elimination mechanism, the aggregate pyramid of this invention maintains a query granularity access frequency statistics table. For granularities whose query frequency exceeds the popularity threshold, the background asynchronous task actively pre-materializes them to reduce the latency of the first query to the same level as that of materialized nodes. For granularity levels that have not been accessed for a long time, the materialized cache is released to reclaim storage space, thereby achieving a dynamic balance between the storage overhead of the aggregated index and the query acceleration effect.
[0118] This invention provides a real-time detection and classification method for time-series patterns based on lightweight statistical features. Unlike existing adaptive compression schemes that rely on machine learning models for pattern classification or graph segmentation, this invention calculates five lightweight statistical features (first-order difference standard deviation σ_Δ, peak autocorrelation coefficient ρ_max, linear trend slope |β|, linear fit determination coefficient R², and impulse ratio P_ratio) and executes four deterministic rule chains according to priority. This allows for real-time classification of data segments into four time-series patterns: periodic, trend-based, stationary, and impulse-based. This method does not rely on the training and inference of any machine learning model, has a time complexity of O(W) (W is the window size), and can be executed in real-time on the write path without introducing significant latency. The impulse-based pattern is a unique fourth pattern not covered by existing classification schemes.
[0119] For pattern-specific differentiated compression coding strategies, unlike existing schemes that uniformly use fixed coding (such as Gorilla XOR or Delta-of-Delta) or only perform binary division processing (such as MOST dividing data into smooth segments and outliers), this invention designs targeted coding schemes for the four detected time-series patterns: periodic patterns use periodic template differential coding (extracting a one-cycle template waveform from the window data and only performing Delta+Varint coding on the difference between each data point and the corresponding phase position value of the template); trend patterns use trend regression residual coding (using linear regression parameters to detrend and only performing Gorilla XOR coding on small residuals); stationary patterns use Gorilla standard coding; and impulsive patterns use baseline-impulse separation coding (separating the baseline segment and impulsive data and then using RLE+Delta and sparse coding respectively)—ensuring that each pattern segment achieves a compression ratio close to the optimal level in information theory for that pattern. Among these, periodic template differential coding and baseline-impulse separation coding are innovations of this invention.
[0120] For the precision-latency adaptive multi-path query routing decision method, unlike the rigid "hit / backoff" binary strategy of existing schemes that can only backtrack to full original data scanning when pre-aggregation mismatch occurs, the query routing decision-maker of this invention provides four execution paths (pyramid direct hit P1, pyramid asymptotic calculation P2, approximate calculation P3, and original data scanning P4). It automatically selects the optimal path based on the precision requirements (exact / approximate) in the query parameters, the pyramid materialization state, and the estimated data volume, allowing users to make a controllable trade-off between precision and query latency. At the same time, it introduces block-level pruning optimization based on PA-Block block-level aggregation summary (min / max / sum / count) in the original data scanning path to skip data blocks that have no impact on the query results, thereby reducing unnecessary disk I / O and decompression overhead.
[0121] For the incremental aggregation pyramid maintenance mechanism for late data, unlike existing pre-aggregation schemes that require a full recalculation of all aggregation results at the affected granularity when late data arrives, this invention uses a bottom-up dirty label propagation mechanism along the aggregation pyramid. Only materialized dirty nodes are added to the incremental recalculation queue, and the background asynchronous task recalculates the aggregation summary of dirty nodes layer by layer from Level-0 upwards. This limits the aggregation maintenance overhead of late data to the affected local area, while unmaterialized nodes are unaffected, avoiding the computational waste of a full recalculation.
[0122] Figure 2 A schematic diagram of the structure of a time-series database query device provided for one or more embodiments of this specification includes: At least one processor and bus; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0123] This specification provides one or more embodiments of a non-volatile computer storage medium storing computer-executable instructions, which, when executed by a computer, can perform the following: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
[0124] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, devices, and non-volatile computer storage media are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0125] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0126] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0127] In the embodiments provided in this application, it should be understood that the disclosed apparatus / network devices and methods can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0128] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0129] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The aforementioned units can be implemented in hardware or software.
[0130] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0131] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A query method for a time-series database, characterized in that, include: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
2. The method according to claim 1, characterized in that, The pattern labels include: periodic pattern, trend pattern, stable pattern, and pulse pattern. The current data segment is classified into patterns based on a preset priority rule chain, and pattern labels are output, including: Judged in descending order of priority; If the pulse ratio exceeds the first threshold, it is determined to be a pulse mode; Otherwise, if the peak value of the autocorrelation coefficient exceeds the second threshold, it is determined to be a periodic pattern; Otherwise, if the coefficient of determination for linear fitting exceeds the third threshold and the absolute value of the slope of the linear trend exceeds the fourth threshold, it is determined to be a trend-type pattern. Otherwise, it is determined to be a stable mode.
3. The method according to claim 1, characterized in that, The step of selecting a corresponding compression encoding strategy from a preset encoding algorithm library based on the mode label includes: If the pattern label is periodic, a periodic template differential coding strategy is adopted. The periodic template differential coding strategy includes: extracting a periodic template waveform from the window data based on the detected estimated period length, calculating the difference between each data point in the window and the corresponding phase position value in the template waveform to obtain a residual sequence, and compressing the residual sequence. If the pattern label is trend-type, then a trend regression residual coding strategy is adopted. The trend regression residual coding strategy includes: calculating the regression residual of each data point using the parameters obtained by linear regression on the window data, and compressing the regression residual sequence. If the pattern label is stable, then a preset standard encoding strategy is adopted; If the pattern label is pulse type, a baseline-pulse separation coding strategy is adopted. The baseline-pulse separation coding strategy includes: separating the window data into a baseline data subsequence and a pulse data subsequence, performing run-length encoding and differential encoding compression on the baseline data subsequence, and storing the pulse position and pulse value in a sparse representation form for the pulse data subsequence.
4. The method according to claim 1, characterized in that, The block-level aggregated summary includes at least the minimum, maximum, sum, and quantity of data within the data block.
5. The method according to claim 1, characterized in that, The on-demand materialization strategy also includes: Statistical analysis of query frequency for each time granularity within the past preset time period; When the query frequency at a certain time granularity exceeds the popularity threshold, the background asynchronous task will actively pre-materialize the unmaterialized nodes at the corresponding granularity level in the aggregation pyramid.
6. The method according to claim 1, characterized in that, The method further includes an incremental maintenance step to address the impact of late data on the already constructed pattern-aware data blocks and the aggregation pyramid: When late data with a timestamp earlier than the current write window is received, update the affected pattern-aware data block and its block-level aggregated summary; In the aggregate pyramid, affected nodes are marked as dirty nodes from bottom to top; For materialized dirty nodes, their aggregated summaries are incrementally recalculated through an asynchronous background task.
7. The method according to claim 1, characterized in that, The multiple predetermined execution paths include: The first path is to directly read the aggregate summary of the target level node when the output granularity of the query request has been fully materialized and the data is consistent. The second approach involves calculating and materializing the aggregate summary of the target level node in real time when the target level node is not fully materialized but its next-level node is fully materialized, by merging the aggregate summaries of the corresponding multiple child nodes in the next level. The third approach involves approximating the accuracy requirement of the query request when the query time range exceeds a preset threshold, based on the aggregated summary of materialized nodes at a higher level than the target level in the aggregated pyramid. The fourth path involves decompressing and scanning the original data in the pattern-aware data block for precise calculation.
8. The method according to claim 7, characterized in that, When the fourth path is selected to execute the query, the method further includes: Block-level pruning is performed using the block-level aggregated summary of the pattern-aware data blocks, skipping the decompression and scanning of pattern-aware data blocks that have no impact on the query results.
9. A query device for a time-series database, characterized in that, include: At least one processor and bus; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enable the at least one processor to: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.
10. A non-volatile computer storage medium, characterized in that, It stores computer-executable instructions, which, when executed by a computer, can achieve the following: The system receives time-series data streams. When the accumulated data points of the same time series reach a preset analysis window size, it triggers a time-series pattern detector. The time-series pattern detector extracts multiple statistical features of the data points within the window and classifies the current data segment into patterns based on a preset priority rule chain, outputting pattern labels. Based on the pattern label, a corresponding compression encoding strategy is selected from a preset encoding algorithm library to compress the current data segment and encapsulate it into a pattern-aware data block; wherein, during the encapsulation process, the block-level aggregated digest of the pattern-aware data block is calculated and stored simultaneously. Using the block-level aggregated summary of each pattern-aware data block as the bottom-level node, a multi-level time aggregation pyramid structure is constructed. For any target level node in the aggregation pyramid above the bottom level, the generation of its aggregated summary adopts an on-demand materialization strategy. The on-demand materialization strategy is to calculate and materialize the aggregated summary of the target level node in real time only when the query request requires it by merging the aggregated summaries of multiple corresponding child nodes in the next level. When a query request is received, a path is selected from multiple predetermined execution paths to execute the query based on the query request and the materialized state of the aggregation pyramid. The query request includes at least a time range, aggregation function, output granularity, and precision requirements.