Dynamic index creation method, computer equipment and readable storage medium
Through the dynamic index creation method, the partition table type is identified and indexed is created, which solves the problems of slow partition table query speed and index occupancy disk space, and achieves efficient index creation and data writing performance.
Patent Information
- Application Number
- CN202411425201.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-02-07
AI Technical Summary
The query speed of existing partition tables is slow, creating indexes requires a large disk space, affecting the performance of dynamic data writing to partition tables.
Provide a dynamic index creation method, by reading the last piece of data in the record file, extracting the record time and executing the identification, identifying whether the partition table is a historical partition table, and using corresponding preset rules to create index entries to avoid long-term occupation of system resources.
It realizes flexible index creation, avoids long-term occupation of system resources, reduces the impact on the current hourly dynamic data partition table, and improves query speed and data writing performance.
Smart Images

Figure CN119396831A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database index creation, and in particular to a dynamic index creation method, a computer device and a readable storage medium. Background Art
[0002] In the database, especially for large amounts of data, it is usually stored in the form of tables. Generally, tables are partitioned by hour, so a table for one day is split into 24 partition tables. However, when using conditions to query data, the query speed is slow, and even causes the system query to crash. To solve this problem, you can add indexes to the table to facilitate data query. Considering that the partition table is created dynamically (a table for the next month is created every month), and there are also a large number of historical partition tables in the installed projects, and the table of the current hour is also constantly writing data, the current index method cannot adapt to the dynamically created partition table. Creating an index takes up a lot of disk space, which affects the dynamic writing of data into the partition table. Summary of the invention
[0003] In view of the problems that the query speed of existing partition tables is slow, the creation of indexes requires a large amount of disk space, and affects the dynamic writing of data into the partition table, a dynamic index creation method, computer equipment and readable storage medium are provided to flexibly create indexes, avoid long-term occupation of system resources, and avoid the impact of dynamic writing of data on the partition table.
[0004] The present invention provides a dynamic index creation method for creating an index for a partition table, comprising:
[0005] Obtain the last piece of data in the record file associated with the partition table, and extract the recording time and the corresponding execution identifier of the last piece of data;
[0006] Identify whether the partition table corresponding to the last piece of data is a historical partition table according to the current time, the recording time and the execution identifier;
[0007] If the partition table is a historical partition table, using a first preset rule to create an index entry associated with the historical partition table according to the recording time;
[0008] If the partition table is the current partition table, an index entry associated with the current partition table is created according to the recording time using a second preset rule.
[0009] Preferably, the record file records the recording time of each partition table and the execution mark of each partition table in ascending order;
[0010] The execution mark includes two types: a historical cycle mark and a current execution mark. The historical cycle mark corresponds to the historical partition table, and the current execution mark corresponds to the current partition table.
[0011] Preferably, the step of identifying whether the partition table corresponding to the last piece of data is a historical partition table according to the current time, the recording time and the execution identifier includes:
[0012] Determine whether the recorded time exists, the format of the recorded time is year, month, day and hour;
[0013] If the recorded time exists, the hour before the current time is taken as the end time in hours;
[0014] Determine whether the recording time is greater than the end time;
[0015] If the recording time is greater than the end time, it indicates that the partition table is the current partition table;
[0016] If the recording time is less than or equal to the end time, it indicates that the partition table is the historical partition table.
[0017] Preferably, if the recorded time does not exist, query all partition tables in the database, sort them in ascending order by table name, obtain the recorded time of the partition table corresponding to the minimum time, store the recorded time in the record file, and set the execution mark associated with the recorded time as a historical cycle mark;
[0018] Determine whether the recording time exists;
[0019] If the recorded time does not exist, then end;
[0020] If the recorded time exists, the hour before the current time is taken as the end time in units of hours, and it is determined whether the recorded time is greater than the end time.
[0021] Preferably, the first preset rule includes:
[0022] Taking the first preset frequency as a period, query whether there is script data associated with the recording time in the task file associated with the recording file, and the corresponding execution mark is the current execution mark;
[0023] If there is no script data associated with the recording time in the task file, and the corresponding execution mark is a historical loop mark, converting the recording time into a start timestamp and converting the end time into an end timestamp;
[0024] Determine whether the start timestamp is less than or equal to the end timestamp;
[0025] If the start timestamp is less than or equal to the end timestamp;
[0026] Convert the start timestamp into a preset format and store it in an array;
[0027] After adding 1 hour to the start timestamp, convert the start timestamp into a preset format as the record time of the partition table of the next index entry to be created, store the historical loop mark as an execution mark associated with the record time in the record file, repeat the execution N times to obtain the table names of at least N data in the array, and create an index entry according to the table name;
[0028] Wherein, N is a positive integer.
[0029] Preferably, if the task file associated with the record file is queried and there is script data associated with the record time and the corresponding execution mark is the current execution mark, the partition table is the current partition table, and the second preset rule is used to create an index entry associated with the current partition table according to the record time.
[0030] Preferably, if the start timestamp is greater than the end timestamp, the execution mark corresponding to the recording time is set as the current execution mark, and an index entry associated with the current partition table is created according to the recording time using a second preset rule.
[0031] Preferably, the second preset rule includes:
[0032] With the second preset frequency as a period, query whether there is script data associated with the recording time and a corresponding current execution mark in the task file associated with the recording file; if so, convert the recording time into a start timestamp, convert the start timestamp into a preset format, store it in an array, add 1 hour to the start timestamp, convert the start timestamp into a preset format, and use it as the recording time of the partition table for the next index entry to be created, store the current execution mark as an execution mark associated with the recording time in the recording file, obtain the table name of the data in the array, and create an index entry according to the table name.
[0033] Preferably, the partition table is a partition table of at least one category.
[0034] The present invention also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0035] The present invention also provides a computer-readable storage medium on which a computer program is stored, and the computer program implements the steps of the above method when executed by a processor.
[0036] Beneficial effects of the above technical solution:
[0037] In the present technical scheme, the dynamic index creation method of the present invention is applicable to creating an index for a partition table, by reading the last data in the record file to extract the recording time and the corresponding execution identifier of the last data; according to the current time, the recording time and the execution identifier, it is identified whether the partition table corresponding to the last data is a historical partition table; if the partition table is a historical partition table, the first preset rule is used to create an index entry associated with the historical partition table according to the recording time until the index creation of all historical partition tables is completed; if the partition table is the current partition table, the second preset rule is used to create an index entry associated with the current partition table according to the recording time to avoid long-term occupation of system and database resources. At the same time, the index is created to the hour before the current hour to avoid affecting the partition table that dynamically writes data in the current hour. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flowchart of an embodiment of the dynamic index creation method of the present invention;
[0039] Figure 2 A flow chart of a method for identifying whether the partition table corresponding to the last piece of data is a historical partition table according to an embodiment of the present invention;
[0040] Figure 3 A flowchart of an embodiment of the present invention of using a first preset rule to create an index entry associated with the historical partition table according to the recording time;
[0041] Figure 4 A schematic diagram of the hardware structure of a computer device for executing a dynamic index creation method provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The advantages of the present invention are further described below in conjunction with the accompanying drawings and specific embodiments.
[0043] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0044] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0045] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0046] In the description of the present invention, it should be understood that the numerical labels before the steps do not identify the order of executing the steps, but are only used to facilitate the description of the present invention and distinguish each step, and therefore cannot be understood as a limitation of the present invention.
[0047] The dynamic index creation method of the embodiment of the present application can be applied to school system data forms, and can also be applied to application scenarios with different start times of different projects, for example, it can be applied to some factory systems, etc.
[0048] In an embodiment of the present application, the dynamic index creation method is applicable to creating an index for a partition table, by reading the last data in the record file to extract the recording time and the corresponding execution identifier of the last data; identifying whether the partition table corresponding to the last data is a historical partition table according to the current time, the recording time and the execution identifier; if the partition table is a historical partition table, using the first preset rule to create an index entry associated with the historical partition table according to the recording time until the index creation of all historical partition tables is completed; if the partition table is the current partition table, using the second preset rule to create an index entry associated with the current partition table according to the recording time to avoid long-term occupation of system and database resources. At the same time, the index is created to the hour before the current hour to avoid affecting the partition table that dynamically writes data in the current hour.
[0049] The present invention proposes a dynamic index creation method to solve the defects of the existing partition table, such as slow query speed, large disk space occupied by index creation, and influence on dynamic writing of data into the partition table. Figure 1-Figure 3 , which is a flow chart of a dynamic index creation method according to a preferred embodiment of the present invention. The dynamic index creation method provided in this embodiment is used to create an index for a partition table, and mainly includes the following steps:
[0050] S1. Get the last piece of data in the record file associated with the partition table, extract the recording time of the last piece of data and the corresponding execution mark;
[0051] It should be noted that: the record file records the recording time of each partition table and the execution mark of each partition table in ascending order.
[0052] In this embodiment, the execution mark includes two types: a historical cycle mark and a current execution mark. The historical cycle mark corresponds to the historical partition table, and the current execution mark corresponds to the current partition table.
[0053] As an example but not limitation, the historical cycle flag of the crontab execution flag may be assigned a value of 1, where 1=execute once every 10 minutes; the historical cycle flag of the crontab execution flag may be assigned a value of 2, where 2=execute once every 60 minutes.
[0054] In this implementation, the dynamic index creation method can be implemented in combination with the script and the Linux system's scheduled task crontab. The table name format of the partition table is: table name prefix _yyyy_MM_dd_HH, where yyyy is year, MM is month, dd is day, and HH is hour. Remove the table name prefix and separator "_" to get the initial recording time format of yyyyMMddHH. In step S1, read the last line of data in the record file recode_index.log, and the format of each line of data is: yyyyMMddHH:crontab execution mark: write time (for example: 2024051715:2:2024-05-17 15:08:38.230); wherein, the recording time is 2024051715, and the crontab execution mark is 2, which can be understood as being executed once every 60 minutes.
[0055] S2. According to the current time, the recording time and the execution identifier, identify whether the partition table corresponding to the last piece of data is a historical partition table. If so, execute step S3; if not, execute step S4;
[0056] Specifically, see Figure 2 As shown, step S2 may include the following steps:
[0057] S21. Determine whether the recorded time exists, the format of the recorded time is year, month, day and hour; if so, execute step S22;
[0058] S22. The hour before the current time is taken as the end time in hours;
[0059] S23. Determine whether the recording time is greater than the end time. If so, it indicates that the partition table is the current partition table, and step S4 is executed; if not, it indicates that the partition table is the historical partition table, and step S3 is executed.
[0060] Furthermore, step S2 may also include:
[0061] S24. If the recorded time does not exist, query all partition tables in the database, sort them in ascending order by table name, obtain the recorded time of the partition table corresponding to the minimum time, store the recorded time in the record file, and set the execution mark associated with the recorded time as the historical loop mark;
[0062] In step S24, if the recording time is empty (i.e., does not exist), it means that the recording file does not have data yet, and it is necessary to query the recording time from the database. In actual operation, all partition tables can be queried by executing sql statements, and sorted in ascending order by table name (table name prefix _yyyy_MM_dd_HH), then the partition table of the minimum time is at the front, and the first value is taken, and then the table name prefix and separator "_" are removed to obtain the initial recording time, and the format is yyyyMMddHH (consistent with the recode_index.log file data format). It is necessary to query the database, indicating that there is no data in the recording file, that is, it is the first time to process, so the new crontab execution mark newCrontabFlag is set to 1 (i.e.: historical cycle mark), so that crontab will process the historical partition table once every 10 minutes.
[0063] S25. Determine whether the recorded time exists. If so, execute step S26; if not, end.
[0064] In step S25, it is determined again whether the recording time is empty. If it is empty, it means that the recording time cannot be obtained, and the execution of this script is terminated.
[0065] S26. Take the hour before the current time as the end time, and return to step S23.
[0066] In step S26, the time one hour before the current time is obtained, and the time is used as the end time of this execution. It is determined whether the obtained recording time is greater than the end time. If it is less than or equal to the end time, step S3 is executed; if it is greater, step S4 is executed.
[0067] S3. Using a first preset rule to create an index entry associated with the historical partition table according to the recording time;
[0068] In this embodiment, see Figure 3 As shown, the first preset rule includes:
[0069] S31. With a first preset frequency as a period, query whether there is script data associated with the recording time in the task file associated with the recording file, and the corresponding execution mark is the current execution mark;
[0070] By way of example and not limitation, the first preset frequency is 10 minutes.
[0071] S32. If there is no script data associated with the recording time in the task file, and the corresponding execution mark is a historical loop mark, the recording time is converted to a start timestamp, and the end time is converted to an end timestamp;
[0072] S33. Determine whether the start timestamp is less than or equal to the end timestamp; if so, execute step S34; if not, set the execution mark to the current execution mark, and execute step S4;
[0073] S34. Convert the start timestamp into a preset format and store it in an array;
[0074] S35. After adding 1 hour to the start timestamp, convert the start timestamp into a preset format as the record time of the partition table of the next index entry to be created, store the historical loop mark as an execution mark associated with the record time in the record file, repeat the execution N times to obtain the table names of at least N data in the array, and create an index entry according to the table name;
[0075] Wherein, N is a positive integer.
[0076] In this embodiment, the task file is searched for script data associated with the recorded time and related information of the current execution mark 2; when there is no script data and / or it is not the current execution mark, it means that crontab is executed in mode 1, and no other processing is required, and the current script execution is terminated; otherwise, it means that crontab is executed in mode 1; if there is script data in the task file, the existing execution script needs to be deleted first to avoid repeated addition; the recorded time is converted to a start timestamp, and the end time is converted to an end timestamp. When the start timestamp is less than or equal to the end timestamp, and the count i is less than 3, a loop is entered to obtain all the time sets to be executed this time; when the start timestamp is greater than the end timestamp, or the count i is greater than or equal to 3, the loop is terminated:
[0077] Specifically, the steps include:
[0078] A1. Convert the start timestamp startSec into yyyy_MM_dd_HH format and put it into the enum_dates array;
[0079] A2. The count i is incremented by 1; the starting timestamp startSec is incremented by 1 hour;
[0080] Wherein, i is an integer less than 3, and the initial value of i is 0;
[0081] A3. Convert the start timestamp startSec into yyyy_MM_dd_HH format and assign it to the next execution record time recodeDate;
[0082] A4. If the start timestamp startSec is less than the end timestamp endSec, it means that crontab needs to be executed in mode 1, and the new crontab execution flag newCrontabFlag is set to 1; otherwise, it means that crontab needs to be executed in mode 2, and the execution flag newCrontabFlag is set to 2. Enter the next loop;
[0083] A5. Loop through the time collection array enum_dates and add an index to the table (table name: prefix_single value in the array);
[0084] A6. Determine whether the next execution record time ecodeDate has a value. If not, the script execution ends. If so, execute step A7.
[0085] A7. Convert the next execution record time recodeDate to yyyyMMddHH format and write it together with newCrontabFlag into the record file recode_index.log;
[0086] A8. Determine whether the crontab execution mode is consistent with newCrontabFlag. If they are consistent, the script execution ends. If they are inconsistent, modify the crontab execution time according to newCrontabFlag and restart crontab.
[0087] In this embodiment, the first preset rule also includes:
[0088] S36. If the task file associated with the record file contains script data associated with the record time and the corresponding execution mark is the current execution mark, it means that the partition table is the current partition table, and step S4 is executed.
[0089] In this embodiment, the first preset rule also includes:
[0090] S37. If the start timestamp is greater than the end timestamp, set the execution mark corresponding to the recording time as the current execution mark, and execute step S4.
[0091] In this embodiment, when the start timestamp is greater than the end timestamp, it means that the record time has been processed to the partition table with the largest index to be created. It is not necessary to execute it every 10 minutes to avoid wasting resources. Therefore, the scheduled task crontab is changed to execute it every 60 minutes, that is, the index of the table one hour before the current time is created each time. This can avoid long-term occupation of system and database resources, thereby not affecting other operations of users.
[0092] S4. Using a second preset rule to create an index entry associated with the current partition table according to the recording time.
[0093] In this embodiment, the second preset rule may include:
[0094] With the second preset frequency as a period, query whether there is script data associated with the recording time and a corresponding current execution mark in the task file associated with the recording file; if so, convert the recording time into a start timestamp, convert the start timestamp into a preset format, store it in an array, add 1 hour to the start timestamp, convert the start timestamp into a preset format, and use it as the recording time of the partition table for the next index entry to be created, store the current execution mark as an execution mark associated with the recording time in the recording file, obtain the table name of the data in the array, and create an index entry according to the table name.
[0095] By way of example and not limitation, the second preset frequency is 60 minutes.
[0096] In this embodiment, a search is performed from the task file to determine whether there is script data associated with the recorded time and whether there is relevant information about the current execution mark 2; when both the script data and the current execution mark are present, it indicates that crontab is executed in mode 2, and no other processing is required, and the current script execution is terminated; otherwise, it indicates that crontab is executed in mode 1 and subsequent processing is required; if there is script data in the task file, the existing execution script needs to be deleted first to avoid repeated addition; the crontab expression of execution mode 2 is written into the scheduled task file, because the partition table with the largest index to be created has been processed, and it is not necessary to execute it every 10 minutes to avoid wasting resources; crontab is restarted to terminate the current script execution, because the recorded time is greater than the end time, it indicates that the partition table with the largest index to be created has been processed, and no processing is required this time.
[0097] In a preferred embodiment, the partition table is a partition table of at least one category.
[0098] This embodiment can create index entries for partition tables of multiple categories.
[0099] In this embodiment, considering that the starting table of each project is different, the first query start time needs to be queried through the database, and after sorting in ascending order according to the table name (table name prefix _yyyy_MM_dd_HH, where yyyy is year, MM is month, dd is day, and HH is hour), take the first value, and then remove the table name prefix and separator "_" to get the initial start time in the format of yyyyMMddHH. After each execution is completed, the recording time of the next processing and the crontab execution mark are recorded in the file recode_index.log. The subsequent processing is to read the start time from the recode_index.log file. In this way, the start time can be automatically matched, and different projects can be adapted without the need for customized configuration.
[0100] This embodiment takes into account that there are a large number of historical partition tables in the project, and the index of the existing table cannot be created in one go. Therefore, when the recording time is less than one hour before the current time, the scheduled task crontab is executed once every 10 minutes, and 3 partition tables are executed each time; when the historical partition table is executed, the recording time is greater than or equal to one hour before the current time (i.e., the end time), the scheduled task crontab is changed to be executed once every 60 minutes, that is, the index of the table one hour before the current time is created each time. Doing so can avoid long-term occupation of system and database resources, thereby not affecting other operations of the user. When the historical partition table is processed, modify the scheduled task execution mode to reduce unnecessary execution. The table of the current hour is constantly writing data, so creating an index will only be created one hour before the current time, which will not affect the writing of data.
[0101] The dynamic index creation method of this embodiment can dynamically obtain the start time and adapt to the different recording times of different projects. Create indexes in batches to avoid long-term occupation of system resources and to avoid affecting other operations of users. The ability to select different execution frequencies for different situations can effectively utilize resources and avoid unnecessary waste. The advantages of this embodiment are: it optimizes the use of resources during the index creation process and reduces the impact on database performance, especially for large partition tables; the automated index creation process reduces labor costs, reduces operational errors and improves efficiency; it provides a flexible index creation strategy to better utilize system resources without affecting other operations; it has strong scalability, and if other partition tables need to create indexes, indexes can be created for the new partition tables through simple modifications.
[0102] like Figure 4 As shown, a computer device 4, the computer device 4 includes:
[0103] A memory 41, used for storing executable program codes; and
[0104] The processor 42 is used to call the executable program code in the memory 41, and the execution steps include the above-mentioned dynamic index creation method.
[0105] Figure 4 A processor 42 is taken as an example.
[0106] The memory 41 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the dynamic index creation method in the embodiment of the present application. The processor 42 executes various functional applications and data processing of the computer device 4 by running the non-volatile software programs, instructions and modules stored in the memory 41, that is, the dynamic index creation method in the above method embodiment is implemented.
[0107] The memory 41 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and at least one application required for a function; the data storage area may store the user's voice input request on the computer device 4, convert the voice information into text information, generate barrage information, send the barrage information, and the client identification or voice inputter identification, etc. In addition, the memory 41 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 41 may optionally include a memory 41 remotely arranged relative to the processor 42, and these remote memories 41 may be connected to the dynamic index creation via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0108] The one or more modules are stored in the memory 41, and when executed by the one or more processors 42, the dynamic index creation method in any of the above method embodiments is executed.
[0109] The above-mentioned product can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method provided in the embodiment of the present application.
[0110] The computer device 4 of the embodiment of the present application exists in various forms, including but not limited to:
[0111] (1) Mobile communication devices: These devices are characterized by their mobile communication functions and their main purpose is to provide voice and data communications. These terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones.
[0112] (2) Ultra-mobile personal computer devices: These devices fall into the category of personal computers, have computing and processing capabilities, and generally also have mobile Internet access features. These terminals include: PDA, MID and UMPC devices, such as iPad.
[0113] (3) Portable entertainment devices: These devices can display and play multimedia content. They include audio and video players (such as iPods), handheld game consoles, e-books, smart toys, and portable car navigation devices.
[0114] (4) Server: A device that provides computing services. The server consists of a processor, hard disk, memory, system bus, etc. The server is similar to a general computer architecture, but because it needs to provide highly reliable services, it has higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0115] (5) Other electronic devices with data interaction functions.
[0116] The embodiment of the present application provides a non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, such as Figure 4 A processor 42 in the embodiment may enable the one or more processors 42 to execute the dynamic index creation method in any of the above method embodiments, for example, to execute the above described Figure 2 Steps S21 to S26 of the method, Figure 3 Method steps S31 to S35.
[0117] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on at least two network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present application. Those of ordinary skill in the art may understand and implement them without creative effort.
[0118] Through the description of the above implementation methods, a person of ordinary skill in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0119] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application 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 replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A dynamic index creation method for creating an index for a partition table, characterized in that: include: Obtain the last piece of data in the record file associated with the partition table, and extract the recording time and the corresponding execution identifier of the last piece of data; Identify whether the partition table corresponding to the last piece of data is a historical partition table according to the current time, the recording time and the execution identifier; If the partition table is a historical partition table, using a first preset rule to create an index entry associated with the historical partition table according to the recording time; If the partition table is the current partition table, an index entry associated with the current partition table is created according to the recording time using a second preset rule.
2. The dynamic index creation method according to claim 1, characterized in that: The record file records the recording time and execution mark of each partition table in ascending order; The execution mark includes two types: a historical cycle mark and a current execution mark. The historical cycle mark corresponds to the historical partition table, and the current execution mark corresponds to the current partition table.
3. The dynamic index creation method according to claim 1, characterized in that: The step of identifying whether the partition table corresponding to the last piece of data is a historical partition table according to the current time, the recording time and the execution identifier includes: Determine whether the recorded time exists, the format of the recorded time is year, month, day and hour; If the recorded time exists, the hour before the current time is taken as the end time in hours; Determine whether the recording time is greater than the end time; If the recording time is greater than the end time, it indicates that the partition table is the current partition table; If the recording time is less than or equal to the end time, it indicates that the partition table is the historical partition table.
4. The dynamic index creation method according to claim 3, characterized in that: If the record time does not exist, query all partition tables in the database, sort them in ascending order by table name, obtain the record time of the partition table corresponding to the minimum time, store the record time in the record file, and set the execution mark associated with the record time as a historical cycle mark; Determine whether the recording time exists; If the recorded time does not exist, then end; If the recorded time exists, the hour before the current time is taken as the end time in units of hours, and it is determined whether the recorded time is greater than the end time.
5. The dynamic index creation method according to claim 3, characterized in that: The first preset rule includes: Taking the first preset frequency as a period, query whether there is script data associated with the recording time in the task file associated with the recording file, and the corresponding execution mark is the current execution mark; If there is no script data associated with the recording time in the task file, and the corresponding execution mark is a historical loop mark, converting the recording time into a start timestamp and converting the end time into an end timestamp; Determine whether the start timestamp is less than or equal to the end timestamp; If the start timestamp is less than or equal to the end timestamp; Convert the start timestamp into a preset format and store it in an array; After adding 1 hour to the start timestamp, convert the start timestamp into a preset format as the record time of the partition table of the next index entry to be created, store the historical loop mark as an execution mark associated with the record time in the record file, repeat the execution N times to obtain the table names of at least N data in the array, and create an index entry according to the table name; Wherein, N is a positive integer.
6. The dynamic index creation method according to claim 5, characterized in that: If the task file associated with the record file is queried and there is script data associated with the record time and the corresponding execution mark is the current execution mark, the partition table is the current partition table, and the second preset rule is used to create an index entry associated with the current partition table according to the record time.
7. The dynamic index creation method according to claim 5, characterized in that: If the start timestamp is greater than the end timestamp, the execution mark corresponding to the recording time is set as the current execution mark, and an index entry associated with the current partition table is created according to the recording time using a second preset rule.
8. The dynamic index creation method according to claim 1, characterized in that: The second preset rule includes: With the second preset frequency as a period, query whether there is script data associated with the recording time and a corresponding current execution mark in the task file associated with the recording file; if so, convert the recording time into a start timestamp, convert the start timestamp into a preset format, store it in an array, add 1 hour to the start timestamp, convert the start timestamp into a preset format, and use it as the recording time of the partition table for the next index entry to be created, store the current execution mark as an execution mark associated with the recording time in the recording file, obtain the table name of the data in the array, and create an index entry according to the table name.
9. The dynamic index creation method according to claim 1, characterized in that: The partition table is a partition table of at least one category.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
Citation Information
Cited By
Database partition table processing method, device and system and medium
CN120804126A