A database index optimization method, device, equipment, storage medium and product
By binding time metadata to each index and dynamically maintaining an index time range mapping table, the problem of data misalignment caused by the ambiguity between index data timestamps and index names is solved, improving query efficiency and accuracy.
Patent Information
- Application Number
- CN202611086288.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-11-27
AI Technical Summary
In existing technologies, data misalignment occurs during log writing due to the blurred time boundaries between the timestamp of the index data and the index name, which increases query complexity and reduces query efficiency.
Bind time metadata to each index, match indexes using an index time range mapping table, dynamically maintain the index time range mapping table to ensure that the timestamp of the data to be written strictly falls within the time range of the target index, and create a new index when no matching index is found.
This effectively avoids data misalignment caused by the ambiguity between the timestamp of the index data and the time boundary of the index name, reducing query complexity and improving query efficiency.
Smart Images

Figure CN123178394A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a database index optimization method, apparatus, device, storage medium, and product. Background Technology
[0002] Indexes in search-based databases are widely used in log analysis. In log query analysis, a two-dimensional rolling index, based on both time and size, is typically employed. New indexes are created during log writing using index template matching; during the log query phase, aliases bound via rollover are used to perform index queries across time ranges or specific index queries, thereby filtering the query data.
[0003] However, the existing log writing method may encounter boundary data misalignment issues when writing data to a specific date index. For example, if data arrives late, a service might generate a log at 2024-01-01T23:59:58, but network latency causes the log to arrive at the index only at 2024-01-02T00:00:05. According to the timestamp, this data should have been written to the logs-2024-01-01 index, but because the write time is already January 2nd, it might be incorrectly assigned to the logs-2024-01-02 index. This causes ambiguity between the timestamp of the index data and the time boundary of the index name, resulting in data misalignment, increased query complexity, and decreased query efficiency. Summary of the Invention
[0004] To address the problems existing in the prior art, embodiments of the present invention provide a database index optimization method, apparatus, device, storage medium, and product, which can effectively avoid data misalignment caused by the ambiguity of the time boundary between the timestamp of the index data and the index name, reduce query complexity, and improve query efficiency.
[0005] In a first aspect, embodiments of the present invention provide a database index optimization method, including: Based on the time field of the data to be written, index matching is performed through an index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; If an index is matched, the currently matched index will be used as the first target index. If no matching index is found, create a new index as the first target index; The time field of the data to be written is timestamped, and the data to be written that passes the verification is routed to the first target index for writing.
[0006] As an improvement to the above scheme, the time metadata includes: the minimum timestamp that the index is allowed to write, the maximum timestamp that the index is allowed to write, and the time field in the index used to identify the timestamp.
[0007] As an improvement to the above scheme, the process of creating a new index includes: Based on the time field of the data to be written, create a new index according to a preset time granularity, and generate the time metadata of the currently created index; Bind the currently created index and its time metadata, and update the index time range mapping table; The timestamp indicated by the time field of the data to be written falls within the time granularity range between the minimum and maximum timestamps indicated by the time metadata bound to the index.
[0008] As an improvement to the above solution, the method further includes: The query request initiated by the user is parsed to obtain the query time range in the query request; Based on the query time range, index pre-filtering is performed through the index time range mapping table to obtain candidate indexes, and the candidate indexes are sorted in chronological order to obtain a candidate index list; The query is rewritten based on the query time range to perform a binary search on the candidate index list and obtain the second target index.
[0009] As an improvement to the above scheme, based on the query time range, index pre-filtering is performed through the index time range mapping table to obtain candidate indexes, including: Based on the query time range, determine the time filtering conditions, and exclude indexes that meet the time filtering conditions from the index time range mapping table to obtain candidate indexes; If the query time range does not match the cold storage node, the indexes that have been migrated to the cold storage node are excluded from the candidate indexes to obtain the candidate indexes; If the query time range matches the cold storage node, the query is routed to the cold storage node, and the corresponding candidate index in the cold storage node is used as the candidate index. The cold storage node is used to store the index corresponding to the maximum timestamp exceeding a preset time threshold, and / or the heat label is the index corresponding to the cold label; the heat label of the index is determined based on the difference between the maximum timestamp of the corresponding index and the current timestamp.
[0010] As an improvement to the above solution, the method further includes: During the writing phase of the data to be written, the timestamp difference between the data to be written and its adjacent data, and the identification information of the data to be written are encoded to generate a document identifier for the data to be written, and the document identifier is written into an inverted list. Specifically, a timestamp range skip list is added to the inverted index corresponding to the inverted list; the timestamp range skip list is used to locate the index within the query time range to be queried based on the time metadata of each data in the inverted list.
[0011] Secondly, embodiments of the present invention provide a database index optimization apparatus, comprising: The index matching module is used to perform index matching based on the time field of the data to be written, through an index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; The index confirmation module is used to use the currently matched index as the first target index when an index is matched. The index creation module is used to create a new index as the first target index according to a preset time granularity when no matching index is found. The index routing module is used to perform timestamp verification on the time field of the data to be written, and to route the data to be written that passes the verification to the first target index for writing.
[0012] Thirdly, embodiments of the present invention provide a database index optimization device, comprising: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the database index optimization method as described in any one of the first aspects.
[0013] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the database index optimization method as described in any one of the first aspects.
[0014] Fifthly, embodiments of the present invention provide a computer program product, including a computer program or instructions that, when executed by a processor, implement the database index optimization method as described in any one of the first aspects.
[0015] Compared to existing technologies, the present invention provides a database index optimization method, apparatus, device, storage medium, and product. This method binds time metadata to each database index to indicate the timeliness boundaries of data within that index, and dynamically maintains an index time range mapping table to indicate the mapping relationship between the index and its bound time metadata. Subsequently, based on the time field of the data to be written, index matching is performed through the index time range mapping table. If an index is matched, it is used as the first target index; otherwise, a new index is created as the first target index. Then, the time field of the data to be written is timestamped, and the data that passes the verification is routed to the first target index for writing. By binding time metadata to each database index and dynamically maintaining the index time range mapping table, the present invention effectively avoids data misalignment caused by ambiguity between the timestamp of the index data and the time boundaries of the index name, reducing query complexity and improving query efficiency. Attached Figure Description
[0016] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of a database index optimization method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the data writing process provided in an embodiment of the present invention; Figure 3 This is a flowchart illustrating the query phase provided in an embodiment of the present invention; Figure 4 This is a structural block diagram of a database index optimization device provided in an embodiment of the present invention; Figure 5 This is a structural block diagram of a database index optimization device provided in an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] It is understood that the various numerical designations used in the embodiments of this invention are merely for descriptive convenience and are not intended to limit the scope of this application. The order of the process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic.
[0020] In embodiments of the invention, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising" does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element. The term "a plurality or several" refers to two or more.
[0021] See Figure 1 , Figure 1 This is a flowchart of a database index optimization method provided in an embodiment of the present invention. The database index optimization method specifically includes: S11: Based on the time field of the data to be written, perform index matching through the index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; The time metadata includes: the minimum timestamp that the index is allowed to write, the maximum timestamp that the index is allowed to write, and the time field used by the data in the index to identify the timestamp.
[0022] For example, time metadata is bound to each index to define the timeliness boundaries of the data within the corresponding index. Time metadata is tied to the index's lifecycle, requiring no additional storage costs and supporting dynamic updates, such as adjusting the time range when merging historical indexes. The time metadata includes the following fields: start_time: The minimum timestamp at which the index is allowed to be written, which is a closed interval.
[0023] End time (end_time): The maximum timestamp that the index is allowed to write to, which is an open interval.
[0024] Document time_field: A field in the document used to identify the time, such as @timestamp.
[0025] For example, time metadata = {[start_time, end_time), time_field}.
[0026] Using the fields mentioned above, time metadata can clearly define the time range of the index, avoiding boundary data misalignment caused by fuzzy index time windows.
[0027] Furthermore, time metadata can be stored by extending the `settings` property of the Elasticsearch index configuration, providing index-level metadata and avoiding intrusion into the data document. For example, a time metadata field `index.time_metadata` can be added to the `settings` field of the `logs-2024-08-01` index configuration to store time metadata content, such as: `ime_field: @timestamp`, `start_time: 2024-08-01T00:00:00.000Z`, `end_time: 2024-08-02T00:00:00.000Z`.
[0028] Furthermore, a global mapping table of index time ranges can be maintained in the cluster state, namely the aforementioned index time range mapping table, such as IndexTimeRangeMap, to achieve global view maintenance, thereby enabling fast retrieval support.
[0029] This invention enhances index definition by introducing time metadata. It dynamically binds time metadata to each Elasticsearch index, clearly defining the time boundaries of data within the index and strictly associating it with the data's time field (time_field). By using the time range indicated by the time metadata as a meta-attribute of the index, it replaces traditional index management methods based on write time or naming rules, enabling precise control over data timeliness.
[0030] It should be noted that the embodiments of the present invention can be used for Internet of Things (IoT) time-series data, such as log data, device sensor data such as temperature and pressure; financial transaction monitoring data, such as order data; medical and health data, such as ECG and blood glucose monitoring data, etc., but are not specifically limited in the embodiments of the present invention.
[0031] S12: If an index is matched, the currently matched index will be used as the first target index; S13: If no index is found, create a new index as the first target index; S14: Perform timestamp verification on the time field of the data to be written, and route the data to be written that passes the verification to the first target index for writing.
[0032] To ensure that the timestamp indicated by the time_field of the data to be written strictly falls within the time range [start_time, end_time] of the first target index, this embodiment of the invention introduces a dynamic index routing and timestamp verification mechanism based on time metadata, such as... Figure 2 As shown, the specific data writing process is as follows: Based on the `time_field` value of the data to be written carried in the user's write request, the index time range mapping table `IndexTimeRangeMap` is traversed. Time range parsing and filtering are performed on the indexes based on their time metadata, selecting an index that satisfies `time_field ∈ [start_time, end_time)`. Through the metadata service, if an index is matched, an automatic rollover mechanism is triggered to create a new index, which is then used as the first target index. The data to be written is routed to this index for execution. At this point, the `[start_time, end_time)` of the first target index should satisfy `time_field ∈ [start_time, end_time)`. If an index is matched, the matched index satisfying `time_field ∈ [start_time, end_time)` is used as the first target index, and the data to be written is routed to this index for execution.
[0033] Insert a preprocessing channel, such as an Ingest Pipeline, before writing data to perform preprocessing, or perform preprocessing on other servers before writing data to verify whether the time field of the data to be written is valid. For example, if the timestamp indicated by the time field of the data to be written falls within the time range of the first target index, the subsequent write operation is performed after the timestamp verification is passed; otherwise, the write operation is rejected if the time verification fails.
[0034] For example, before writing data, the preprocessing channel verifies whether the data timestamp is within the [start_time, end_time) range of the currently determined target index, i.e., the first target index. If it exceeds the range, index matching is re-executed to automatically route to the correct index or trigger a new index rollover. By forcibly verifying the matching between the document timestamp and the index time metadata during writing, and rejecting the write or automatically routing to the correct index if it exceeds the range, the time range of data within the index is strictly continuous. This ensures that delayed data can also be written to the accurate index, improving data consistency and avoiding query omissions or redundancy.
[0035] By using dynamic routing decisions and automatic rolling strategies, the problem of data misplacement caused by data delays or time window misalignments in traditional solutions can be solved.
[0036] In this embodiment of the invention, when the index is not closed, based on the index's time metadata, delayed data can be appended to the historical index, reducing boundary data misalignment.
[0037] Furthermore, by synchronizing UTC (Coordinated Universal Time) and NTP (Network Time Protocol), a clock rollback protection mechanism can be introduced to avoid write misalignment caused by inconsistent node times.
[0038] This invention binds time metadata to each index in the database to indicate the timeliness boundaries of the data within that index, and dynamically maintains an index time range mapping table to indicate the mapping relationship between the index and its bound time metadata. Subsequently, based on the time field of the data to be written, index matching is performed in the index time range mapping table to find an existing index range that meets the timestamp requirement indicated by that time field. If found, the data to be written, verified by the timestamp, is routed to the currently found existing index for data writing. If not found, a new index is generated first, and then the data to be written, verified by the timestamp, is routed to the newly generated index for data writing. By binding time metadata to each index in the database to indicate the timeliness boundaries of the data within that index, this invention avoids data misalignment caused by ambiguity between the timestamp of the index data and the time boundaries of the index name, reducing query complexity and improving query efficiency.
[0039] In one alternative embodiment, the process of creating a new index includes: Based on the time field of the data to be written, create a new index according to a preset time granularity, and generate the time metadata of the currently created index; Bind the currently created index and its time metadata, and update the index time range mapping table; The timestamp indicated by the time field of the data to be written falls within the time granularity range between the minimum and maximum timestamps indicated by the time metadata bound to the index.
[0040] For example, when the timestamp of the data to be written exceeds the time range of all existing indexes (i.e., no index satisfying time_field∈[start_time, end_time) is found), a new index is generated based on a predefined time granularity, such as by day or hour. For instance, if time_field=2024-01-01T23:59:58 and the time granularity is days, then the time range of the newly generated index will be [2024-08-01T00:00:00.000Z, 2024-08-02T00:00:00.000Z). Simultaneously, the newly generated index is updated in the IndexTimeRangeMap table for dynamic maintenance, achieving automatic index expansion and dynamic management of time metadata.
[0041] Furthermore, the method also includes: The query request initiated by the user is parsed to obtain the query time range in the query request; Based on the query time range, index pre-filtering is performed through the index time range mapping table to obtain candidate indexes, and the candidate indexes are sorted in chronological order to obtain a candidate index list; The query is rewritten based on the query time range to perform a binary search on the candidate index list and obtain the second target index.
[0042] For example, such as Figure 3 As shown, during the query phase, the query time range [query_start, query_end] is extracted from the query request initiated by the user by parsing the query request. If there is no explicit condition in the query request, the query request will cover all indexes by default.
[0043] Then, based on the query time range [query_start, query_end), the index time range mapping table IndexTimeRangeMap is traversed. The index time range is parsed and filtered based on the index's time metadata, quickly filtering out indexes that meet the following conditions: (index.start_time)<query_end) AND (index.end_time> The query_start function retrieves the remaining indexes, which are then used as candidate indexes. For the selected candidate indexes, based on the metadata service, a binary search is used to quickly match the time range, reducing the time complexity from O(N) to O(logN). The second target index that falls within the query time range [query_start, query_end) is found, and the query is routed to that index for distributed query to find data that matches the query time range [query_start, query_end).
[0044] For example, during query rewriting, the index alias of the original query, such as logs_ Replace with the filtered candidate index list, such as logs-2024-08-01, logs-2024-08-02. Then, based on the query time range [query_start, query_end), perform time matching on the time range of the logs-2024-08-01 and logs-2024-08-02 indexes.
[0045] This invention automatically extracts the time range from the query request based on the time_field field of the time metadata, and uses binary search to quickly match the data that satisfies (index.start_time).<query_end) AND (index.end_time> The pre-filtering mechanism of the `query_start` index only filters indexes with overlapping time metadata, reducing invalid index scans by at least 70%. This effectively reduces redundant index scans, significantly lowering CPU and disk I / O overhead. Users do not need to be aware of the underlying index distribution, balancing ease of use and performance. Fast and accurate time range matching through query rewriting avoids scanning shards of irrelevant indexes. Moving the index selection logic from the query execution layer to the routing resolution layer reduces the number of open Lucene segments, further reducing CPU and disk I / O pressure.
[0046] It should be noted that in other embodiments, a Bloom filter or an interval tree can be used instead of the binary search algorithm to find candidate indexes that meet the query time range. This is not limited in the embodiments of the present invention. In one optional embodiment, based on the query time range, index pre-filtering is performed through the index time range mapping table to obtain candidate indexes, including: Based on the query time range, determine the time filtering conditions, and exclude indexes that meet the time filtering conditions from the index time range mapping table to obtain candidate indexes; If the query time range does not match the cold storage node, the indexes that have been migrated to the cold storage node are excluded from the candidate indexes to obtain the candidate indexes; If the query time range matches the cold storage node, the query is routed to the cold storage node, and the corresponding candidate index in the cold storage node is used as the candidate index. The cold storage node is used to store the index corresponding to the maximum timestamp exceeding a preset time threshold, and / or the heat label is the index corresponding to the cold label; the heat label of the index is determined based on the difference between the maximum timestamp of the corresponding index and the current timestamp.
[0047] In this embodiment of the invention, for each index, a heat label can be automatically assigned based on the difference between the maximum timestamp indicated by the index's end time (end_time) and the current timestamp, including a hot label, a warm label, and a cold label.
[0048] For example, different time threshold conditions can be set for different tags. If the timestamp difference meets the corresponding time threshold condition, the tag is assigned to the corresponding tag. For example, the time threshold condition for cold tags is: based on the current time, indexes older than 20 days are assigned cold tags; the time threshold condition for hot tags is: based on the current time, indexes within 5 days are assigned hot tags; and the time threshold condition for warm tags is: based on the current time, indexes between 5 and 20 days are assigned warm tags. For example, if the current time is 2024-08-25, then end_time < 2024-08-05, and the corresponding index is marked as cold, that is, the index with the end time before 2024-08-05 is marked as cold.
[0049] For indexes whose end_time exceeds the preset time threshold, or indexes that have been assigned the cold tag, the ILM (Index Lifecycle Management) strategy is triggered to migrate them to low-performance cold storage nodes.
[0050] During the pre-filtering stage of the query, the popularity tags of the initially selected candidate indexes can be checked. If the popularity tags of the initially selected candidate indexes are all cold tags, it means that the query time range hits the cold storage node. In this case, the query will be automatically routed to the cold storage node, and the candidate indexes with cold popularity tags that have been migrated to the cold storage node will be used as candidate indexes for time range matching. Otherwise, it means that the query time range does not hit the cold storage node. The candidate indexes with cold popularity tags that have been migrated to the cold storage node can be excluded, and the remaining candidate indexes will be used as candidate indexes for time range matching. This allows for highly accurate index filtering, avoiding the overall query delay caused by invalid scanning of cold node indexes in hot queries, and further improving query efficiency.
[0051] This invention introduces a hot and cold data stratification linkage mechanism based on time metadata. The automated hot and cold data stratification driven by time metadata replaces manual configuration rules, which can optimize the migration of hot and cold data, improve resource utilization, and deeply bind the hot and cold data stratification with time metadata to reduce manual maintenance costs.
[0052] Meanwhile, when ordinary users use DSL statements to query indexes, they do not need to worry about the distribution of hot and cold index data. They only need to specify the query time range, which avoids the risk of wildcard queries potentially crashing the entire cluster.
[0053] Furthermore, the method also includes: During the writing phase of the data to be written, the timestamp difference between the data to be written and its adjacent data, and the identification information of the data to be written are encoded to generate a document identifier for the data to be written, and the document identifier is written into an inverted list. Specifically, a timestamp range skip list is added to the inverted index corresponding to the inverted list; the timestamp range skip list is used to locate the index within the query time range to be queried based on the time metadata of each data in the inverted list.
[0054] This invention, based on time metadata, introduces a time-semantic-based inverted index compression optimization mechanism to reduce storage costs. The time-semantic-based inverted index compression optimization mechanism specifically includes: Timestamp difference encoding: When storing document identifiers for written data in an inverted index, the timestamp difference between consecutive data is jointly encoded with the data's identifier information. For example, the timestamp difference between the current data to be written and the data written at the previous adjacent time is concatenated with the identifier information of the current data to be written to generate a document identifier for the data to be written, which is then written to the inverted index associated with that data. This embodiment of the invention utilizes the temporal continuity of data for document identifier encoding, which can improve the compression ratio. The storage space for timestamp fields can be compressed by more than 40%, effectively reducing storage costs.
[0055] Adding a timestamp range skip list: The current index's time type is based on the RLE (Run-Length Encoding) algorithm, which compresses the time type based on the continuous repetition of timestamps, resulting in a large space consumption. Once the index has start_time and end_time metadata, a timestamp range skip list is added to the inverted index. Based on the start_time and end_time in the index's time metadata, indexes that meet the time range condition (time_range) can be quickly located. Simultaneously, combined with the decoding of document identifiers in the inverted list, indexes that meet the term condition can be quickly located, reducing random disk reads. For time range queries across multiple indexes, latency can be reduced by more than 30%, thus accelerating time range queries.
[0056] See Figure 4 , Figure 4 This is a structural block diagram of a database index optimization device provided in an embodiment of the present invention. The database index optimization device includes: The index matching module 11 is used to perform index matching based on the time field of the data to be written, through an index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; The index confirmation module 12 is used to use the currently matched index as the first target index when an index is matched. The index creation module 13 is used to create a new index as the first target index according to a preset time granularity when no index is matched. The index routing module 14 is used to perform timestamp verification on the time field of the data to be written, and to route the data to be written that passes the verification to the first target index for writing.
[0057] In one optional embodiment, the time metadata includes: the minimum timestamp that the index allows to be written, the maximum timestamp that the index allows to be written, and a time field in the index used to identify the timestamp.
[0058] In one alternative embodiment, the index creation module includes: The index generation unit is used to create a new index according to the time field of the data to be written, according to a preset time granularity, and generate the time metadata of the currently created index. The metadata management unit is used to bind the currently created index and its time metadata, and update the index time range mapping table; The timestamp indicated by the time field of the data to be written falls within the time granularity range between the minimum and maximum timestamps indicated by the time metadata bound to the index.
[0059] In an optional embodiment, the device further includes: The query parsing module is used to parse the query request initiated by the user and obtain the query time range in the query request; The index pre-filtering module is used to perform index pre-filtering based on the query time range through the index time range mapping table to obtain candidate indexes, and sort the candidate indexes in chronological order to obtain a candidate index list; The binary search module is used to rewrite the query based on the query time range in order to perform a binary search on the candidate index list and obtain the second target index.
[0060] In one optional embodiment, the index pre-filtering module includes: The time filtering unit is used to determine the time filtering conditions based on the query time range, and exclude indexes that meet the time filtering conditions from the index time range mapping table to obtain candidate indexes; An index exclusion unit is used to exclude indexes that have been migrated to the cold storage node from the candidate indexes when the query time range does not hit the cold storage node, thereby obtaining the candidate indexes; A cold storage routing unit is configured to route to the cold storage node when the query time range matches the cold storage node, and use the corresponding alternative index in the cold storage node as the candidate index. The cold storage node is used to store the index corresponding to the maximum timestamp exceeding a preset time threshold, and / or the heat label is the index corresponding to the cold label; the heat label of the index is determined based on the difference between the maximum timestamp of the corresponding index and the current timestamp.
[0061] In an optional embodiment, the device further includes: The document identifier writing module is used to encode the timestamp difference between the data to be written and its adjacent data and the identifier information of the data to be written during the writing stage of the data to be written, generate the document identifier of the data to be written, and write the document identifier into the inverted list. Specifically, a timestamp range skip list is added to the inverted index corresponding to the inverted list; the timestamp range skip list is used to locate the index within the query time range to be queried based on the time metadata of each data in the inverted list.
[0062] It should be noted that the working process of each module in the database index optimization device described in the embodiments of the present invention can refer to the working process of the database index optimization method described in the above embodiments, and the technical effect achieved is the same as that of the database index optimization method described in the above embodiments, so it will not be repeated here.
[0063] See Figure 5 , Figure 5 This is a structural block diagram of a database index optimization device provided in an embodiment of the present invention. The database index optimization device includes a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, it implements the steps in the above-described embodiments of the various database index optimization methods, such as steps S11 to S14.
[0064] For example, the computer program may be divided into one or more modules or units, which are stored in the memory 22 and executed by the processor 21 to complete the present invention. The one or more modules or units may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the database index optimization device.
[0065] The database index optimization device may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art will understand that the schematic diagram is merely an example of a database index optimization device and does not constitute a limitation on the device. It may include more or fewer components than illustrated, or combine certain components, or different components. For example, the database index optimization device may also include input / output devices, network access devices, buses, etc.
[0066] The processor 21 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor 21 is the control center of the database index optimization device, connecting various parts of the entire database index optimization device through various interfaces and lines.
[0067] The memory 22 can be used to store the computer programs and / or modules. The processor 21 implements various functions of the database index optimization device by running or executing the computer programs and / or modules stored in the memory 22 and calling the data stored in the memory 22. The memory 22 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0068] If the modules or units integrated into the database index optimization device are implemented as software functional units and sold or used as independent products, they 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 the processor 21, 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.
[0069] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and 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 modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0070] The above description represents the preferred embodiments of the present invention. It should be noted that, for those skilled in the art, various improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A database index optimization method, characterized in that, include: Based on the time field of the data to be written, index matching is performed through an index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; If an index is matched, the currently matched index will be used as the first target index. If no matching index is found, create a new index as the first target index; The time field of the data to be written is timestamped, and the data to be written that passes the verification is routed to the first target index for writing.
2. The database index optimization method as described in claim 1, characterized in that, The time metadata includes: the minimum timestamp that the index is allowed to write, the maximum timestamp that the index is allowed to write, and the time field used by the data in the index to identify the timestamp.
3. The database index optimization method as described in claim 2, characterized in that, The process of creating a new index includes: Based on the time field of the data to be written, create a new index according to a preset time granularity, and generate the time metadata of the currently created index; Bind the currently created index and its time metadata, and update the index time range mapping table; The timestamp indicated by the time field of the data to be written falls within the time granularity range between the minimum and maximum timestamps indicated by the time metadata bound to the index.
4. The database index optimization method as described in claim 1, characterized in that, The method further includes: The query request initiated by the user is parsed to obtain the query time range in the query request; Based on the query time range, index pre-filtering is performed through the index time range mapping table to obtain candidate indexes, and the candidate indexes are sorted in chronological order to obtain a candidate index list; The query is rewritten based on the query time range to perform a binary search on the candidate index list and obtain the second target index.
5. The database index optimization method as described in claim 4, characterized in that, Based on the query time range, index pre-filtering is performed using the index time range mapping table to obtain candidate indexes, including: Based on the query time range, determine the time filtering conditions, and exclude indexes that meet the time filtering conditions from the index time range mapping table to obtain candidate indexes; If the query time range does not match the cold storage node, the indexes that have been migrated to the cold storage node are excluded from the candidate indexes to obtain the candidate indexes; If the query time range matches the cold storage node, the query is routed to the cold storage node, and the corresponding candidate index in the cold storage node is used as the candidate index. The cold storage node is used to store the index corresponding to the maximum timestamp exceeding a preset time threshold, and / or the heat label is the index corresponding to the cold label; the heat label of the index is determined based on the difference between the maximum timestamp of the corresponding index and the current timestamp.
6. The database index optimization method as described in claim 1, characterized in that, The method further includes: During the writing phase of the data to be written, the timestamp difference between the data to be written and its adjacent data, and the identification information of the data to be written are encoded to generate a document identifier for the data to be written, and the document identifier is written into an inverted list. Specifically, a timestamp range skip list is added to the inverted index corresponding to the inverted list; the timestamp range skip list is used to locate the index within the query time range to be queried based on the time metadata of each data in the inverted list.
7. A database index optimization device, characterized in that, include: The index matching module is used to perform index matching based on the time field of the data to be written, through an index time range mapping table; wherein, the index time range mapping table is used to indicate the mapping relationship between the index and its bound time metadata; the time metadata is used to indicate the timeliness boundary of the data within the index; The index confirmation module is used to use the currently matched index as the first target index when an index is matched. The index creation module is used to create a new index as the first target index according to a preset time granularity when no matching index is found. The index routing module is used to perform timestamp verification on the time field of the data to be written, and to route the data to be written that passes the verification to the first target index for writing.
8. A database index optimization device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the database index optimization method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the database index optimization method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the database index optimization method according to any one of claims 1 to 6.
