A delayed materialized scanning method for analytical databases compatible with multiple storage engines
By reading data in the analytical database and controlling the life cycle of the cache area, encapsulating data blocks and converting filtering conditions, the compatibility and filtering performance issues between multiple storage engines are solved, and efficient delayed materialized scanning and low-memory copying are achieved. volume, improving the overall performance of the database.
Patent Information
- Application Number
- CN202410904108.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-08
AI Technical Summary
When the analytical database is compatible with multiple storage engines, it is difficult to achieve efficient data scanning. The predicate compatibility and filtering performance of the storage engine are difficult to guarantee, and modifying the storage engine to meet the conditions will destroy the integrity of external components, making engineering implementation difficult and Maintenance costs are high.
The data to be filtered is read from the disk and stored in the cache area, and the cache area is controlled not to release the data within a preset time. The encapsulated memory address is passed to the execution engine for the data block, and the filtering conditions are converted into a data format suitable for the storage engine to achieve adaptability. Equipped with filtering and return execution engines to ensure high filtering performance and low memory copy volume.
Regardless of the storage engine's conditional push-down support and filtering performance, it can ensure the high filtering performance of the computing engine, reduce the amount of memory copies, enable different storage engines to support delayed materialized scanning, and uniformly accept the high-performance filtering of the vectorized execution engine.
Smart Images

