Data index generation method, device, electronic device and readable storage medium
Generating ordered index files through parallel traversal and Map/Reduce algorithm solves the problems of long database online index construction time and heavy disk load in the existing technology, and achieves efficient index creation and resource saving.
Patent Information
- Application Number
- CN202010244790.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-31
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2040-09-17
AI Technical Summary
When building online indexes for existing databases, the processing time is long and the disk load is heavy, which affects service stability and makes it difficult to improve the concurrency rate and index creation speed.
By acquiring multiple data files based on the LSM storage engine, traversing and parsing them in parallel, using the Map/Reduce algorithm to generate ordered index files, and storing and loading them in a physically isolated manner to avoid repeated sorting and writing and improve concurrency. sex and efficiency.
Significantly improves the speed of data index creation, saves system resources and creation time, and reduces the load on database services.
Smart Images

Figure CN111831622B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a data index generating method, device, electronic device and readable storage medium. Background Art
[0002] The database will create indexes based on the data for quick query. Currently, when the database system provides services in the production environment, it is often necessary to add new indexes online. The traditional solution is to traverse the data in all files first, then generate the data that needs to be indexed, and finally rewrite it into the database to build the index. The processing time required for this index construction method is long and uncontrollable. In addition, the disk load caused by traversing and writing data will also increase the test of online service stability. Summary of the invention
[0003] In view of this, an embodiment of the present invention provides a data index generation method, device, electronic device and readable storage medium to increase the speed of establishing a data index.
[0004] In a first aspect, an embodiment of the present invention provides a method for generating a data index, the method comprising:
[0005] Get multiple data files in a database stored in the LSM storage engine;
[0006] Traversing and parsing the multiple data files in parallel to generate parsed data, the parsed data including index data of each data in the data files;
[0007] Determine at least one index file according to the parsed data, wherein the index data in the index file is ordered;
[0008] Each of the index files is loaded into a corresponding database.
[0009] Optionally, the data file and the index file are stored in a physically isolated manner.
[0010] Optionally, multiple data files are traversed and parsed in parallel to generate parsed data including:
[0011] Traversing the plurality of data files in parallel to determine index columns in each of the data files, wherein at least one of the index columns is identification information;
[0012] The data values of the index column are encoded to generate index data of each data in the data file to determine the parsed data.
[0013] Optionally, multiple data files are traversed and parsed in parallel to generate parsed data including:
[0014] Parsing the plurality of data files in parallel by using a Map algorithm to generate the parsed data;
[0015] Determining at least one index file according to the parsed data includes:
[0016] At least one index file is generated according to the parsed data by using a Reduce algorithm.
[0017] Optionally, obtaining multiple data files in a database stored based on the LSM storage engine includes:
[0018] Receive multiple data files sent by the device where the database is located.
[0019] Optionally, loading each of the index files into a corresponding database includes:
[0020] Each of the index files is sent to the device where the database is located, so that the device loads each of the index files into the database.
[0021] Optionally, the size of the data file is a first preset value, and the size of the index file is a second preset value.
[0022] Optionally, the first preset value is 64M, and the second preset value is 64M.
[0023] In a second aspect, an embodiment of the present invention provides a data index generating device, the device comprising:
[0024] A data file acquisition unit is configured to acquire a plurality of data files in a database stored based on an LSM storage engine;
[0025] A parsing unit, configured to traverse and parse the multiple data files in parallel to generate parsed data, wherein the parsed data includes index data of each data in the data files;
[0026] an index file determining unit, configured to determine at least one index file according to the parsed data, wherein the index data in the index file is ordered;
[0027] The loading unit is configured to load each of the index files into a corresponding database.
[0028] Optionally, the data file and the index file are stored in a physically isolated manner.
[0029] Optionally, the parsing unit includes:
[0030] An index column determination subunit is configured to traverse the plurality of data files in parallel to determine index columns in each of the data files, wherein at least one of the index columns is identification information;
[0031] The encoding subunit is configured to encode the data value of the index column to generate index data of each data in the data file to determine the parsed data.
[0032] Optionally, the parsing unit is further configured to parse the plurality of data files in parallel through a Map algorithm to generate the parsed data;
[0033] The index file determination unit is further configured to generate at least one index file according to the parsed data by using a Reduce algorithm.
[0034] Optionally, the data file acquisition unit includes:
[0035] The receiving subunit is configured to receive a plurality of data files sent by the device where the database is located.
[0036] Optionally, the loading unit includes:
[0037] The sending subunit is configured to send each of the index files to the device where the database is located, so that the device loads each of the index files into the database.
[0038] Optionally, the size of the data file is a first preset value, and the size of the index file is a second preset value.
[0039] Optionally, the first preset value is 64M, and the second preset value is 64M.
[0040] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described above.
[0041] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the method as described above is implemented.
[0042] The embodiment of the present invention obtains multiple data files in a database stored based on an LSM storage engine, traverses and parses the multiple data files in parallel, generates parsed data, determines at least one index file based on the parsed data, and loads each of the index files into a corresponding database, wherein the parsed data includes index data of each data in the data file, and the index data in the index file is ordered, thereby improving the speed of establishing data indexes. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0044] Figure 1 It is a schematic diagram of the data index generation process of the prior art;
[0045] Figure 2 is a flow chart of a data index generating method according to an embodiment of the present invention;
[0046] Figure 3 is a schematic diagram of a data storage process according to an embodiment of the present invention;
[0047] Figure 4 is a schematic diagram of a data index generation process according to an embodiment of the present invention;
[0048] Figure 5 is a schematic diagram of another data index generation process according to an embodiment of the present invention;
[0049] Figure 6 is a flow chart of another data index generating method according to an embodiment of the present invention;
[0050] Figure 7 is a schematic diagram of a data index generating device according to an embodiment of the present invention;
[0051] Figure 8 is a schematic diagram of another data index generating device according to an embodiment of the present invention;
[0052] Fig. 9 is a schematic diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0053] The present invention is described below based on embodiments, but the present invention is not limited to these embodiments. In the detailed description of the present invention below, some specific details are described in detail. It is possible for a person skilled in the art to fully understand the present invention without the description of these details. In order to avoid confusing the essence of the present invention, known methods, processes, flows, components and circuits are not described in detail.
[0054] In addition, persons of ordinary skill in the art will appreciate that the drawings provided herein are for illustration purposes and are not necessarily drawn to scale.
[0055] Unless the context clearly requires otherwise, words such as “include”, “including” and the like in the specification should be interpreted as including rather than being exclusive or exhaustive; that is, as including but not limited to “including”.
[0056] In the description of the present invention, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, "plurality" means two or more.
[0057] Figure 1 It is a schematic diagram of the data index generation process of the prior art. Database services often need to build the index online in full, that is, to calculate and generate index data based on historical data. In the prior art, it usually relies on the storage engine, builds a full-volume scanning program in the program, traverses in units of single data to find the data that needs to be re-indexed, parses the data that needs to be indexed to obtain parsed data, and reorganizes the parsed data, and re-obtains new data files and index files based on the corresponding storage engine, where the parsed data may include information that uniquely identifies the data (such as the primary key, etc.) and data information. Figure 1 As shown, the data in the data file 11 in the database 1 is traversed line by line, the data that needs to be indexed is determined, and the data that needs to be indexed is parsed to obtain parsed data 2, and the parsed data 2 is reorganized, and a new data file 11 and index file 12 are obtained based on the corresponding storage engine. Therefore, in the prior art, each piece of data in the data file 11 needs to be traversed line by line. If parallel traversal and parsing are adopted, it will occupy a lot of system resources, which may affect the execution of other applications in the system. Therefore, it is difficult to improve the concurrency rate in the prior art, and the index creation process is slow and time-consuming.
[0058] Therefore, an embodiment of the present invention provides a data index generation method, which achieves high concurrency of data traversal and analysis by parallel traversal and analysis of data in units of data files, thereby improving the efficiency of index creation.
[0059] Figure 2 FIG. 1 is a flow chart of a method for generating a data index according to an embodiment of the present invention. Figure 2 As shown, the data index generation method of this embodiment includes the following steps:
[0060] Step S110, obtaining multiple data files in a database stored based on an LSM storage engine. In an optional implementation, the size of the data file is a first predetermined value, and optionally, the first predetermined value is 64M.
[0061] The LSM storage engine is a storage engine based on LSM-tree (Log-Structured Merged-Tree). Among them, the LSM storage engine provides a file loading method so that files (SST files) generated by certain rules can be quickly imported into the database. The core idea of the LSM storage engine is to keep the modified increments of the data in memory and write these modified increments to the disk in batches after reaching the specified size limit.
[0062] Figure 3 FIG. 1 is a schematic diagram of the data storage process of an embodiment of the present invention. Figure 3 As shown, the LSM storage engine 3 mainly includes a MemTable file 311 and a frozen MemTable file 312 in the memory 31, as well as files on the disk 32, such as an SST file 321, an operation log file (not shown in the figure), etc. When a record is written based on the storage engine 3, the modification increment is first written to the operation log file, and then the modification increment is written to the MemTable file 311 in the memory. After the memory occupied by the MemTable file 311 reaches the upper limit, the data in the memory needs to be dumped into an external memory file. Specifically, the MemTable file 311 is first frozen into an immutable frozen MemTable file 312, and then the data of the frozen MemTable file 312 is sorted and dumped to the disk 32 to form a new SST file. Among them, the data in the SST file is ordered, for example, sorted based on the primary key. As a result, the data files in the database stored based on the LSM storage engine are ordered and have a predetermined size. Optionally, the size of the data file can be set by setting the upper limit of the memory occupied by the MemTable file 311. It should be understood that Figure 3 The data storage process based on the LSM storage engine is merely exemplary, and other data storage methods based on the LSM storage engine may be applied to this embodiment.
[0063] Step S120, traverse and parse multiple data files in parallel to generate parsed data, wherein the parsed data includes index data of each data in the data files.
[0064] In an optional implementation, step S120 may include:
[0065] A1: traverse multiple data files in parallel to determine the index columns in each data file, wherein at least one of the index columns is identification information. Optionally, traverse multiple data files in parallel to determine the data in the data files that need to be indexed and the index columns of each data file. Optionally, assuming that the data file includes a student's grade table, the student's student ID column, name column, etc. can be determined as index columns, wherein the student's student ID column is identification information, which can uniquely identify the student.
[0066] A2: Encode the data value of the index column to generate the index data of each data in the data file to determine the parsed data. The parsed data includes the index data of each data in the data file. Optionally, the data value of the index column is encoded according to a predetermined encoding rule to generate the index data of the data file, thereby determining the parsed data. In an optional implementation, the index data of [primary key, data] is created according to a predetermined encoding rule, that is, the corresponding data is obtained according to the primary key during the indexing process, wherein the primary key is information that can uniquely identify the data, such as a student ID number. In another optional implementation, [index, primary key] is created according to a predetermined encoding rule, that is, the corresponding primary key is queried according to the corresponding index during the indexing process, and then the corresponding data is obtained according to the primary key.
[0067] Step S130, determining at least one index file according to the parsed data, wherein the index data in the index file is in order.
[0068] In an optional implementation, this embodiment uses a Map / Reduce programming model to implement parallel processing of multiple data files. Specifically, multiple data files are parsed in parallel by a Map algorithm to determine the index data and data information of each data in each data file, generate parsed data, and generate at least one ordered index file based on the parsed data by a Reduce algorithm. Optionally, the Reduce algorithm writes the parsed data through an LSM storage engine to generate at least one index file, whereby the index file is also a SST type file.
[0069] Figure 4 FIG. 1 is a schematic diagram of a data index generation process according to an embodiment of the present invention. Figure 4As shown, multiple data files D1-DN are parsed in parallel by the Map algorithm to obtain parsed data X, and multiple ordered index files I1-IM are generated by the Reduce algorithm. Wherein, N is greater than or equal to 1, and M is greater than or equal to 1. Optionally, the size of the data file is a first preset value, and the size of the index file is a second preset value, wherein the first preset value and the second preset value may be the same or different. Optionally, the first preset value and the second preset value are both 64M. It should be understood that during the Reduce processing, multiple ordered index files are generated according to the index data of each data in the parsed data X. That is, the index data in the index file is ordered, and thus, the data file and the index file may not correspond one to one.
[0070] Step S140, loading each index file into the corresponding database to complete the data index creation process.
[0071] In an optional implementation, the data files and index files of this embodiment are stored in a physically isolated manner, so that there is no need to reorganize the parsed data and then obtain new data files and index files based on the storage engine, thereby further saving system resources and data index creation time.
[0072] Figure 5 FIG. 1 is a schematic diagram of another data index generation process according to an embodiment of the present invention. Figure 5 As shown, in this embodiment, multiple data files 51 in the parsed database 5 are traversed in parallel through Map / Reduce to determine the index columns in each data file, and the data values of the index columns are encoded to generate the index data of each data in the data file, the parsed data is determined, and at least one index file 52 is generated according to the parsed data, and the index file 52 is imported into the database to complete the data index creation process. Therefore, this embodiment saves a lot of system resources and data index creation time by storing data files and index files in a physically isolated manner, so that there is no need to reorganize the parsed data, and then obtain new data files and index files based on the storage engine.
[0073] The embodiment of the present invention obtains multiple data files in a database stored based on an LSM storage engine, traverses and parses the multiple data files in parallel, generates parsed data, determines at least one index file based on the parsed data, and loads each of the index files into a corresponding database, wherein the parsed data includes index data of each data in the data file, and the index data in the index file is ordered. Thus, the embodiment improves the speed of establishing data indexes by traversing and parsing and constructing data indexes in parallel based on data files. At the same time, in the embodiment, data traversal is not dependent on the storage engine, which makes it easy to increase the concurrency of data traversal and further saves the time of traversal and parsing. In addition, the embodiment stores data files and index files in a physically isolated manner, so that there is no need to reorganize the parsed data, and then obtain new data files and index files based on the storage engine, which saves a lot of system resources and data index creation time.
[0074] Figure 6 FIG. 1 is a flow chart of another data index generation method according to an embodiment of the present invention. Figure 6 As shown, the data index generation method of the embodiment of the present invention includes the following steps:
[0075] Step S1, the index creation device receives multiple data files in the database sent from the device where the database is located. The multiple data files in the database are stored based on the LSM storage engine. The data files are ordered SST type data files.
[0076] Step S2, on the index creation device, traverse and parse multiple data files in parallel to generate parsed data. The parsed data includes index data of each data in the data file. In an optional implementation, traverse multiple data files in parallel, determine the index column in each data file, encode the data value of the index column to generate the index data of each data in the data file, so as to determine the parsed data. At least one column in the index column is identification information, and the parsed data includes index data of each data in the data file. Optionally, assuming that the data file includes a student's grade table, the student's student number column, name column, etc. can be determined as index columns, wherein the student's student number column is identification information, that is, the student can be uniquely identified.
[0077] Optionally, the data value of the index column is encoded according to a predetermined encoding rule to generate the index data of the data file, thereby determining the parsed data. In an optional implementation, the index data of [primary key, data] is created according to a predetermined encoding rule, that is, the corresponding data is obtained according to the primary key during the indexing process, wherein the primary key is information that can uniquely identify the data, such as a student ID number. In another optional implementation, [index, primary key] is created according to a predetermined encoding rule, that is, the corresponding primary key is queried according to the corresponding index during the indexing process, and then the corresponding data is obtained according to the primary key.
[0078] Step S3, on the index creation device, determine at least one index file based on the parsed data. The index data in the index file is ordered. In an optional implementation, this embodiment uses the Map / Reduce programming model to implement parallel processing of multiple data files. Specifically, multiple data files are parsed in parallel through the Map algorithm to determine the index data and data information of each data in each data file, generate parsed data, and generate at least one ordered index file based on the parsed data through the Reduce algorithm. Optionally, the Reduce algorithm writes the parsed data through the LSM storage engine to generate at least one index file, whereby the index file is also a SST type file.
[0079] Step S4: the index creation device sends each index file to the device where the database is located.
[0080] Step S5: The device where the database is located loads each index file into the corresponding database to complete the data index creation process.
[0081] In an optional implementation, the data files and index files of this embodiment are stored in a physically isolated manner, so that there is no need to reorganize the parsed data and then obtain new data files and index files based on the storage engine, thereby further saving system resources and data index creation time.
[0082] The embodiment of the present invention transfers the data index creation process to other devices, does not occupy the system resources of the device where the database is located, and thus can avoid the impact of the full index creation process on other applications of the device where the database is located. At the same time, the embodiment of the present invention obtains multiple data files in the database, traverses and parses the multiple data files in parallel, generates parsing data, determines at least one index file according to the parsing data, and loads each index file into the corresponding database, wherein the parsing data includes the index data of each data in the data file, and the index data in the index file is ordered. Therefore, this embodiment improves the speed of data index establishment by traversing and parsing and building data indexes in parallel with data files. At the same time, in this embodiment, it is not dependent on the storage engine for data traversal, which is easy to increase the concurrency of data traversal and further saves the time of traversal and parsing. In addition, this embodiment stores data files and index files in a physically isolated manner, so that there is no need to rewrite the data into the database and then create the index, which saves a lot of system resources and data index creation time.
[0083] Figure 7 Schematic diagram of a data index generation device according to an embodiment of the present invention. Figure 7 As shown, the data indexing device 7 of the embodiment of the present invention includes a data file acquiring unit 71 , a parsing unit 72 , an index file determining unit 73 and a loading unit 74 .
[0084] The data file acquisition unit 71 is configured to acquire multiple data files in a database stored based on the LSM storage engine.
[0085] The parsing unit 72 is configured to traverse and parse the multiple data files in parallel to generate parsed data, and the parsed data includes index data of each data in the data file. In an optional implementation, the parsing unit 72 is further configured to parse the multiple data files in parallel through a Map algorithm to generate the parsed data. In an optional implementation, the parsing unit 72 includes an index column determination subunit 721 and an encoding subunit 722. The index column determination subunit 721 is configured to traverse the multiple data files in parallel to determine the index columns in each of the data files, and at least one of the index columns is identification information. The encoding subunit 722 is configured to encode the data values of the index columns to generate index data of each data in the data file to determine the parsed data.
[0086] The index file determination unit 73 is configured to determine at least one index file according to the parsed data, and the index data in the index file is ordered. In an optional implementation, the index file determination unit 73 is further configured to generate at least one index file according to the parsed data by using a Reduce algorithm.
[0087] The loading unit 74 is configured to load each of the index files into a corresponding database. In an optional implementation, the data file and the index file are stored in a physically isolated manner. In an optional implementation, the size of the data file is a first preset value, and the size of the index file is a second preset value. Optionally, the first preset value is 64M, and the second preset value is 64M.
[0088] The embodiment of the present invention obtains multiple data files in a database stored based on an LSM storage engine, traverses and parses the multiple data files in parallel, generates parsed data, determines at least one index file based on the parsed data, and loads each of the index files into a corresponding database, wherein the parsed data includes index data of each data in the data file, and the index data in the index file is ordered, thereby improving the speed of establishing data indexes.
[0089] Figure 8 FIG. 1 is a schematic diagram of another data index generating device according to an embodiment of the present invention. Figure 8 As shown, the data index generating device 8 of this embodiment includes a data file acquiring unit 81 , a parsing unit 82 , an index file determining unit 83 and a loading unit 84 .
[0090] The data file acquisition unit 81 is configured to acquire multiple data files in a database stored based on the LSM storage engine. In an optional implementation, the data file acquisition unit 81 includes a receiving subunit 811. The receiving subunit 811 is configured to receive multiple data files sent by the device where the database is located.
[0091] The parsing unit 82 is configured to traverse and parse the multiple data files in parallel to generate parsed data, and the parsed data includes index data of each data in the data file. In an optional implementation, the parsing unit 82 is further configured to parse the multiple data files in parallel through a Map algorithm to generate the parsed data. In an optional implementation, the parsing unit 82 includes an index column determination subunit 821 and an encoding subunit 822. The index column determination subunit 821 is configured to traverse the multiple data files in parallel to determine the index columns in each of the data files, and at least one of the index columns is identification information. The encoding subunit 822 is configured to encode the data values of the index columns to generate index data of each data in the data file to determine the parsed data.
[0092] The index file determination unit 83 is configured to determine at least one index file according to the parsed data, and the index data in the index file is ordered. In an optional implementation, the index file determination unit 83 is further configured to generate at least one index file according to the parsed data by using a Reduce algorithm.
[0093] The loading unit 84 is configured to load each of the index files into the corresponding database. In an optional implementation, the loading unit 84 includes a sending subunit 841. The sending subunit 841 is configured to send each of the index files to the device where the database is located, so that the device loads each of the index files into the database.
[0094] In an optional implementation, the data file and the index file are stored in a physically isolated manner. In an optional implementation, the size of the data file is a first preset value, and the size of the index file is a second preset value. Optionally, the first preset value is 64M, and the second preset value is 64M.
[0095] The embodiment of the present invention obtains multiple data files in a database stored based on an LSM storage engine, traverses and parses the multiple data files in parallel, generates parsed data, determines at least one index file based on the parsed data, and loads each of the index files into a corresponding database, wherein the parsed data includes index data of each data in the data file, and the index data in the index file is ordered, thereby improving the speed of establishing data indexes.
[0096] Fig. 9 Schematic diagram of an electronic device according to an embodiment of the present invention. Fig. 9 As shown, Fig. 9 The electronic device shown is a general address query device, which includes a general computer hardware structure, which at least includes a processor 91 and a memory 92. The processor 91 and the memory 92 are connected via a bus 93. The memory 92 is suitable for storing instructions or programs executable by the processor 91. The processor 91 can be an independent microprocessor or a collection of one or more microprocessors. Thus, the processor 91 executes the instructions stored in the memory 92, thereby executing the method flow of the embodiment of the present invention as described above to realize the processing of data and the control of other devices. The bus 93 connects the above-mentioned multiple components together, and at the same time connects the above-mentioned components to the display controller 94 and the display device and the input / output (I / O) device 95. The input / output (I / O) device 95 can be a mouse, a keyboard, a modem, a network interface, a touch input device, a somatosensory input device, a printer, and other devices known in the art. Typically, the input / output device 95 is connected to the system through an input / output (I / O) controller 99.
[0097] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices (equipment) or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the present application may adopt a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0098] The present application is described with reference to flowcharts of methods, apparatuses (devices) and computer program products according to embodiments of the present application. It should be understood that each process in the flowchart can be implemented by computer program instructions.
[0099] These computer program instructions may be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device that implements the process Figure 1 A function specified in a process or multiple processes.
[0100] These computer program instructions may also be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce the instructions for implementing the process Figure 1 A device that specifies functions in a process or multiple processes.
[0101] Another embodiment of the present invention relates to a non-volatile storage medium for storing a computer-readable program, wherein the computer-readable program is used for a computer to execute part or all of the above method embodiments.
[0102] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0103] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for generating a data index, characterized in that: Applicable to an index creation device, the method comprises: Acquire multiple data files in a database stored based on an LSM storage engine, wherein the data files include index columns, and at least one of the index columns is identification information; Traversing and parsing the multiple data files in parallel to generate parsed data, the parsed data including index data of each data in the data files; Determine at least one index file according to the parsed data, wherein the index data in the index file is ordered; Loading each of the index files into a corresponding database; The obtaining of multiple data files in a database stored based on an LSM storage engine includes: Receiving multiple data files sent by the device where the database is located; The step of loading each of the index files into a corresponding database comprises: Each of the index files is sent to the device where the database is located, so that the device loads each of the index files into the database.
2. The method according to claim 1, characterized in that The data file and the index file are stored in a physically isolated manner.
3. The method according to claim 1, characterized in that Traverse and parse multiple data files in parallel to generate parsed data including: Traversing the plurality of data files in parallel to determine the index column in each of the data files; The data values of the index column are encoded to generate index data of each data in the data file to determine the parsed data.
4. The method according to claim 1, characterized in that: Traverse and parse multiple data files in parallel to generate parsed data including: Parsing the plurality of data files in parallel by using a Map algorithm to generate the parsed data; Determining at least one index file according to the parsed data includes: At least one index file is generated according to the parsed data by using a Reduce algorithm.
5. The method according to claim 1, characterized in that The size of the data file is a first preset value, and the size of the index file is a second preset value.
6. The method according to claim 5, characterized in that The first preset value is 64M, and the second preset value is 64M.
7. A data index generating device, characterized in that: Applicable to an index creation device, the device comprising: A data file acquisition unit is configured to acquire a plurality of data files in a database stored based on an LSM storage engine, wherein the data files include index columns, and at least one column of the index columns is identification information; A parsing unit, configured to traverse and parse the multiple data files in parallel to generate parsed data, wherein the parsed data includes index data of each data in the data files; an index file determining unit, configured to determine at least one index file according to the parsed data, wherein the index data in the index file is ordered; A loading unit, configured to load each of the index files into a corresponding database; The data file acquisition unit comprises: A receiving subunit, configured to receive a plurality of data files sent by the device where the database is located; The loading unit comprises: The sending subunit is configured to send each of the index files to the device where the database is located, so that the device loads each of the index files into the database.
8. The device according to claim 7, characterized in that The data file and the index file are stored in a physically isolated manner.
9. The device according to claim 7, characterized in that The parsing unit comprises: An index column determination subunit is configured to traverse the plurality of data files in parallel and determine an index column in each of the data files; The encoding subunit is configured to encode the data value of the index column to generate index data of each data in the data file to determine the parsed data.
10. The device according to claim 7, characterized in that The parsing unit is further configured to parse the plurality of data files in parallel through a Map algorithm to generate the parsed data; The index file determination unit is further configured to generate at least one index file according to the parsed data by using a Reduce algorithm.
11. The device according to claim 7, characterized in that The size of the data file is a first preset value, and the size of the index file is a second preset value.
12. The device according to claim 11, characterized in that The first preset value is 64M, and the second preset value is 64M.
13. An electronic device comprising a memory and a processor, characterized in that: The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 6.
14. A computer-readable storage medium storing computer program instructions, characterized in that: The computer program instructions, when executed by a processor, implement the method according to any one of claims 1 to 6.