Figure CN118445347B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data scanning technology, and in particular to a delayed materialized scanning method for an analytical database compatible with multiple storage engines. Background Art
[0002] When an analytical database execution engine needs to be compatible with multiple column storage engines, the various storage engines are usually encapsulated as different types of "input streams" or "data sources". The execution engine is only responsible for reading data from the input stream, without considering the internal logic of the storage engine. However, due to the different functions supported by various storage engines, analytical databases with high performance requirements often face some obstacles in achieving efficient data scanning.
[0003] When faced with multiple storage engines, the predicate compatibility and filtering performance of the storage engines cannot be guaranteed. Only when the compatibility of the storage engine meets the requirements and the filtering performance is higher than or close to the computing engine itself, can delayed materialized scanning improve performance. However, it is almost impossible for every supported storage engine to meet the above conditions. Modifying the storage engine to make it meet the conditions will destroy the integrity of the external components, and the difficulty and maintenance cost of engineering implementation are also high. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the related art. To this end, the present invention provides a delayed materialized scanning method for an analytical database compatible with multiple storage engines.
[0005] The present invention provides a delayed materialized scanning method for an analytical database compatible with multiple storage engines, comprising:
[0006] S1: Reading the data to be filtered from the disk and storing the data to be filtered in the buffer area;
[0007] S2: calling the storage engine interface to control the cache area not to release the data to be filtered within a preset time;
[0008] S3: Encapsulate the memory address of the data to be filtered into a data block, and transfer the data block to the execution engine;
[0009] S4: Convert the filtering condition into the data format of the storage engine to be executed to obtain the adapted filtering condition;
[0010] S5: filtering the storage engine according to the adaptation filtering condition and the data block, copying the remaining rows after filtering and returning them to the execution engine.
[0011] According to a delayed materialized scanning method for analytical databases compatible with multiple storage engines provided by the present invention, the preset time in step S2 is greater than or equal to the execution time of the execution engine for filtering and materializing the data to be filtered.
[0012] According to a delayed materialized scanning method for an analytical database compatible with multiple storage engines provided by the present invention, the storage engine in step S2 is a vectorized storage engine.
[0013] According to a delayed materialized scanning method for analytical databases compatible with multiple storage engines provided by the present invention, in step S4, the process of converting the filtering conditions is implemented in the execution engine.
[0014] According to a delayed materialized scanning method for an analytical database compatible with multiple storage engines provided by the present invention, in step S4, when the filtering condition cannot be converted into the data format of the storage engine, the unfiltered data in the data to be filtered is rolled back to the execution engine, and the unfiltered data is filtered by the execution engine.
[0015] According to a delayed materialized scanning method for an analytical database compatible with multiple storage engines provided by the present invention, step S4 specifically includes: when the data of the storage engine is encoded and stored as a minimum value, the condition value of the adapted filtering condition is the difference between the condition value of the filtering condition and the minimum value; when the data of the storage engine is stored in a comparable binary format, the condition value of the adapted filtering condition is the condition value of the filtering condition calculated by a comparable binary encoding function.
[0016] According to a delayed materialized scanning method for an analytical database compatible with multiple storage engines provided by the present invention, in step S4, the filter condition is converted into the data format of the storage engine to be executed, and is implemented by rewriting the expression of the filter condition.
[0017] The present invention provides a delayed materialized scanning method for analytical databases that is compatible with multiple storage engines. Regardless of the storage engine's support for condition pushdown and filtering performance, it can ensure the high filtering performance of the computing engine and greatly reduce the amount of memory copying, so that different storage engines can support delayed materialized scanning and can uniformly accept the high-performance filtering of the vectorized execution engine.
[0018] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 It is a flow chart of a delayed materialized scanning method for an analytical database compatible with multiple storage engines provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical scheme and advantages of the present invention clearer, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. The following embodiments are used to illustrate the present invention, but cannot be used to limit the scope of the present invention.
[0022] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiment of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0023] In order to better understand the present invention, the research background of physicochemical scanning is first described below.
[0024] Assuming a query needs to filter data according to conditions, the following problems are faced:
[0025] The filtering condition is pushed down to the storage engine for filtering, and only the hit data is passed to the execution engine, that is, delayed materialized scanning; or all unfiltered data is directly passed to the execution engine and then filtered inside the execution engine, that is, early materialized scanning.
[0026] Obviously, delayed materialized scans seem to be more efficient because the amount of data output from the storage engine may be significantly reduced, which greatly reduces memory copies and improves performance. Databases that are deeply bound to the execution engine and storage engine generally adopt this design.
[0027] However, while supporting delayed materialized scanning for different storage engines, it is not possible to uniformly accept high-performance filtering of vectorized execution engines. To this end, the present invention provides a delayed materialized scanning method for an analytical database that is compatible with multiple storage engines.
[0028] Combine the following Figure 1 Embodiments of the present invention are described.
[0029] The present invention provides a delayed materialized scanning method for an analytical database compatible with multiple storage engines, comprising:
[0030] S1: Reading the data to be filtered from the disk and storing the data to be filtered in the buffer area.
[0031] Furthermore, after various storage engines read data from disk into memory, they generally place it in a buffer to wait for subsequent components to read it. After use, it is released according to different cache elimination strategies or released directly.
[0032] S2: calling the interface of the storage engine to control the cache area not to release the data to be filtered within a preset time.
[0033] The preset time in step S2 is greater than or equal to the execution time of the execution engine for filtering and materializing the data to be filtered.
[0034] Based on the aforementioned buffer zone release situation, step S2 of the present invention is to control the life cycle of the data in the buffer zone by calling the interface of the storage engine to ensure that it can be released only after filtering and materialization are completed in the execution engine.
[0035] Specifically, once the data is loaded into the buffer, an API can be used to access the data. If the data needs to be modified, the corresponding API function or method can be used to update the data in the buffer. The present invention can determine which data should be retained in the buffer and which should be removed by setting a data cache strategy, such as LRU (least recently used) or LFU (most recently used), etc. The implementation process sets an expiration time for the data. Once the data is in the buffer for more than this threshold, it should be automatically deleted, and then an API is provided to explicitly delete the data from the buffer. Finally, when the data is modified in the buffer, it needs to be refreshed back to the underlying storage system.
[0036] Wherein, the storage engine in step S2 is a vectorized storage engine.
[0037] S3: Encapsulate the memory address of the data to be filtered into a data block, and transfer the data block to the execution engine.
[0038] Furthermore, if the data flow directly copies the data in the buffer to a data block that can be processed by the execution engine, it is a typical early materialization implementation. In step S3 of the present invention, no copying is required. Only the memory address of the required data in the buffer is encapsulated as a special data block. Even if the data block is passed to the execution engine, it is still equivalent to no materialization.
[0039] S4: Convert the filter condition into the data format of the storage engine to be executed to obtain the adapted filter condition.
[0040] Among them, in step S4: converting the filter condition into the data format of the storage engine to be executed is achieved by rewriting the expression of the filter condition.
[0041] Wherein, in step S4: the process of converting the filtering condition is implemented in the execution engine.
[0042] Wherein, in step S4: when the filtering condition cannot be converted into the data format of the storage engine, the unfiltered data in the data to be filtered is returned to the execution engine, and the execution engine filters the unfiltered data.
[0043] Furthermore, simply referencing the buffer will not correctly read data when facing storage engines with different storage formats. For example, the data stored in some storage engines is encoded, and after being read into the memory, it needs to be decoded to restore it to a normal state. At this time, it is necessary to introduce the expression rewriting step to rewrite the filter conditions themselves to adapt to the data format of the storage engine. At the same time, some encoding formats cannot be adapted through expression rewriting. The program needs to distinguish such situations and fall back to the early materialized execution mode. It should be noted that the expression rewriting operations are all implemented in the data flow or execution engine, and the code does not need to invade the storage engine.
[0044] Among them, step S4 specifically includes: when the data of the storage engine is encoded and stored as a minimum value, the condition value of the adaptive filtering condition is the difference between the condition value of the filtering condition and the minimum value; when the data of the storage engine is stored in a comparable binary format, the condition value of the adaptive filtering condition is the condition value of the filtering condition calculated by a comparable binary encoding function.
[0045] Some specific examples of rewriting the expression described in step S4 are described below.
[0046] 1) Data is stored according to the minimum value encoding, that is, the minimum value of a batch of data is stored in the metadata, and the actual data is stored after subtracting this value to reduce the data volume;
[0047] Minimum value: 10000;
[0048] Stored values: 1, 2, 3;
[0049] Condition: X>10000;
[0050] Then the condition needs to be rewritten as X>(10000-minimum value), that is, X>0.
[0051] 2) Data is stored in a comparable binary format, and bin represents some comparable binary encoding function;
[0052] Storage value: bin(10000), bin(10001);
[0053] Condition: X>10000;
[0054] Then you need to rewrite the condition as X>bin(10000).
[0055] S5: filtering the storage engine according to the adaptation filtering condition and the data block, copying the remaining rows after filtering and returning them to the execution engine.
[0056] After steps S1 to S4, the filtering operation of the vectorized execution engine can be used to access the data in the buffer in a read-only manner. After the filtering is completed, only the remaining rows are copied, thereby achieving high-performance delayed materialized scanning for different storage engines.
[0057] Another specific example is described in detail below.
[0058] Query statement: select sum(a) from t1 where b>2 and c>2;
[0059] The characteristic of the above query is that the data is filtered according to the values of columns b and c, but the subsequent aggregation calculation part only requires the data of column a.
[0060] When the analytical database delayed materialized scanning method compatible with multiple storage engines provided by the present invention is not used, the specific data scanning process is as follows:
[0061] Read the data file of column b and fill the cache;
[0062] Copy column b from the cache, filter b>2, and record the row number that hits after filtering;
[0063] If the hit row is not 0, read the c column data file and fill the cache;
[0064] According to the row number hit in the second step, copy the corresponding row in column c from the cache, perform filtering on c>2, and record the hit row number;
[0065] If the hit row is not 0, read the data file of column a and fill the cache;
[0066] Copy column a from the cache according to the row number in step 4;
[0067] Output column a and release the memory of columns b and c after copying.
[0068] When using the analytical database delayed materialized scanning method compatible with multiple storage engines provided by the present invention, the specific data scanning process is as follows:
[0069] Read the data file of column b and fill the cache;
[0070] Construct a reference column for column b, rewrite the expression as needed, perform filtering, and record the row number hit after filtering;
[0071] If the hit row is not 0, read the c column data file and fill the cache;
[0072] According to the ratio of the hit row numbers in the second step of the previous sequence, determine whether to construct the reference column of column c (high hit ratio) or materialize according to the hit row number (low hit ratio), and perform c>2 filtering;
[0073] If the hit row is not 0, read the data file of column a and fill the cache;
[0074] Materialize column a according to the row number;
[0075] Output column a. If column c is copied, release the memory of column c.
[0076] After the above comparison, after using the analytical database delayed materialization scanning method compatible with multiple storage engines provided by the present invention, regardless of the storage engine's support for condition pushdown and filtering performance, it can ensure the high filtering performance of the computing engine and greatly reduce the amount of memory copying. In the above example, the materialization of column b is completely avoided, and whether column c is materialized is dynamically adjusted according to the filtering result. If the selection rate is high, the materialization of column c can be completely avoided. Although some invalid rows that have been filtered out by the condition of column b are included when filtering column c, due to the vectorized execution of the expression, the additional calculation of a small number of invalid rows has little impact on the performance, and ultimately the performance of data scanning is significantly improved. Under the premise that the storage engine performance remains unchanged and the filtering performance is not lost, the materialization overhead is almost eliminated after using the method described in the present invention. After using the present invention to optimize the database, the performance of the TPC-H benchmark test is also slightly improved. The greater the materialization overhead of the column type involved in the query, the more obvious the improvement.
[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A delayed materialized scanning method for an analytical database compatible with multiple storage engines, characterized in that: include: S1: Reading the data to be filtered from the disk and storing the data to be filtered in the buffer area; S2: calling the interface of the storage engine to control the cache area not to release the data to be filtered within a preset time, and the preset time is greater than or equal to the execution time of the execution engine for filtering and materializing the data to be filtered; S3: Encapsulate the memory address of the data to be filtered into a data block, and transfer the data block to the execution engine; S4: Convert the filter condition into the data format of the storage engine to be executed to obtain the adapted filter condition, which specifically includes: When the data of the storage engine is encoded and stored as a minimum value, the condition value of the adapted filtering condition is the difference between the condition value of the filtering condition and the minimum value; When the data of the storage engine is stored in a comparable binary format, the condition value of the adapted filtering condition is the condition value of the filtering condition calculated by the comparable binary encoding function; The filter condition is converted into a data format of a storage engine to be executed by rewriting the expression of the filter condition; S5: filtering the storage engine according to the adaptation filtering condition and the data block, copying the remaining rows after filtering and returning them to the execution engine.
2. According to the method for delayed materialized scanning of analytical databases compatible with multiple storage engines according to claim 1, it is characterized in that: The storage engine in step S2 is a vectorized storage engine.
3. According to the method for delayed materialized scanning of analytical databases compatible with multiple storage engines according to claim 1, it is characterized in that: In step S4, the process of converting the filtering conditions is implemented in the execution engine.
4. According to the method for delayed materialized scanning of analytical databases compatible with multiple storage engines according to claim 1, it is characterized in that: In step S4, when the filtering condition cannot be converted into the data format of the storage engine, the unfiltered data in the data to be filtered is returned to the execution engine, and the execution engine filters the unfiltered data.
